Correct basic tests using a Y range system for normal numbers.

secondmonitor
sigonasr2 4 years ago
parent 6a270300b7
commit c8af68b140
  1. BIN
      DivaBot/DivaBot.jar
  2. 8
      DivaBot/calibration_data.txt
  3. BIN
      DivaBot/rectangle0.png
  4. BIN
      DivaBot/rectangle1.png
  5. BIN
      DivaBot/rectangle2.png
  6. BIN
      DivaBot/rectangle3.png
  7. BIN
      DivaBot/rectangle4.png
  8. 4
      DivaBot/src/sig/Calibrator.java
  9. 381
      DivaBot/src/sig/MyRobot.java
  10. 3
      DivaBot/src/sig/Result.java
  11. 8
      DivaBot/src/sig/SongData.java
  12. 175
      DivaBot/src/sig/TypeFace2.java
  13. BIN
      DivaBot/typeface.png
  14. BIN
      DivaBot/typeface2.png

Binary file not shown.

@ -1,4 +1,4 @@
517
265
1485
808
521
299
1490
842

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

@ -207,9 +207,9 @@ public class Calibrator{
//ImageIO.write(miniImg,"png",new File("capture_"+System.nanoTime()+".png"));
Color col = new Color(miniImg.getRGB(0, 0));
System.out.println("Checking "+col);
if ((col.getRed()>=5&&col.getRed()<=40&&
if ((col.getRed()>=5&&col.getRed()<=75&&
col.getGreen()>=170&&col.getGreen()<=210&&
col.getBlue()>=205&&col.getBlue()<=250)) {
col.getBlue()>=180&&col.getBlue()<=250)) {
//This is the max X. Calibration on this side good.
MyRobot.STARTDRAG.y=MyRobot.STARTDRAG.y+i;
//MyRobot.STARTDRAG.x--;

@ -205,193 +205,201 @@ public class MyRobot{
@Override
public void run() {
try {
if (MyRobot.calibrating) {
MyRobot.calibrating=false;
Overlay.OVERLAY.setVisible(false);
Thread.sleep(1000);
Calibrator c = new Calibrator();
}
if (checkSongSelect()) {
if (!overlayHidden) {
overlayHidden=true;
p.repaint(0, 0, 1400, 1000);
}
GetCurrentSong();
GetCurrentDifficulty();
recordedResults=false;
if (selectedSong!=null && difficulty!=null) {
if (!prevSongTitle.equalsIgnoreCase(selectedSong.title) || !prevDifficulty.equalsIgnoreCase(difficulty)) {
System.out.println("On Song Select Screen: Current Song-"+selectedSong.title+" Diff:"+difficulty);
p.pullData(selectedSong.title,difficulty);
prevSongTitle=selectedSong.title;
prevDifficulty=difficulty;
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_SHIFT);
MYROBOT.keyPress(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_SHIFT);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
}
if (CALIBRATION_MODE) {
if (MyRobot.calibrating) {
MyRobot.calibrating=false;
Overlay.OVERLAY.setVisible(false);
Thread.sleep(1000);
Calibrator c = new Calibrator();
}
lastSongSelectTime = System.currentTimeMillis();
} else {
if (overlayHidden) {
overlayHidden=false;
p.repaint(0, 0, 1400, 1000);
}
if ((selectedSong!=null && difficulty!=null)) {
if (OnResultsScreen() && !recordedResults && !recordingResults && results.size()==0) {
lastSongSelectTime=System.currentTimeMillis();
MYROBOT.setAutoDelay(0);
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_SHIFT);
MYROBOT.keyPress(KeyEvent.VK_F12);
MYROBOT.keyRelease(KeyEvent.VK_F12);
MYROBOT.keyRelease(KeyEvent.VK_SHIFT);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
Thread.sleep(200);
MYROBOT.refreshScoreScreen();
ImageIO.write(MYROBOT.createScoreScreenCapture(),"png",new File("scoreimage.png"));
File tmp = new File("tmp");
if (tmp.exists()) {
FileUtils.deleteFile(tmp);
} else {
tmp.mkdir();
if (checkSongSelect()) {
if (!overlayHidden) {
overlayHidden=true;
p.repaint(0, 0, 1400, 1000);
}
GetCurrentSong();
GetCurrentDifficulty();
recordedResults=false;
if (selectedSong!=null && difficulty!=null) {
if (!prevSongTitle.equalsIgnoreCase(selectedSong.title) || !prevDifficulty.equalsIgnoreCase(difficulty)) {
System.out.println("On Song Select Screen: Current Song-"+selectedSong.title+" Diff:"+difficulty);
p.pullData(selectedSong.title,difficulty);
prevSongTitle=selectedSong.title;
prevDifficulty=difficulty;
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_SHIFT);
MYROBOT.keyPress(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_SHIFT);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
}
try {
Result data = typeface1.getAllData(MYROBOT.createScoreScreenCapture());
//ImageIO.write(MYROBOT.createNormalScreenCapture(new Rectangle(418,204,1227,690)),"png",new File("test.png"));
if (data.cool==-1 || data.fine==-1 || data.safe==-1 || data.sad==-1 || data.worst==-1 || data.percent<0f || data.percent>110f || data.combo==-1 || data.score==-1) {
System.out.println("Waiting for results to populate...");
} else
if ((data.combo!=lastcombo || data.fail!=lastfail || data.cool!=lastcool || lastfine!=data.fine || lastsafe!=data.safe || lastsad!=data.sad || lastworst!=data.worst)
&& data.score!=lastscore /*|| lastpercent!=percent*/){
//System.out.println("Results for "+selectedSong.title+" "+difficulty+": "+data.cool+"/"+data.fine+"/"+data.safe+"/"+data.sad+"/"+data.worst+" "+data.percent+"%");
System.out.println("Results for "+selectedSong.title+" "+difficulty+": "+data.display());
File songFolder = new File(selectedSong.title+"/"+difficulty);
if (!songFolder.exists()) {
songFolder.mkdirs();
}
File[] songFolderFiles = songFolder.listFiles();
int playId = songFolderFiles.length;
File playFolder = new File(selectedSong.title+"/"+difficulty+"/"+playId);
playFolder.mkdir();
recordedResults=true;
lastcool=data.cool;
lastfine=data.fine;
lastsafe=data.safe;
lastsad=data.sad;
lastworst=data.worst;
lastpercent=data.percent;
lastcombo=data.combo;
lastscore=data.score;
lastfail=data.fail;
new File("scoreimage.png").renameTo(new File(playFolder,selectedSong.title+"_"+difficulty+"play_"+data.cool+"_"+data.fine+"_"+data.safe+"_"+data.sad+"_"+data.worst+"_"+data.percent+""
+ "_"+data.combo+"_"+data.score+".png"));
results.add(new Result(selectedSong.title,difficulty,data.cool,data.fine,data.safe,data.sad,data.worst,data.percent,data.combo,data.score,data.fail));
SoundUtils.playSound("collect_item.wav");
//gotoxy(800,64);
//click();
MYROBOT.setAutoDelay(0);
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_SHIFT);
MYROBOT.keyPress(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_SHIFT);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
}
lastSongSelectTime = System.currentTimeMillis();
} else {
if (overlayHidden) {
overlayHidden=false;
p.repaint(0, 0, 1400, 1000);
}
if ((selectedSong!=null && difficulty!=null)) {
if (OnResultsScreen() && !recordedResults && !recordingResults && results.size()==0) {
lastSongSelectTime=System.currentTimeMillis();
MYROBOT.setAutoDelay(0);
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_SHIFT);
MYROBOT.keyPress(KeyEvent.VK_F12);
MYROBOT.keyRelease(KeyEvent.VK_F12);
MYROBOT.keyRelease(KeyEvent.VK_SHIFT);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
Thread.sleep(200);
MYROBOT.refreshScoreScreen();
ImageIO.write(MYROBOT.createScoreScreenCapture(),"png",new File("scoreimage.png"));
File tmp = new File("tmp");
if (tmp.exists()) {
FileUtils.deleteFile(tmp);
} else {
tmp.mkdir();
}
} catch (IOException|NumberFormatException|IndexOutOfBoundsException e) {
}
} else {
if (results.size()>0) {
recordingResults=true;
for (Result r : results) {
r.songName=r.songName.equalsIgnoreCase("PIANOGIRL")?"PIANO*GIRL":(r.songName.equalsIgnoreCase("16 -out of the gravity-"))?"1/6 -out of the gravity-":r.songName;
HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost("http://45.33.13.215:4501/submit");
// Request parameters and other properties.
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("song", r.songName));
params.add(new BasicNameValuePair("username", "sigonasr2"));
params.add(new BasicNameValuePair("authentication_token", "sig"));
params.add(new BasicNameValuePair("difficulty", r.difficulty));
params.add(new BasicNameValuePair("cool", Integer.toString(r.cool)));
params.add(new BasicNameValuePair("fine", Integer.toString(r.fine)));
params.add(new BasicNameValuePair("safe", Integer.toString(r.safe)));
params.add(new BasicNameValuePair("sad", Integer.toString(r.sad)));
params.add(new BasicNameValuePair("worst", Integer.toString(r.worst)));
params.add(new BasicNameValuePair("percent", Float.toString(r.percent)));
params.add(new BasicNameValuePair("fail", Boolean.toString(r.fail)));
params.add(new BasicNameValuePair("mod", r.mod));
params.add(new BasicNameValuePair("combo", Integer.toString(r.combo)));
params.add(new BasicNameValuePair("gameScore", Integer.toString(r.score)));
try {
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
//Execute and get the response.
HttpResponse response = null;
try {
response = httpclient.execute(httppost);
} catch (IOException e) {
e.printStackTrace();
try {
Result data = typeface1.getAllData(MYROBOT.createScoreScreenCapture());
System.out.println(data);
//ImageIO.write(MYROBOT.,"png",new File("test.png"));
if (data.cool==-1 || data.fine==-1 || data.safe==-1 || data.sad==-1 || data.worst==-1 || data.percent<0f || data.percent>110f || data.combo==-1 || data.score==-1) {
System.out.println("Waiting for results to populate...");
} else
if ((data.combo!=lastcombo || data.fail!=lastfail || data.cool!=lastcool || lastfine!=data.fine || lastsafe!=data.safe || lastsad!=data.sad || lastworst!=data.worst)
&& data.score!=lastscore /*|| lastpercent!=percent*/){
//System.out.println("Results for "+selectedSong.title+" "+difficulty+": "+data.cool+"/"+data.fine+"/"+data.safe+"/"+data.sad+"/"+data.worst+" "+data.percent+"%");
System.out.println("Results for "+selectedSong.title+" "+difficulty+": "+data.display());
File songFolder = new File(selectedSong.title+"/"+difficulty);
if (!songFolder.exists()) {
songFolder.mkdirs();
}
File[] songFolderFiles = songFolder.listFiles();
int playId = songFolderFiles.length;
File playFolder = new File(selectedSong.title+"/"+difficulty+"/"+playId);
playFolder.mkdir();
recordedResults=true;
lastcool=data.cool;
lastfine=data.fine;
lastsafe=data.safe;
lastsad=data.sad;
lastworst=data.worst;
lastpercent=data.percent;
lastcombo=data.combo;
lastscore=data.score;
lastfail=data.fail;
new File("scoreimage.png").renameTo(new File(playFolder,selectedSong.title+"_"+difficulty+"play_"+data.cool+"_"+data.fine+"_"+data.safe+"_"+data.sad+"_"+data.worst+"_"+data.percent+""
+ "_"+data.combo+"_"+data.score+".png"));
results.add(new Result(selectedSong.title,difficulty,data.cool,data.fine,data.safe,data.sad,data.worst,data.percent,data.combo,data.score,data.fail));
SoundUtils.playSound("collect_item.wav");
//gotoxy(800,64);
//click();
MYROBOT.setAutoDelay(0);
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_SHIFT);
MYROBOT.keyPress(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_SHIFT);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
}
HttpEntity entity = response.getEntity();
if (entity != null) {
try (InputStream instream = entity.getContent()) {
Scanner s = new Scanner(instream).useDelimiter("\\A");
String result = s.hasNext() ? s.next() : "";
System.out.println(result);
instream.close();
} catch (UnsupportedOperationException | IOException e) {
} catch (IOException|NumberFormatException|IndexOutOfBoundsException e) {
}
} else {
if (results.size()>0) {
recordingResults=true;
for (Result r : results) {
r.songName=r.songName.equalsIgnoreCase("PIANOGIRL")?"PIANO*GIRL":(r.songName.equalsIgnoreCase("16 -out of the gravity-"))?"1/6 -out of the gravity-":r.songName;
HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost("http://45.33.13.215:4501/submit");
// Request parameters and other properties.
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("song", r.songName));
params.add(new BasicNameValuePair("username", "sigonasr2"));
params.add(new BasicNameValuePair("authentication_token", "sig"));
params.add(new BasicNameValuePair("difficulty", r.difficulty));
params.add(new BasicNameValuePair("cool", Integer.toString(r.cool)));
params.add(new BasicNameValuePair("fine", Integer.toString(r.fine)));
params.add(new BasicNameValuePair("safe", Integer.toString(r.safe)));
params.add(new BasicNameValuePair("sad", Integer.toString(r.sad)));
params.add(new BasicNameValuePair("worst", Integer.toString(r.worst)));
params.add(new BasicNameValuePair("percent", Float.toString(r.percent)));
params.add(new BasicNameValuePair("fail", Boolean.toString(r.fail)));
params.add(new BasicNameValuePair("mod", r.mod));
params.add(new BasicNameValuePair("combo", Integer.toString(r.combo)));
params.add(new BasicNameValuePair("gameScore", Integer.toString(r.score)));
try {
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
//Execute and get the response.
HttpResponse response = null;
try {
response = httpclient.execute(httppost);
} catch (IOException e) {
e.printStackTrace();
}
HttpEntity entity = response.getEntity();
if (entity != null) {
try (InputStream instream = entity.getContent()) {
Scanner s = new Scanner(instream).useDelimiter("\\A");
String result = s.hasNext() ? s.next() : "";
System.out.println(result);
instream.close();
} catch (UnsupportedOperationException | IOException e) {
e.printStackTrace();
}
}
}
}
results.clear();
try {
JSONObject obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/rating/sigonasr2");
JSONObject obj2 = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/bestplay/sigonasr2/"+URLEncoder.encode(MyRobot.p.songname, StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20")+"/"+difficulty);
p.lastRating = p.overallrating;
if (obj2.has("score")) {
double newScore = obj2.getDouble("score");
if (newScore>p.lastScore) {
p.bestPlayTime=System.currentTimeMillis();
results.clear();
try {
JSONObject obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/rating/sigonasr2");
JSONObject obj2 = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/bestplay/sigonasr2/"+URLEncoder.encode(MyRobot.p.songname, StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20")+"/"+difficulty);
p.lastRating = p.overallrating;
if (obj2.has("score")) {
double newScore = obj2.getDouble("score");
if (newScore>p.lastScore) {
p.bestPlayTime=System.currentTimeMillis();
}
p.lastScore = newScore;
}
p.lastScore = newScore;
p.overallrating = (int)obj.getDouble("rating");
if (p.lastRating<p.overallrating) {p.ratingTime=System.currentTimeMillis();}
p.pullData(selectedSong.title, difficulty);
} catch (JSONException | IOException e) {
e.printStackTrace();
}
p.overallrating = (int)obj.getDouble("rating");
if (p.lastRating<p.overallrating) {p.ratingTime=System.currentTimeMillis();}
p.pullData(selectedSong.title, difficulty);
} catch (JSONException | IOException e) {
e.printStackTrace();
recordingResults=false;
}
if (!OnResultsScreen() && recordedResults) {
recordedResults=false;
}
recordingResults=false;
}
if (!OnResultsScreen() && recordedResults) {
recordedResults=false;
}
}
}
MYROBOT.refreshScreen();
}
MYROBOT.refreshScreen();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
private boolean OnResultsScreen() {
Color c1 = new Color(MYROBOT.createScreenCapture(new Rectangle(449,434,2,2)).getRGB(0, 0));
Color c2 = new Color(MYROBOT.createScreenCapture(new Rectangle(449,400,2,2)).getRGB(0, 0));
Color c3 = new Color(MYROBOT.createScreenCapture(new Rectangle(901,460,2,2)).getRGB(0, 0));
private boolean OnResultsScreen() throws IOException {
//r.x-418, r.y-204
ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(31,230,40,40)),"png",new File("color1.png"));
ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(31,196,40,40)),"png",new File("color2.png"));
ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(483,256,40,40)),"png",new File("color3.png"));
Color c1 = new Color(MYROBOT.createScreenCapture(new Rectangle(31,230,40,40)).getRGB(0, 0));
Color c2 = new Color(MYROBOT.createScreenCapture(new Rectangle(31,196,40,40)).getRGB(0, 0));
Color c3 = new Color(MYROBOT.createScreenCapture(new Rectangle(483,256,40,40)).getRGB(0, 0));
//System.out.println(c1+"/"+c2+"/"+c3);
return c1.getRed()>=254 && c1.getGreen()>=254 && c1.getBlue()>=254 && c2.getRed()==16 && c2.getGreen()==222 && c2.getBlue()==202 &&
c3.getRed()>=219 && c3.getRed()<=255 && c3.getGreen()>=213 && c3.getGreen()<=255 && c3.getBlue()>=160 && c3.getBlue()<=220;
}
@ -571,6 +579,7 @@ public class MyRobot{
f.add(OVERLAY);
f.setBackground(new Color(0,0,0,0));
} else {
RunTests();
f.setSize(1362, 1036);
f.add(p);
}
@ -581,12 +590,12 @@ public class MyRobot{
title.setText((currentSong>=SONGNAMES.length)?"DONE!":SONGNAMES[currentSong].name);
SongData s = SongData.getByTitle(SONGNAMES[currentSong].name);
//SongData s = SongData.getByTitle(SONGNAMES[currentSong].name);
BotMain();
}
void RunTests() throws IOException {
static void RunTests() throws IOException {
selectedSong=new SongData("LIKE THE WIND",new Color[] {});
difficulty="H";
@ -609,6 +618,7 @@ public class MyRobot{
RunTest("test16.png",320,46,2,0,4,93.26f,"EXEX","HS",135,463170,false);
RunTest("test17.png",431,30,3,0,3,100.51f,"EXEX","HS",386,581700,false);
RunTest("test18.png",427,86,5,1,4,92.45f,"EX","HS",136,526740,false);
RunTest("test19.png",4,2,2,0,95,0.42f,"EXEX","HS",2,4130,true);
RunTest("testimage.png",371,40,3,4,3,97.63f,"EX","HS",233,523750,false);
RunTest("testimage2.png",942,71,1,0,3,97.02f,"EXEX","",714,951020,false);
RunTest("testimage3.png",546,52,0,0,0,101.77f,"EX","",598,567430,false);
@ -649,11 +659,11 @@ public class MyRobot{
RunTest("サマーアイドル.jpg",245,19,4,0,2,87.04f,"E","",103,179360,false);
}
void RunTest(String _img,int _cool,int _fine, int _safe, int _sad, int _worst, float _percent,String _difficulty,String _mod,int _combo,int _score,boolean _fail) throws IOException {
static void RunTest(String _img,int _cool,int _fine, int _safe, int _sad, int _worst, float _percent,String _difficulty,String _mod,int _combo,int _score,boolean _fail) throws IOException {
RunTest(_img,_cool,_fine,_safe,_sad,_worst,_percent,_difficulty,_mod,_combo,_score,_fail,false);
}
void RunTest(String _img,int _cool,int _fine, int _safe, int _sad, int _worst, float _percent,String _difficulty,String _mod,int _combo,int _score,boolean _fail,boolean debug) throws IOException {
static void RunTest(String _img,int _cool,int _fine, int _safe, int _sad, int _worst, float _percent,String _difficulty,String _mod,int _combo,int _score,boolean _fail,boolean debug) throws IOException {
System.out.println("Running test "+_img);
long startTime = System.currentTimeMillis();
String testdir="testsuite";
@ -671,18 +681,23 @@ public class MyRobot{
e.printStackTrace();
}
Result data = typeface1.getAllData(img,debug);
assert data.cool == _cool : "Expected cool count to be "+_cool+", got "+data.cool;
assert data.fine == _fine : "Expected fine count to be "+_fine+", got "+data.fine;
assert data.safe == _safe : "Expected safe count to be "+_safe+", got "+data.safe;
assert data.sad == _sad : "Expected sad count to be "+_sad+", got "+data.sad;
assert data.worst == _worst : "Expected worst count to be "+_worst+", got "+data.worst;
assert data.percent == _percent : "Expected percent to be "+_percent+", got "+data.percent;
assert data.fail == _fail : "Expected fail to be "+_fail+", got "+data.fail;
assert data.mod == _mod : "Expected mod to be "+_mod+", got "+data.mod;
assert data.difficulty == _difficulty : "Expected difficulty to be "+_difficulty+", got "+data.difficulty;
assert data.combo == _combo : "Expected combo to be "+_combo+", got "+data.combo;
assert data.score == _score : "Expected score to be "+_score+", got "+data.score;
System.out.println(" Passed ("+(System.currentTimeMillis()-startTime)+"ms)!");
try {
assert data.cool == _cool : "Expected cool count to be "+_cool+", got "+data.cool;
assert data.fine == _fine : "Expected fine count to be "+_fine+", got "+data.fine;
assert data.safe == _safe : "Expected safe count to be "+_safe+", got "+data.safe;
assert data.sad == _sad : "Expected sad count to be "+_sad+", got "+data.sad;
assert data.worst == _worst : "Expected worst count to be "+_worst+", got "+data.worst;
assert data.percent == _percent : "Expected percent to be "+_percent+", got "+data.percent;
assert data.fail == _fail : "Expected fail to be "+_fail+", got "+data.fail;
assert data.mod == _mod : "Expected mod to be "+_mod+", got "+data.mod;
assert data.difficulty == _difficulty : "Expected difficulty to be "+_difficulty+", got "+data.difficulty;
assert data.combo == _combo : "Expected combo to be "+_combo+", got "+data.combo;
assert data.score == _score : "Expected score to be "+_score+", got "+data.score;
} catch(AssertionError e) {
System.err.println("\t"+e.getMessage()+" "+"("+(System.currentTimeMillis()-startTime)+"ms)!");
System.exit(1);
}
System.out.println("\tPassed ("+(System.currentTimeMillis()-startTime)+"ms)!");
}
public static boolean checkSongSelect() throws IOException {

@ -44,4 +44,7 @@ public class Result {
.append(",\"").append(difficulty).append("\",\"").append(mod).append("\",").append(Boolean.toString(fail).toLowerCase())
.append(",").append(combo).append(",").append(score).toString();
}
public String toString() {
return displayDebug();
}
}

@ -8,7 +8,7 @@ public class SongData {
String title;
Color[] songCode;
int distance=0;
static int MAXTHRESHOLD=200000;
static int MAXTHRESHOLD=400000;
final static float TOLERANCE = 0.95f;
public SongData(String title,Color[] songCode) {
this.title=title;
@ -38,16 +38,16 @@ public class SongData {
break;
}*/
}
if (/*distance<=MAXTHRESHOLD && */distance<closestDistance) {
if (/*distance<=MAXTHRESHOLD &&*/ distance<closestDistance) {
//System.out.println(distance+" pixels matched for song "+s.title);
closestSong=s;
closestSong.distance=distance;
closestDistance=distance;
}
if (distance>=MAXTHRESHOLD && distance<closestMaxThresholdDistance) {
/*if (distance>=MAXTHRESHOLD && distance<closestMaxThresholdDistance) {
System.out.println(distance+" pixels diff: "+s.title);
closestMaxThresholdDistance=distance;
}
}*/
} else {
continue;
}

@ -37,19 +37,31 @@ public class TypeFace2 {
public Result getAllData(BufferedImage img) throws IOException {
return getAllData(img,false);
}
final static int XOFFSET = 8;
final static Rectangle RECT_SEARCH_COOL=new Rectangle(866+XOFFSET,260,100+XOFFSET,22);
final static Rectangle RECT_SEARCH_FINE=new Rectangle(866+XOFFSET,294,100+XOFFSET,22);
final static Rectangle RECT_SEARCH_SAFE=new Rectangle(866+XOFFSET,329,100+XOFFSET,22);
final static Rectangle RECT_SEARCH_SAD=new Rectangle(866+XOFFSET,364,100+XOFFSET,22);
final static Rectangle RECT_SEARCH_WORST=new Rectangle(866+XOFFSET,400,100+XOFFSET,22);
final static Rectangle RECT_SEARCH_PCT=new Rectangle(1182+XOFFSET,165,1132,168);
final static Rectangle RECT_SEARCH_PCT2=new Rectangle(1123+XOFFSET,165,1051,168);
final static Rectangle RECT_SEARCH_SCORE=new Rectangle(859+XOFFSET,578,250+XOFFSET,32);
final static Rectangle RECT_SEARCH_COMBO=new Rectangle(1010+XOFFSET,435,100+XOFFSET,20);
public Result getAllData(BufferedImage img, boolean debug) throws IOException,NumberFormatException,IndexOutOfBoundsException {
BufferedImage img2 = ImageUtils.toBufferedImage(img.getScaledInstance(1280, 720, Image.SCALE_SMOOTH));
BufferedImage img2 = ImageUtils.toBufferedImage(img.getScaledInstance(1280 , 720, Image.SCALE_SMOOTH));
Result result = new Result("","",-1,-1,-1,-1,-1,-1f);
int[] finalNumbers = new int[5];
Rectangle[] ranges = new Rectangle[] {
//These coords are in regard to the old screenshot sizes.
new Rectangle(866,262,100,20), //33 pixels per line.
new Rectangle(866,296,100,20),
new Rectangle(866,331,100,20),
new Rectangle(866,366,100,20),
new Rectangle(866,400,100,20),
RECT_SEARCH_COOL, //33 pixels per line.
RECT_SEARCH_FINE,
RECT_SEARCH_SAFE,
RECT_SEARCH_SAD,
RECT_SEARCH_WORST,
};
for (int i=0;i<ranges.length;i++) {
@ -86,10 +98,10 @@ public class TypeFace2 {
//1109,435
result.combo = extractNumbersFromImage(img2.getSubimage(
1010,435,100,20),debug);
RECT_SEARCH_COMBO.x,RECT_SEARCH_COMBO.y,RECT_SEARCH_COMBO.width,RECT_SEARCH_COMBO.height),debug);
result.score = extractScoreNumbersFromImage(img2.getSubimage(
859,578,250,32),debug);
RECT_SEARCH_SCORE.x,RECT_SEARCH_SCORE.y,RECT_SEARCH_SCORE.width,RECT_SEARCH_SCORE.height),debug);
return result;
}
@ -131,14 +143,14 @@ public class TypeFace2 {
//second part: 1123
String decimal = "";
String integer = "";
xpointer=1182;
ypointer=165;
xpointer=RECT_SEARCH_PCT.x;
ypointer=RECT_SEARCH_PCT.y;
BufferedImage test = null;
trialloop:
while (ypointer<168) {
xpointer=1182;
while (xpointer>1132) {
while (ypointer<RECT_SEARCH_PCT.height) {
xpointer=RECT_SEARCH_PCT.x;
while (xpointer>RECT_SEARCH_PCT.width) {
int foundIndex = -1;
for (int i=0;i<10;i++) {
if (debug) {
@ -243,12 +255,12 @@ public class TypeFace2 {
ypointer++;
}
xpointer=1123;
ypointer=165;
xpointer=RECT_SEARCH_PCT2.x;
ypointer=RECT_SEARCH_PCT2.y;
trialloop:
while (ypointer<168) {
xpointer=1123;
while (xpointer>1051) {
while (ypointer<RECT_SEARCH_PCT2.height) {
xpointer=RECT_SEARCH_PCT2.x;
while (xpointer>RECT_SEARCH_PCT2.width) {
int foundIndex = -1;
for (int i=0;i<10;i++) {
if (debug) {
@ -375,74 +387,83 @@ public class TypeFace2 {
this.img=img;
File f = null;
BufferedImage test = null;
xpointer=99;
xpointer=RECT_SEARCH_COOL.width-1;
ypointer=0;
String total = "";
while (xpointer>22) {
int distance = 0;
int foundIndex = -1;
//Compare the 22x21 range.
for (int i=0;i<10;i++) {
if (debug) {
test = new BufferedImage(22,20,BufferedImage.TYPE_INT_ARGB);
}
boolean ruleBreak=false;
colorloop:
for (int x=0;x<22;x++) {
for (int y=0;y<20;y++) {
Color fontCol = new Color(font.getRGB(x+i*22,y));
Color pixelCol = new Color(img.getRGB(xpointer-22+x+1, y));
if (fontCol.equals(Color.RED) && pixelCol.getRed()<150
&& pixelCol.getGreen()<150 && pixelCol.getBlue()<150) {
//Breaks a rule.
ruleBreak=true;
if (!debug) {
break colorloop;
} else {
test.setRGB(x, y, Color.RED.getRGB());
}
} else
if (fontCol.equals(Color.GREEN) && (pixelCol.getRed()>166
|| pixelCol.getGreen()>171 || pixelCol.getBlue()>185)) {
//Breaks a rule.
ruleBreak=true;
if (!debug) {
break colorloop;
} else {
test.setRGB(x, y, Color.GREEN.getRGB());
trialloop:
while (ypointer<4) {
xpointer=RECT_SEARCH_COOL.width-1;
while (xpointer>22) {
int distance = 0;
int foundIndex = -1;
//Compare the 22x21 range.
for (int i=0;i<10;i++) {
if (debug) {
test = new BufferedImage(22,20,BufferedImage.TYPE_INT_ARGB);
}
boolean ruleBreak=false;
colorloop:
for (int x=0;x<22;x++) {
for (int y=0;y<20;y++) {
Color fontCol = new Color(font.getRGB(x+i*22,y));
Color pixelCol = new Color(img.getRGB(xpointer-22+x+1, y+ypointer));
if (fontCol.equals(Color.RED) && pixelCol.getRed()<150
&& pixelCol.getGreen()<150 && pixelCol.getBlue()<150) {
//Breaks a rule.
ruleBreak=true;
if (!debug) {
break colorloop;
} else {
test.setRGB(x, y, Color.RED.getRGB());
}
} else
if (fontCol.equals(Color.GREEN) && (pixelCol.getRed()>166
|| pixelCol.getGreen()>171 || pixelCol.getBlue()>185)) {
//Breaks a rule.
ruleBreak=true;
if (!debug) {
break colorloop;
} else {
test.setRGB(x, y, Color.GREEN.getRGB());
}
} else
if (debug) {
test.setRGB(x, y, pixelCol.getRGB());
}
} else
}
}
if (!ruleBreak) {
foundIndex=i;
if (debug) {
test.setRGB(x, y, pixelCol.getRGB());
System.out.println("Passes as "+((foundIndex+1)%10));
}
} else
if (debug) {
ImageIO.write(test,"png",new File("debug",System.nanoTime()+"_"+((i+1)%10)+".png"));
}
}
if (!ruleBreak) {
foundIndex=i;
if (foundIndex!=-1) {
//System.out.println(" Closest Match: Index "+((shortestIndex+1)%10)+" ("+shortestDistance+")");
if (total.equals("")) {
total = Integer.toString((foundIndex+1)%10);
} else {
total = Integer.toString((foundIndex+1)%10)+total;
}
if (debug) {
System.out.println("Passes as "+((foundIndex+1)%10));
System.out.println("Input as "+((foundIndex+1)%10));
System.out.println("-------------");
}
} else
if (debug) {
ImageIO.write(test,"png",new File("debug",System.nanoTime()+"_"+((i+1)%10)+".png"));
}
}
if (foundIndex!=-1) {
//System.out.println(" Closest Match: Index "+((shortestIndex+1)%10)+" ("+shortestDistance+")");
if (total.equals("")) {
total = Integer.toString((foundIndex+1)%10);
xpointer-=22;
} else {
total = Integer.toString((foundIndex+1)%10)+total;
}
if (debug) {
System.out.println("Input as "+((foundIndex+1)%10));
System.out.println("-------------");
//Try shifting the xpointer slowly to the right and try again.
xpointer--;
}
xpointer-=22;
} else {
//Try shifting the xpointer slowly to the right and try again.
xpointer--;
}
if (total.length()>0) {
break trialloop;
}
ypointer++;
}
if (total.equals("")) {
@ -456,12 +477,12 @@ public class TypeFace2 {
this.img=img;
File f = null;
BufferedImage test = null;
xpointer=249;
xpointer=RECT_SEARCH_SCORE.width-1;
ypointer=0;
String total = "";
trialloop:
while (ypointer<4) {
xpointer=249;
xpointer=RECT_SEARCH_SCORE.width-1;
while (xpointer>31) {
int distance = 0;
int foundIndex = -1;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Loading…
Cancel
Save