-
Notifications
You must be signed in to change notification settings - Fork 0
/
DotsandBoxes.py
570 lines (482 loc) · 28.2 KB
/
DotsandBoxes.py
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
from tkinter import *
import heuristic
root=Tk()
root.title("Dots & Boxes")
root.resizable(width=False, height=False)
root.geometry("600x600+30+30")
#LOGIC
class RC(object):
def __init__(self):
self.row1 = [False] * 6
self.row2 = [False] * 6
self.row3 = [False] * 6
self.row4 = [False] * 6
self.row5 = [False] * 6
self.column1 = [False] * 6
self.column2 = [False] * 6
self.column3 = [False] * 6
self.column4 = [False] * 6
self.column5 = [False] * 6
class Board(object):
def __init__(self, data):
self.data = data
self.gameboard =[[self.data.row1[0],self.data.row1[1],self.data.column1[0],self.data.column1[1]],
[self.data.row1[1],self.data.row1[2],self.data.column2[0],self.data.column2[1]],
[self.data.row1[2],self.data.row1[3],self.data.column3[0],self.data.column3[1]],
[self.data.row1[3],self.data.row1[4],self.data.column4[0],self.data.column4[1]],
[self.data.row1[4],self.data.row1[5],self.data.column5[0],self.data.column5[1]],
[self.data.row2[0],self.data.row2[1],self.data.column1[1],self.data.column1[2]],
[self.data.row2[1],self.data.row2[2],self.data.column2[1],self.data.column2[2]],
[self.data.row2[2],self.data.row2[3],self.data.column3[1],self.data.column3[2]],
[self.data.row2[3],self.data.row2[4],self.data.column4[1],self.data.column4[2]],
[self.data.row2[4],self.data.row2[5],self.data.column5[1],self.data.column5[2]],
[self.data.row3[0],self.data.row3[1],self.data.column1[2],self.data.column1[3]],
[self.data.row3[1],self.data.row3[2],self.data.column2[2],self.data.column2[3]],
[self.data.row3[2],self.data.row3[3],self.data.column3[2],self.data.column3[3]],
[self.data.row3[3],self.data.row3[4],self.data.column4[2],self.data.column4[3]],
[self.data.row3[4],self.data.row3[5],self.data.column5[2],self.data.column5[3]],
[self.data.row4[0],self.data.row4[1],self.data.column1[3],self.data.column1[4]],
[self.data.row4[1],self.data.row4[2],self.data.column2[3],self.data.column2[4]],
[self.data.row4[2],self.data.row4[3],self.data.column3[3],self.data.column3[4]],
[self.data.row4[3],self.data.row4[4],self.data.column4[3],self.data.column4[4]],
[self.data.row4[4],self.data.row4[5],self.data.column5[3],self.data.column5[4]],
[self.data.row5[0],self.data.row5[1],self.data.column1[4],self.data.column1[5]],
[self.data.row5[1],self.data.row5[2],self.data.column2[4],self.data.column2[5]],
[self.data.row5[2],self.data.row5[3],self.data.column3[4],self.data.column3[5]],
[self.data.row5[3],self.data.row5[4],self.data.column4[4],self.data.column4[5]],
[self.data.row5[4],self.data.row5[5],self.data.column5[4],self.data.column5[5]],]
def create_board(*state):
if str(type("")) == "<class '__main__.RC'>":
return Board(state)
else:
data = RC()
return Board(data)
def update_board(state):
#print('Change')
return Board(state)
def make_a_move(data,d,dn,pos):
if(d=='r'):
direction=getattr(data,'row'+str(dn))
direction[pos-1]=True
setattr(data, 'row'+str(dn), direction)
else:
direction=getattr(data,'column'+str(dn))
direction[pos-1]=True
setattr(data, 'column'+str(dn), direction)
return update_board(data)
def is_valid_move(data,d,dn,pos):
if(d=='r'):
direction=getattr(data,'row'+str(dn))
return not direction[pos-1]
else:
direction=getattr(data,'column'+str(dn))
return not direction[pos-1]
data = RC()
board = create_board(data)
painted = [False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,
False,False,False,False,False,False,False,False,False]
boxes = heuristic.count_filled_boxes(board.gameboard)
turno_jugador = True
#LOGIC
canvas = Canvas(root)
for j in range(0,6):
for i in range(0,6):
canvas.create_oval(i*80+100, j*80+100, (i+1)*80, (j+1)*80, outline="blue",
fill="blue", width=2)
canvas.pack(fill=BOTH, expand=1)
def paint(x,y,d,dn,pos):
global board
if(((x > 80 and x < 100 and y > 100 and y < 160) or (d == 'r' and dn == 1 and pos == 1)) and is_valid_move(data,"r",1,1)):
board = make_a_move(data,"r",1,1)
canvas.create_line(90, 100, 90, 160, fill="red", width=10)
elif(((x > 80 and x < 100 and y > 180 and y < 240) or (d == 'r' and dn == 2 and pos == 1)) and is_valid_move(data,"r",2,1)):
board = make_a_move(data,"r",2,1)
canvas.create_line(90, 180, 90, 240, fill="red", width=10)
elif(((x > 80 and x < 100 and y > 260 and y < 320) or (d == 'r' and dn == 3 and pos == 1)) and is_valid_move(data,"r",3,1)):
board = make_a_move(data,"r",3,1)
canvas.create_line(90, 260, 90, 320, fill="red", width=10)
elif(((x > 80 and x < 100 and y > 340 and y < 400) or (d == 'r' and dn == 4 and pos == 1)) and is_valid_move(data,"r",4,1)):
board = make_a_move(data,"r",4,1)
canvas.create_line(90, 340, 90, 400, fill="red", width=10)
elif(((x > 80 and x < 100 and y > 420 and y < 480) or (d == 'r' and dn == 5 and pos == 1)) and is_valid_move(data,"r",5,1)):
board = make_a_move(data,"r",5,1)
canvas.create_line(90, 420, 90, 480, fill="red", width=10)
elif(((x > 160 and x < 180 and y > 100 and y < 160) or (d == 'r' and dn == 1 and pos == 2)) and is_valid_move(data,"r",1,2)):
board = make_a_move(data,"r",1,2)
canvas.create_line(170, 100, 170, 160, fill="red", width=10)
elif(((x > 160 and x < 180 and y > 180 and y < 240) or (d == 'r' and dn == 2 and pos == 2)) and is_valid_move(data,"r",2,2)):
board = make_a_move(data,"r",2,2)
canvas.create_line(170, 180, 170, 240, fill="red", width=10)
elif(((x > 160 and x < 180 and y > 260 and y < 320) or (d == 'r' and dn == 3 and pos == 2)) and is_valid_move(data,"r",3,2)):
board = make_a_move(data,"r",3,2)
canvas.create_line(170, 260, 170, 320, fill="red", width=10)
elif(((x > 160 and x < 180 and y > 340 and y < 400) or (d == 'r' and dn == 4 and pos == 2)) and is_valid_move(data,"r",4,2)):
board = make_a_move(data,"r",4,2)
canvas.create_line(170, 340, 170, 400, fill="red", width=10)
elif(((x > 160 and x < 180 and y > 420 and y < 480) or (d == 'r' and dn == 5 and pos == 2)) and is_valid_move(data,"r",5,2)):
board = make_a_move(data,"r",5,2)
canvas.create_line(170, 420, 170, 480, fill="red", width=10)
elif(((x > 240 and x < 260 and y > 100 and y < 160) or (d == 'r' and dn == 1 and pos == 3)) and is_valid_move(data,"r",1,3)):
board = make_a_move(data,"r",1,3)
canvas.create_line(250, 100, 250, 160, fill="red", width=10)
elif(((x > 240 and x < 260 and y > 180 and y < 240) or (d == 'r' and dn == 2 and pos == 3)) and is_valid_move(data,"r",2,3)):
board = make_a_move(data,"r",2,3)
canvas.create_line(250, 180, 250, 240, fill="red", width=10)
elif(((x > 240 and x < 260 and y > 260 and y < 320) or (d == 'r' and dn == 3 and pos == 3)) and is_valid_move(data,"r",3,3)):
board = make_a_move(data,"r",3,3)
canvas.create_line(250, 260, 250, 320, fill="red", width=10)
elif(((x > 240 and x < 260 and y > 340 and y < 400) or (d == 'r' and dn == 4 and pos == 3)) and is_valid_move(data,"r",4,3)):
board = make_a_move(data,"r",4,3)
canvas.create_line(250, 340, 250, 400, fill="red", width=10)
elif(((x > 240 and x < 260 and y > 420 and y < 480) or (d == 'r' and dn == 5 and pos == 3)) and is_valid_move(data,"r",5,3)):
board = make_a_move(data,"r",5,3)
canvas.create_line(250, 420, 250, 480, fill="red", width=10)
elif(((x > 320 and x < 340 and y > 100 and y < 160) or (d == 'r' and dn == 1 and pos == 4)) and is_valid_move(data,"r",1,4)):
board = make_a_move(data,"r",1,4)
canvas.create_line(330, 100, 330, 160, fill="red", width=10)
elif(((x > 320 and x < 340 and y > 180 and y < 240) or (d == 'r' and dn == 2 and pos == 4)) and is_valid_move(data,"r",2,4)):
board = make_a_move(data,"r",2,4)
canvas.create_line(330, 180, 330, 240, fill="red", width=10)
elif(((x > 320 and x < 340 and y > 260 and y < 320) or (d == 'r' and dn == 3 and pos == 4)) and is_valid_move(data,"r",3,4)):
board = make_a_move(data,"r",3,4)
canvas.create_line(330, 260, 330, 320, fill="red", width=10)
elif(((x > 320 and x < 340 and y > 340 and y < 400) or (d == 'r' and dn == 4 and pos == 4)) and is_valid_move(data,"r",4,4)):
board = make_a_move(data,"r",4,4)
canvas.create_line(330, 340, 330, 400, fill="red", width=10)
elif(((x > 320 and x < 340 and y > 420 and y < 480) or (d == 'r' and dn == 5 and pos == 4)) and is_valid_move(data,"r",5,4)):
board = make_a_move(data,"r",5,4)
canvas.create_line(330, 420, 330, 480, fill="red", width=10)
elif(((x > 400 and x < 420 and y > 100 and y < 160) or (d == 'r' and dn == 1 and pos == 5)) and is_valid_move(data,"r",1,5)):
board = make_a_move(data,"r",1,5)
canvas.create_line(410, 100, 410, 160, fill="red", width=10)
elif(((x > 400 and x < 420 and y > 180 and y < 240) or (d == 'r' and dn == 2 and pos == 5)) and is_valid_move(data,"r",2,5)):
board = make_a_move(data,"r",2,5)
canvas.create_line(410, 180, 410, 240, fill="red", width=10)
elif(((x > 400 and x < 420 and y > 260 and y < 320) or (d == 'r' and dn == 3 and pos == 5)) and is_valid_move(data,"r",3,5)):
board = make_a_move(data,"r",3,5)
canvas.create_line(410, 260, 410, 320, fill="red", width=10)
elif(((x > 400 and x < 420 and y > 340 and y < 400) or (d == 'r' and dn == 4 and pos == 5)) and is_valid_move(data,"r",4,5)):
board = make_a_move(data,"r",4,5)
canvas.create_line(410, 340, 410, 400, fill="red", width=10)
elif(((x > 400 and x < 420 and y > 420 and y < 480) or (d == 'r' and dn == 5 and pos == 5)) and is_valid_move(data,"r",5,5)):
board = make_a_move(data,"r",5,5)
canvas.create_line(410, 420, 410, 480, fill="red", width=10)
elif(((x > 480 and x < 500 and y > 100 and y < 160) or (d == 'r' and dn == 1 and pos == 6)) and is_valid_move(data,"r",1,6)):
board = make_a_move(data,"r",1,6)
canvas.create_line(490, 100, 490, 160, fill="red", width=10)
elif(((x > 480 and x < 500 and y > 180 and y < 240) or (d == 'r' and dn == 2 and pos == 6)) and is_valid_move(data,"r",2,6)):
board = make_a_move(data,"r",2,6)
canvas.create_line(490, 180, 490, 240, fill="red", width=10)
elif(((x > 480 and x < 500 and y > 260 and y < 320) or (d == 'r' and dn == 3 and pos == 6)) and is_valid_move(data,"r",3,6)):
board = make_a_move(data,"r",3,6)
canvas.create_line(490, 260, 490, 320, fill="red", width=10)
elif(((x > 480 and x < 500 and y > 340 and y < 400) or (d == 'r' and dn == 4 and pos == 6)) and is_valid_move(data,"r",4,6)):
board = make_a_move(data,"r",4,6)
canvas.create_line(490, 340, 490, 400, fill="red", width=10)
elif(((x > 480 and x < 500 and y > 420 and y < 480) or (d == 'r' and dn == 5 and pos == 6)) and is_valid_move(data,"r",5,6)):
board = make_a_move(data,"r",5,6)
canvas.create_line(490, 420, 490, 480, fill="red", width=10)
elif(((x > 100 and x < 160 and y > 80 and y < 100) or (d == 'c' and dn == 1 and pos == 1)) and is_valid_move(data,"c",1,1)):
board = make_a_move(data,"c",1,1)
canvas.create_line(100, 90, 160, 90, fill="red", width=10)
elif(((x > 100 and x < 160 and y > 160 and y < 180) or (d == 'c' and dn == 1 and pos == 2)) and is_valid_move(data,"c",1,2)):
board = make_a_move(data,"c",1,2)
canvas.create_line(100, 170, 160, 170, fill="red", width=10)
elif(((x > 100 and x < 160 and y > 240 and y < 260) or (d == 'c' and dn == 1 and pos == 3)) and is_valid_move(data,"c",1,3)):
board = make_a_move(data,"c",1,3)
canvas.create_line(100, 250, 160, 250, fill="red", width=10)
elif(((x > 100 and x < 160 and y > 320 and y < 340) or (d == 'c' and dn == 1 and pos == 4)) and is_valid_move(data,"c",1,4)):
board = make_a_move(data,"c",1,4)
canvas.create_line(100, 330, 160, 330, fill="red", width=10)
elif(((x > 100 and x < 160 and y > 400 and y < 420) or (d == 'c' and dn == 1 and pos == 5)) and is_valid_move(data,"c",1,5)):
board = make_a_move(data,"c",1,5)
canvas.create_line(100, 410, 160, 410, fill="red", width=10)
elif(((x > 100 and x < 160 and y > 480 and y < 500) or (d == 'c' and dn == 1 and pos == 6)) and is_valid_move(data,"c",1,6)):
board = make_a_move(data,"c",1,6)
canvas.create_line(100, 490, 160, 490, fill="red", width=10)
elif(((x > 180 and x < 240 and y > 80 and y < 100) or (d == 'c' and dn == 2 and pos == 1)) and is_valid_move(data,"c",2,1)):
board = make_a_move(data,"c",2,1)
canvas.create_line(180, 90, 240, 90, fill="red", width=10)
elif(((x > 180 and x < 240 and y > 160 and y < 180) or (d == 'c' and dn == 2 and pos == 2)) and is_valid_move(data,"c",2,2)):
board = make_a_move(data,"c",2,2)
canvas.create_line(180, 170, 240, 170, fill="red", width=10)
elif(((x > 180 and x < 240 and y > 240 and y < 260) or (d == 'c' and dn == 2 and pos == 3)) and is_valid_move(data,"c",2,3)):
board = make_a_move(data,"c",2,3)
canvas.create_line(180, 250, 240, 250, fill="red", width=10)
elif(((x > 180 and x < 240 and y > 320 and y < 340) or (d == 'c' and dn == 2 and pos == 4)) and is_valid_move(data,"c",2,4)):
board = make_a_move(data,"c",2,4)
canvas.create_line(180, 330, 240, 330, fill="red", width=10)
elif(((x > 180 and x < 240 and y > 400 and y < 420) or (d == 'c' and dn == 2 and pos == 5)) and is_valid_move(data,"c",2,5)):
board = make_a_move(data,"c",2,5)
canvas.create_line(180, 410, 240, 410, fill="red", width=10)
elif(((x > 180 and x < 240 and y > 480 and y < 500) or (d == 'c' and dn == 2 and pos == 6)) and is_valid_move(data,"c",2,6)):
board = make_a_move(data,"c",2,6)
canvas.create_line(180, 490, 240, 490, fill="red", width=10)
elif(((x > 260 and x < 320 and y > 80 and y < 100) or (d == 'c' and dn == 3 and pos == 1)) and is_valid_move(data,"c",3,1)):
board = make_a_move(data,"c",3,1)
canvas.create_line(260, 90, 320, 90, fill="red", width=10)
elif(((x > 260 and x < 320 and y > 160 and y < 180) or (d == 'c' and dn == 3 and pos == 2)) and is_valid_move(data,"c",3,2)):
board = make_a_move(data,"c",3,2)
canvas.create_line(260, 170, 320, 170, fill="red", width=10)
elif(((x > 260 and x < 320 and y > 240 and y < 260) or (d == 'c' and dn == 3 and pos == 3)) and is_valid_move(data,"c",3,3)):
board = make_a_move(data,"c",3,3)
canvas.create_line(260, 250, 320, 250, fill="red", width=10)
elif(((x > 260 and x < 320 and y > 320 and y < 340) or (d == 'c' and dn == 3 and pos == 4)) and is_valid_move(data,"c",3,4)):
board = make_a_move(data,"c",3,4)
canvas.create_line(260, 330, 320, 330, fill="red", width=10)
elif(((x > 260 and x < 320 and y > 400 and y < 420) or (d == 'c' and dn == 3 and pos == 5)) and is_valid_move(data,"c",3,5)):
board = make_a_move(data,"c",3,5)
canvas.create_line(260, 410, 320, 410, fill="red", width=10)
elif(((x > 260 and x < 320 and y > 480 and y < 500) or (d == 'c' and dn == 3 and pos == 6)) and is_valid_move(data,"c",3,6)):
board = make_a_move(data,"c",3,6)
canvas.create_line(260, 490, 320, 490, fill="red", width=10)
elif(((x > 340 and x < 400 and y > 80 and y < 100) or (d == 'c' and dn == 4 and pos == 1)) and is_valid_move(data,"c",4,1)):
board = make_a_move(data,"c",4,1)
canvas.create_line(340, 90, 400, 90, fill="red", width=10)
elif(((x > 340 and x < 400 and y > 160 and y < 180) or (d == 'c' and dn == 4 and pos == 2)) and is_valid_move(data,"c",4,2)):
board = make_a_move(data,"c",4,2)
canvas.create_line(340, 170, 400, 170, fill="red", width=10)
elif(((x > 340 and x < 400 and y > 240 and y < 260) or (d == 'c' and dn == 4 and pos == 3)) and is_valid_move(data,"c",4,3)):
board = make_a_move(data,"c",4,3)
canvas.create_line(340, 250, 400, 250, fill="red", width=10)
elif(((x > 340 and x < 400 and y > 320 and y < 340) or (d == 'c' and dn == 4 and pos == 4)) and is_valid_move(data,"c",4,4)):
board = make_a_move(data,"c",4,4)
canvas.create_line(340, 330, 400, 330, fill="red", width=10)
elif(((x > 340 and x < 400 and y > 400 and y < 420) or (d == 'c' and dn == 4 and pos == 5)) and is_valid_move(data,"c",4,5)):
board = make_a_move(data,"c",4,5)
canvas.create_line(340, 410, 400, 410, fill="red", width=10)
elif(((x > 340 and x < 400 and y > 480 and y < 500) or (d == 'c' and dn == 4 and pos == 6)) and is_valid_move(data,"c",4,6)):
board = make_a_move(data,"c",4,6)
canvas.create_line(340, 490, 400, 490, fill="red", width=10)
elif(((x > 420 and x < 480 and y > 80 and y < 100) or (d == 'c' and dn == 5 and pos == 1)) and is_valid_move(data,"c",5,1)):
board = make_a_move(data,"c",5,1)
canvas.create_line(420, 90, 480, 90, fill="red", width=10)
elif(((x > 420 and x < 480 and y > 160 and y < 180) or (d == 'c' and dn == 5 and pos == 2)) and is_valid_move(data,"c",5,2)):
board = make_a_move(data,"c",5,2)
canvas.create_line(420, 170, 480, 170, fill="red", width=10)
elif(((x > 420 and x < 480 and y > 240 and y < 260) or (d == 'c' and dn == 5 and pos == 3)) and is_valid_move(data,"c",5,3)):
board = make_a_move(data,"c",5,3)
canvas.create_line(420, 250, 480, 250, fill="red", width=10)
elif(((x > 420 and x < 480 and y > 320 and y < 340) or (d == 'c' and dn == 5 and pos == 4)) and is_valid_move(data,"c",5,4)):
board = make_a_move(data,"c",5,4)
canvas.create_line(420, 330, 480, 330, fill="red", width=10)
elif(((x > 420 and x < 480 and y > 400 and y < 420) or (d == 'c' and dn == 5 and pos == 5)) and is_valid_move(data,"c",5,5)):
board = make_a_move(data,"c",5,5)
canvas.create_line(420, 410, 480, 410, fill="red", width=10)
elif(((x > 420 and x < 480 and y > 480 and y < 500) or (d == 'c' and dn == 5 and pos == 6)) and is_valid_move(data,"c",5,6)):
board = make_a_move(data,"c",5,6)
canvas.create_line(420, 490, 480, 490, fill="red", width=10)
else:
return False
return True
def paint_box(boxes,painted,jugador):
for box in boxes:
if(not painted[box]):
if(box==0):
if(jugador):
canvas.create_rectangle(100, 100, 160, 160,
outline="green", fill="green")
else:
canvas.create_rectangle(100, 100, 160, 160,
outline="yellow", fill="yellow")
if(box==1):
if(jugador):
canvas.create_rectangle(180, 100, 240, 160,
outline="green", fill="green")
else:
canvas.create_rectangle(180, 100, 240, 160,
outline="yellow", fill="yellow")
if(box==2):
if(jugador):
canvas.create_rectangle(260, 100, 320, 160,
outline="green", fill="green")
else:
canvas.create_rectangle(260, 100, 320, 160,
outline="yellow", fill="yellow")
if(box==3):
if(jugador):
canvas.create_rectangle(340, 100, 400, 160,
outline="green", fill="green")
else:
canvas.create_rectangle(340, 100, 400, 160,
outline="yellow", fill="yellow")
if(box==4):
if(jugador):
canvas.create_rectangle(420, 100, 480, 160,
outline="green", fill="green")
else:
canvas.create_rectangle(420, 100, 480, 160,
outline="yellow", fill="yellow")
if(box==5):
if(jugador):
canvas.create_rectangle(100, 180, 160, 240,
outline="green", fill="green")
else:
canvas.create_rectangle(100, 180, 160, 240,
outline="yellow", fill="yellow")
if(box==6):
if(jugador):
canvas.create_rectangle(180, 180, 240, 240,
outline="green", fill="green")
else:
canvas.create_rectangle(180, 180, 240, 240,
outline="yellow", fill="yellow")
if(box==7):
if(jugador):
canvas.create_rectangle(260, 180, 320, 240,
outline="green", fill="green")
else:
canvas.create_rectangle(260, 180, 320, 240,
outline="yellow", fill="yellow")
if(box==8):
if(jugador):
canvas.create_rectangle(340, 180, 400, 240,
outline="green", fill="green")
else:
canvas.create_rectangle(340, 180, 400, 240,
outline="yellow", fill="yellow")
if(box==9):
if(jugador):
canvas.create_rectangle(420, 180, 480, 240,
outline="green", fill="green")
else:
canvas.create_rectangle(420, 180, 480, 240,
outline="yellow", fill="yellow")
if(box==10):
if(jugador):
canvas.create_rectangle(100, 260, 160, 320,
outline="green", fill="green")
else:
canvas.create_rectangle(100, 260, 160, 320,
outline="yellow", fill="yellow")
if(box==11):
if(jugador):
canvas.create_rectangle(180, 260, 240, 320,
outline="green", fill="green")
else:
canvas.create_rectangle(180, 260, 240, 320,
outline="yellow", fill="yellow")
if(box==12):
if(jugador):
canvas.create_rectangle(260, 260, 320, 320,
outline="green", fill="green")
else:
canvas.create_rectangle(260, 260, 320, 320,
outline="yellow", fill="yellow")
if(box==13):
if(jugador):
canvas.create_rectangle(340, 260, 400, 320,
outline="green", fill="green")
else:
canvas.create_rectangle(340, 260, 400, 320,
outline="yellow", fill="yellow")
if(box==14):
if(jugador):
canvas.create_rectangle(420, 260, 480, 320,
outline="green", fill="green")
else:
canvas.create_rectangle(420, 260, 480, 320,
outline="yellow", fill="yellow")
if(box==15):
if(jugador):
canvas.create_rectangle(100, 340, 160, 400,
outline="green", fill="green")
else:
canvas.create_rectangle(100, 340, 160, 400,
outline="yellow", fill="yellow")
if(box==16):
if(jugador):
canvas.create_rectangle(180, 340, 240, 400,
outline="green", fill="green")
else:
canvas.create_rectangle(180, 340, 240, 400,
outline="yellow", fill="yellow")
if(box==17):
if(jugador):
canvas.create_rectangle(260, 340, 320, 400,
outline="green", fill="green")
else:
canvas.create_rectangle(260, 340, 320, 400,
outline="yellow", fill="yellow")
if(box==18):
if(jugador):
canvas.create_rectangle(340, 340, 400, 400,
outline="green", fill="green")
else:
canvas.create_rectangle(340, 340, 400, 400,
outline="yellow", fill="yellow")
if(box==19):
if(jugador):
canvas.create_rectangle(420, 340, 480, 400,
outline="green", fill="green")
else:
canvas.create_rectangle(420, 340, 480, 400,
outline="yellow", fill="yellow")
if(box==20):
if(jugador):
canvas.create_rectangle(100, 420, 160, 480,
outline="green", fill="green")
else:
canvas.create_rectangle(100, 420, 160, 480,
outline="yellow", fill="yellow")
if(box==21):
if(jugador):
canvas.create_rectangle(180, 420, 240, 480,
outline="green", fill="green")
else:
canvas.create_rectangle(180, 420, 240, 480,
outline="yellow", fill="yellow")
if(box==22):
if(jugador):
canvas.create_rectangle(260, 420, 320, 480,
outline="green", fill="green")
else:
canvas.create_rectangle(260, 420, 320, 480,
outline="yellow", fill="yellow")
if(box==23):
if(jugador):
canvas.create_rectangle(340, 420, 400, 480,
outline="green", fill="green")
else:
canvas.create_rectangle(340, 420, 400, 480,
outline="yellow", fill="yellow")
if(box==24):
if(jugador):
canvas.create_rectangle(420, 420, 480, 480,
outline="green", fill="green")
else:
canvas.create_rectangle(420, 420, 480, 480,
outline="yellow", fill="yellow")
painted[box] = True
return painted
def callback(event):
global data
global board
global boxes
global painted
global turno_jugador
jugada = True
print ("clicked at", event.x, event.y)
if(turno_jugador):
jugada = paint(event.x,event.y,"",0,0)
if(boxes == heuristic.count_filled_boxes(board.gameboard) and jugada and len(boxes)<25):
turno_jugador = False
play = heuristic.first_approach(data,board.gameboard)
print (play)
paint(0,0,play[0],play[1],play[2])
while(boxes != heuristic.count_filled_boxes(board.gameboard) and len(boxes)<24):
boxes = heuristic.count_filled_boxes(board.gameboard)
painted = paint_box(boxes,painted,False)
play = heuristic.first_approach(data,board.gameboard)
print (play)
paint(0,0,play[0],play[1],play[2])
painted = paint_box(boxes,painted,False)
print(boxes)
if(len(boxes)==25):
painted = paint_box(boxes,painted,False)
turno_jugador = True
else:
boxes = heuristic.count_filled_boxes(board.gameboard)
painted = paint_box(boxes,painted,True)
canvas.bind("<Button-1>", callback)
root.mainloop()