diff --git a/DivaBot/DivaBot.jar b/DivaBot/DivaBot.jar index 60dd79e..482b82f 100644 Binary files a/DivaBot/DivaBot.jar and b/DivaBot/DivaBot.jar differ diff --git a/DivaBot/calibration_data.txt b/DivaBot/calibration_data.txt index 38f461e..f387198 100644 --- a/DivaBot/calibration_data.txt +++ b/DivaBot/calibration_data.txt @@ -1,4 +1,4 @@ -517 -265 -1485 -808 +521 +299 +1490 +842 diff --git a/DivaBot/rectangle0.png b/DivaBot/rectangle0.png index 7d66b2c..c701e05 100644 Binary files a/DivaBot/rectangle0.png and b/DivaBot/rectangle0.png differ diff --git a/DivaBot/rectangle1.png b/DivaBot/rectangle1.png index bb4f5a0..b81c338 100644 Binary files a/DivaBot/rectangle1.png and b/DivaBot/rectangle1.png differ diff --git a/DivaBot/rectangle2.png b/DivaBot/rectangle2.png index b47150d..b8a7f2b 100644 Binary files a/DivaBot/rectangle2.png and b/DivaBot/rectangle2.png differ diff --git a/DivaBot/rectangle3.png b/DivaBot/rectangle3.png index 781fd41..599e55d 100644 Binary files a/DivaBot/rectangle3.png and b/DivaBot/rectangle3.png differ diff --git a/DivaBot/rectangle4.png b/DivaBot/rectangle4.png index 148e486..3991d54 100644 Binary files a/DivaBot/rectangle4.png and b/DivaBot/rectangle4.png differ diff --git a/DivaBot/src/sig/Calibrator.java b/DivaBot/src/sig/Calibrator.java index 448855c..add4c8e 100644 --- a/DivaBot/src/sig/Calibrator.java +++ b/DivaBot/src/sig/Calibrator.java @@ -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--; diff --git a/DivaBot/src/sig/MyRobot.java b/DivaBot/src/sig/MyRobot.java index 670627a..8d39743 100644 --- a/DivaBot/src/sig/MyRobot.java +++ b/DivaBot/src/sig/MyRobot.java @@ -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 params = new ArrayList(); - 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 params = new ArrayList(); + 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=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 { diff --git a/DivaBot/src/sig/Result.java b/DivaBot/src/sig/Result.java index f0560a1..0533acc 100644 --- a/DivaBot/src/sig/Result.java +++ b/DivaBot/src/sig/Result.java @@ -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(); + } } diff --git a/DivaBot/src/sig/SongData.java b/DivaBot/src/sig/SongData.java index 93a6770..a798ea4 100644 --- a/DivaBot/src/sig/SongData.java +++ b/DivaBot/src/sig/SongData.java @@ -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=MAXTHRESHOLD && distance=MAXTHRESHOLD && distance1132) { + while (ypointerRECT_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 (ypointerRECT_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; diff --git a/DivaBot/typeface.png b/DivaBot/typeface.png index 87da6e7..dfca268 100644 Binary files a/DivaBot/typeface.png and b/DivaBot/typeface.png differ diff --git a/DivaBot/typeface2.png b/DivaBot/typeface2.png index 7c9b9b3..c55c7df 100644 Binary files a/DivaBot/typeface2.png and b/DivaBot/typeface2.png differ