-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbluedog.java
More file actions
120 lines (103 loc) · 3.11 KB
/
bluedog.java
File metadata and controls
120 lines (103 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package bluedog;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Robot;
public class bluedog {
public static void main(String args[]) throws AWTException, InterruptedException
{
int[][][] pos = new int[4][5][5];
//almost
pos[0][0]=new int[] {725,492,231,230,228};
pos[0][1]=new int[] {730,477,106,103,98};
pos[0][2]=new int[] {715,482,90,89,87};
pos[0][3]=new int[] {711,471,46,38,14};
pos[0][4]=new int[] {710,478,151,148,142};
//bad choice
pos[1][0]=new int[] {715,505,131,125,112};
pos[1][1]=new int[] {722,523,24,22,15};
pos[1][2]=new int[] {727,517,235,234,233};
pos[1][3]=new int[] {717,503,67,56,32};
pos[1][4]=new int[] {726,503,74,64,42};
//1st place
pos[2][0]=new int[] {715,483,227,226,225};
pos[2][1]=new int[] {711,485,71,63,49};
pos[2][2]=new int[] {735,477,82,76,67};
pos[2][3]=new int[] {724,473,174,169,162};
pos[2][4]=new int[] {715,490,130,124,115};
//second place
pos[3][0]=new int[] {721,496,40,32,18};
pos[3][1]=new int[] {711,493,231,230,228};
pos[3][2]=new int[] {712,495,223,222,220};
pos[3][3]=new int[] {719,503,101,98,93};
pos[3][4]=new int[] {728,498,64,55,40};
Color color;
int cr,cg,cb,i,nf=0;
final Robot robot = new Robot();
while(true)
{
for(i=0;i<5;i++)
{
color = robot.getPixelColor(pos[0][i][0], pos[0][i][1]);
cr=color.getRed();
cg=color.getGreen();
cb=color.getBlue();
if(compare(cr,cg,cb,pos[0][i][2],pos[0][i][3],pos[0][i][4])) i=6;
}
if(i==5)
{
System.out.println(nf + ":almost");
nf++;
Thread.sleep(8000);
}
for(i=0;i<5;i++)
{
color = robot.getPixelColor(pos[1][i][0], pos[1][i][1]);
cr=color.getRed();
cg=color.getGreen();
cb=color.getBlue();
if(compare(cr,cg,cb,pos[1][i][2],pos[1][i][3],pos[1][i][4])) i=6;
}
if(i==5)
{
System.out.println(nf + ":bad");
nf++;
Thread.sleep(8000);
}
for(i=0;i<5;i++)
{
color = robot.getPixelColor(pos[2][i][0], pos[2][i][1]);
cr=color.getRed();
cg=color.getGreen();
cb=color.getBlue();
if(compare(cr,cg,cb,pos[2][i][2],pos[2][i][3],pos[2][i][4])) i=6;
}
if(i==5)
{
System.out.println(nf + ":WIN!!!!!");
System.exit(0);
}
for(i=0;i<5;i++)
{
color = robot.getPixelColor(pos[3][i][0], pos[3][i][1]);
cr=color.getRed();
cg=color.getGreen();
cb=color.getBlue();
if(compare(cr,cg,cb,pos[3][i][2],pos[3][i][3],pos[3][i][4])) i=6;
}
if(i==5)
{
System.out.println(nf + ":second");
nf++;
Thread.sleep(8000);
}
Thread.sleep(1);
}
}
public static boolean compare(int a, int b, int c, int d, int e, int f) //return true if different
{
if(Math.abs(a-d)>10) return true;
else if(Math.abs(b-e)>10) return true;
else if(Math.abs(c-f)>10) return true;
return false;
}
}