-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGenerateBoard.java
More file actions
342 lines (285 loc) · 7.81 KB
/
GenerateBoard.java
File metadata and controls
342 lines (285 loc) · 7.81 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
import java.awt.*;
import java.awt.image.*;
public class GenerateBoard {
//pixel-fix (width then height)
int[] pixelFix = new int[] {1, 1};
//width and height of each square
int w = 0, h = 0;
//sensitivity to variations in rgb values (around 15-20 works well)
int sens = 20;
//light and dark green colors on board respectively
int[] c1 = new int[] {170, 215, 81};
int[] c2 = new int[] {162, 209, 73};
//title card color
int[] t1 = new int[] {84, 111, 68};
int[] t2 = new int[] {76, 111, 71};
//board colors when clicked
int[] b1 = new int[]{228, 194, 159};
int[] b2 = new int[]{215, 184, 153};
//numbers from 1-6
int[] blue = new int[]{35, 122, 207};
int[] green = new int[]{87, 149, 76};
int[] red = new int[]{211, 52, 51};
int[] purple = new int[]{166, 103, 157};
int[] orange = new int[]{235, 153, 53};
int[] teal = new int[]{96, 171, 167};
//find where the board is located on the screen
public int[][][] findBoardCoords(int a, int b) throws AWTException {
int[][][] board = new int[a][b][2];
ReadScreen rs = new ReadScreen();
int width = rs.screenSize.width;
int height = rs.screenSize.height;
BufferedImage capture = rs.capture();
int counter = height * width - 1;
int[] colors;
boolean flag;
int w = 0, h = -1;
/*
do {
flag = false;
colors = rs.getColors(counter / width, counter % width, capture);
for (int i = 0; i < 3; i++) {
if (c1[i] != colors[i]) {
flag = true;
break;
}
}
counter--;
} while(flag && counter > 0);
flag = true;
while(flag && counter > 0) {
counter--;
w++;
flag = false;
colors = rs.getColors(counter / width, counter % width, capture);
for (int i = 0; i < 3; i++) {
if (c2[i] != colors[i]) {
flag = true;
break;
}
}
}
this.w = w;
flag = true;
while (flag && counter > 0) {
counter -= width;
h++;
flag = false;
colors = rs.getColors(counter / width, counter % width, capture);
for (int i = 0; i < 3; i++) {
if (c1[i] != colors[i]) {
flag = true;
break;
}
}
}
this.h = h;
System.out.println(h + " " + w);
if (counter < 0) {
throw new ArrayIndexOutOfBoundsException();
}
*/
/*
counter = 0;
do {
flag = false;
colors = rs.getColors(counter % height, counter / height, capture);
for (int i = 0; i < 3; i++) {
if (t1[i] - 10 > colors[i] || t1[i] + 10 < colors[i]) {
flag = true;
}
}
counter++;
} while(flag && width > counter / height);
int border1 = counter / height;
counter = 0;
do {
flag = false;
colors = rs.getColors(counter % height, width - counter / height - 1, capture);
for (int i = 0; i < 3; i++) {
if (t1[i] - 10 > colors[i] || t1[i] + 10 < colors[i]) {
flag = true;
}
}
counter++;
} while(flag && width > counter / height);
int border2 = width - counter / height - 1;
System.out.println(border1 + " " + border2);
w = (border2 - border1 + 1) / b;
h = w;
System.out.println(h + " " + w);
*/
counter = 0;
do {
flag = false;
colors = rs.getColors(height - counter / width - 1, width - counter % width - 1, capture);
for (int i = 0; i < 3; i++) {
if (c1[i] != colors[i]) {
flag = true;
}
}
counter++;
} while(flag && height > counter / width);
int[] endCorner = new int[2];
endCorner[0] = height - counter / width - 1;
endCorner[1] = width - counter % width - 1;
counter = 0;
do {
flag = false;
colors = rs.getColors(counter / width, counter % width, capture);
for (int i = 0; i < 3; i++) {
if (c1[i] != colors[i]) {
flag = true;
}
}
counter++;
} while(flag && height > counter / width);
board[0][0][0] = counter / width;
board[0][0][1] = counter % width;
w = (endCorner[0] - board[0][0][0]) / a + pixelFix[0];
h = (endCorner[1] - board[0][0][1]) / b + pixelFix[1];
this.w = w;
this.h = h;
System.out.println(board[0][0][0] + " " + board[0][0][1]);
for (int i = 0; i < a; i++) {
for (int j = 0; j < b; j++) {
board[i][j][0] = board[0][0][0] + h * i;
board[i][j][1] = board[0][0][1] + w * j;
}
}
return board;
}
//print the board (for dev purposes)
public void printBoard(int[][][] board) {
for (int i = 0; i < board.length; i++) {
for (int j = 0; j < board[i].length; j++) {
System.out.print("(" + board[i][j][0] + ", " + board[i][j][1] + ")\t");
}
System.out.println();
}
}
//to determine what colors each number is (for dev purposes)
public void printColors(int[][][] board) throws AWTException {
ReadScreen rs = new ReadScreen();
BufferedImage capture = rs.capture();
int[] colors;
for (int i = 0; i < board.length; i++) {
for (int j = 0; j < board[i].length; j++) {
colors = rs.getColors(board[i][j][0] + h/2, board[i][j][1] + w/2, capture);
System.out.print("(" + colors[0] + "," + colors[1] + "," + colors[2] + ")\t");
}
System.out.println();
}
}
//get vals on board
public char[][] getNums(int[][][] board, int a, int b) throws AWTException {
ReadScreen rs = new ReadScreen();
char[][] nums = new char[a][b];
BufferedImage capture = rs.capture();
int[] colors;
int color;
int counter;
double sens = 0.7;
for (int i = 0; i < board.length; i++) {
for (int j = 0; j < board[i].length; j++) {
color = -1;
counter = - (int) (h/2 * sens);
/*while (color == -1) {
colors = rs.getColors(board[i][j][0] + h/2 + counter, board[i][j][1] + w/2, capture);
color = findValue(colors);
counter++;
if (counter > h/2 * sens) {
break;
}
}*/
while (color == -1 || color == 45) {
colors = rs.getColors(board[i][j][0] + h/2 + counter, board[i][j][1] + w/2 + counter, capture);
color = findValue(colors);
counter++;
if (counter > h/2 * sens) {
break;
}
}
nums[i][j] = (char) color;
}
}
return nums;
}
//find what number is at a certain position given the color
public int findValue(int[] color) {
boolean flag;
flag = true;
for (int i = 0; i < 3; i++) {
if ((b1[i] - sens > color[i] || b1[i] + sens < color[i]) && (b2[i] - sens > color[i] || b2[i] + sens < color[i])) {
flag = false;
}
}
if (flag) {
return 45;
}
flag = true;
for (int i = 0; i < 3; i++) {
if (blue[i] - sens > color[i] || blue[i] + sens < color[i]) {
flag = false;
}
}
if (flag) {
return 49;
}
flag = true;
for (int i = 0; i < 3; i++) {
if (green[i] - sens > color[i] || green[i] + sens < color[i]) {
flag = false;
}
}
if (flag) {
return 50;
}
flag = true;
for (int i = 0; i < 3; i++) {
if (red[i] - sens > color[i] || red[i] + sens < color[i]) {
flag = false;
}
}
if (flag) {
return 51;
}
flag = true;
for (int i = 0; i < 3; i++) {
if (purple[i] - sens > color[i] || purple[i] + sens < color[i]) {
flag = false;
}
}
if (flag) {
return 52;
}
flag = true;
for (int i = 0; i < 3; i++) {
if (orange[i] - sens > color[i] || orange[i] + sens < color[i]) {
flag = false;
}
}
if (flag) {
return 53;
}
flag = true;
for (int i = 0; i < 3; i++) {
if (teal[i] - sens > color[i] || teal[i] + sens < color[i]) {
flag = false;
}
}
if (flag) {
return 54;
}
flag = true;
for (int i = 0; i < 3; i++) {
if ((c1[i] - sens * 0.25 > color[i] || c1[i] + sens * 0.25 < color[i]) && (c2[i] - sens * 0.25 > color[i] || c2[i] + sens * 0.25 < color[i])) {
flag = false;
}
}
if (flag) {
return 35;
}
return -1;
}
}