From 42fc334ed435b75468925494acf108ae8b64a7dd Mon Sep 17 00:00:00 2001 From: mrbesen Date: Fri, 26 May 2017 09:28:53 +0200 Subject: [PATCH] bug fix --- src/mrbesen/cr/auto/clicker/Clicker.java | 17 ++++++--- .../cr/auto/clicker/PosColSelector.java | 38 ++++++++++++++++++- src/mrbesen/cr/auto/clicker/UI.java | 4 +- 3 files changed, 50 insertions(+), 9 deletions(-) diff --git a/src/mrbesen/cr/auto/clicker/Clicker.java b/src/mrbesen/cr/auto/clicker/Clicker.java index 131be20..54502dc 100644 --- a/src/mrbesen/cr/auto/clicker/Clicker.java +++ b/src/mrbesen/cr/auto/clicker/Clicker.java @@ -31,6 +31,8 @@ public class Clicker implements Runnable{ private boolean doubleplayout = true; private int truppenwait = 180; private int randomness = 15; + + private int mincolordistance = 35; private void sleep( int ms) { if(skipbattle) @@ -137,6 +139,7 @@ public class Clicker implements Runnable{ sleep(9000);//9 sec-loading screen //checken, ob Arena wechsel pop-up while(checkOK(arena_switch, rob,arena_view)) { + System.out.println("Arena found, clicking"); clickL(rob, arena_switch); sleep(2000); } @@ -264,16 +267,16 @@ public class Clicker implements Runnable{ for (int y = 0; y < 20; y++) { int color = img.getRGB(x, y); int red = (color & 0x00ff0000) >> 16; - int green = (color & 0x0000ff00) >> 8; - int blue = color & 0x000000ff; - double distance = Math.sqrt(Math.pow((blue - goalcolor.getBlue()), 2) + int green = (color & 0x0000ff00) >> 8; + int blue = color & 0x000000ff; + double distance = Math.sqrt(Math.pow((blue - goalcolor.getBlue()), 2) + Math.pow((red - goalcolor.getRed()), 2) + Math.pow((green - goalcolor.getGreen()), 2));//calculate the distance between the goalcolor and the test color - if (distance < 25) + if (distance < mincolordistance) count++; } } - // System.out.println("checking ok takes: " + (System.currentTimeMillis() - start));//some performance checking +// System.out.println("counts: " + count);//some performance checking return count > 70; } @@ -301,7 +304,7 @@ public class Clicker implements Runnable{ * @param c Color * @param colornum nummber (0=ok-button, 1=arena_view-button) */ - public void setColor(Color c, int colornum) { + public void setColor(Color c, int colornum, int minimumdistance) { switch(colornum) { case 0: ok_button = c; @@ -310,6 +313,8 @@ public class Clicker implements Runnable{ arena_view = c; break; } + if(mincolordistance < minimumdistance) + mincolordistance = minimumdistance; System.out.println(colornum + ": "+c.getRed() + " " + c.getGreen() + " " + c.getBlue()); } } \ No newline at end of file diff --git a/src/mrbesen/cr/auto/clicker/PosColSelector.java b/src/mrbesen/cr/auto/clicker/PosColSelector.java index 583af5c..6d1204e 100644 --- a/src/mrbesen/cr/auto/clicker/PosColSelector.java +++ b/src/mrbesen/cr/auto/clicker/PosColSelector.java @@ -5,6 +5,9 @@ import java.awt.Color; import java.awt.Rectangle; import java.awt.Robot; import java.awt.image.BufferedImage; +import java.util.Comparator; +import java.util.LinkedList; +import java.util.List; public class PosColSelector extends PosSelector { @@ -40,7 +43,40 @@ public class PosColSelector extends PosSelector { blue /= count; green /= count; Color c = new Color(red, green, blue); - ui.bot.setColor(c,colornum); + + //calculate distances: + List dist = new LinkedList(); + for (int x = 0; x < 20; x++) { + for (int y = 0; y < 20; y++) { + int color = img.getRGB(x, y); + int redf = (color & 0x00ff0000) >> 16; + int greenf = (color & 0x0000ff00) >> 8; + int bluef = color & 0x000000ff; + double distance = Math.sqrt(Math.pow((bluef - c.getBlue()), 2) + + Math.pow((redf - c.getRed()), 2) + Math.pow((greenf - c.getGreen()), 2)); + dist.add((int) distance); +// System.out.println(distance); + } + } + + dist.sort(new Comparator() { + @Override + public int compare(Integer o1, Integer o2) { + if(o1 < o2) + return -1; + if(o1== o2) + return 0; + if(o1 > o2) + return 1; + return 0; + } + }); + + int miniumdistance = dist.get(150);//at least the first 100 tests should fit +// int maximumdistance = dist.get(dist.size()-1); + System.out.println("minimum distance: " + miniumdistance ); + ui.bot.setColor(c,colornum, miniumdistance); + ui.bot.set(p, num); } catch(AWTException e) { e.printStackTrace(); } diff --git a/src/mrbesen/cr/auto/clicker/UI.java b/src/mrbesen/cr/auto/clicker/UI.java index f9bfac6..5e0d7d2 100644 --- a/src/mrbesen/cr/auto/clicker/UI.java +++ b/src/mrbesen/cr/auto/clicker/UI.java @@ -214,10 +214,10 @@ public class UI implements ActionListener { slider[1].setValue(Integer.parseInt(split[1])); } else if(num == 104) { Color c = new Color(Integer.parseInt(split[1]), Integer.parseInt(split[2]), Integer.parseInt(split[3])); - bot.setColor(c, 1); + bot.setColor(c, 1,35); } else if(num == 105) { Color c = new Color(Integer.parseInt(split[1]), Integer.parseInt(split[2]), Integer.parseInt(split[3])); - bot.setColor(c, 0); + bot.setColor(c, 0,35); } } else //standard Point Obj. bot.set(new Point(split[1]), num);