-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTesting.py
595 lines (509 loc) · 27.7 KB
/
Testing.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
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
import math
import pygame
# all our grids and maps are set up with [x][y] so therefore when visualizing
# [[ (0,0), (0, 1), (0,2) ],
# [ (1,0), (1, 1), (1,2) ],
# [ (2,0), (2, 1), (2,2) ]]
# so flip to left 90 degrees and horizontaly cut in middle and flip
# Node Class
class DoubleNode:
def __init__(self, x, y, pastNode=None, head=None):
self.x = x
self.y = y
self.pastNode = pastNode
if(head == None and pastNode != None):
self.head = pastNode.head
else:
self.head = head
def __str__(self):
return f"{self.x}{self.y}"
# use node that got cut to find its last accpectable pos
def gotCut(nodeCut):
cut = []
cut.append([nodeCut.x, nodeCut.y])
nodeCut = nodeCut.pastNode
cut.append(nodeCut)
return cut
# use node that cut itself to get path to erase and current pos
def cutBack(node):
cut = []
curX = node.x
curY = node.y
cur = node.pastNode
cut.append([cur.x, cur.y])
while(cur.x != curX or cur.y != curY):
cur = cur.pastNode
cut.append([cur.x, cur.y])
cut.pop(-1)
cut.append(cur)
return cut
def cutToPoint(nodeToCut, nodeToCutTo):
cut = []
cutToX = nodeToCutTo.x
cutToY = nodeToCutTo.y
cur = nodeToCut
cut.append([cur.x, cur.y])
while(cur.x != cutToX or cur.y != cutToY):
cur = cur.pastNode
cut.append([cur.x, cur.y])
cur = cur.pastNode
cut.append(cur)
return cut
def cutToStart(node):
cut = []
if(node.x == node.head.x and node.y == node.head.y):
return cut
cur = node
cut.append([cur.x, cur.y])
while(cur.x != node.head.x or cur.y != node.head.y):
cur = cur.pastNode
cut.append([cur.x, cur.y])
cut.pop(-1)
return cut
# Initialize Pygame
pygame.init()
points = []
colors = []
black = (0, 0, 0)
white = (255, 255, 255)
xSize = 0
ySize = 0
circRad = 0
cellSize = 0
f = open("map1.txt", "r")
for x in f:
if(x[0:1] == "g"):
x = x[2:]
space = x.find(" ")
xSize = int(x[0:space])
x = x[space+1:]
space = x.find(" ")
ySize = int(x[0:space])
continue
if(x[0:1] == "s"):
x = x[2:]
space = x.find(" ")
circRad = int(x[0:space])
x = x[space+1:]
space = x.find(" ")
cellSize = int(x[0:space])
continue
space = x.find(" ")
red = int(x[0:space])
x = x[space+1:]
space = x.find(" ")
green = int(x[0:space])
x = x[space+1:]
space = x.find(" ")
blue = int(x[0:space])
colors.append((red, green, blue))
x = x[space+3:]
space = x.find(" ")
firstXPos = int(x[0:space])
x = x[space+1:]
space = x.find(" ")
firstYPos = int(x[0:space])
points.append((firstXPos, firstYPos, (red, green, blue)))
x = x[space+3:]
space = x.find(" ")
secondXPos = int(x[0:space])
x = x[space+1:]
secondYPos = int(x[0:])
points.append((secondXPos, secondYPos, (red, green, blue)))
screen_width = cellSize * xSize
screen_height = cellSize * ySize
screen = pygame.display.set_mode((screen_width, screen_height))
screen.fill(black)
nodesDict = {}
for i in colors:
nodesDict.update({i:None})
typeGrid = []
colorGrid = []
for i in range(xSize):
typeGrid.append([])
colorGrid.append([])
for j in range(ySize):
typeGrid[i].append(0)
colorGrid[i].append(black)
for i in points:
typeGrid[i[0]][i[1]] = 2
colorGrid[i[0]][i[1]] = i[2]
def pixelPos(num):
return num * cellSize + 40
def draw():
for row in range(xSize):
for col in range(ySize):
x = row * cellSize
y = col * cellSize
if(typeGrid[row][col] == 2):
pygame.draw.circle(screen, colorGrid[row][col], (pixelPos(row), pixelPos(col)), 40 - 4)
pygame.draw.rect(screen, white, (x, y, cellSize, cellSize), 1)
def drawGrid():
for row in range(xSize):
for col in range(ySize):
x = row * cellSize
y = col * cellSize
pygame.draw.rect(screen, white, (x, y, cellSize, cellSize), 1)
draw()
pygame.display.flip()
curCelX = 0
curCelY = 0
pastCelX = 0
pastCelY = 0
pastPastCelX = 0
pastPastCelY = 0
inputs = (curCelX, curCelY, pastCelX, pastCelY, pastPastCelX, pastPastCelY, colorGrid[curCelX][curCelY], False)
def input(curCelX, curCelY, pastCelX, pastCelY, pastPastCelX, pastPastCelY):
mouseY = pygame.mouse.get_pos()[1]
mouseX = pygame.mouse.get_pos()[0]
mousePressed = pygame.mouse.get_pressed()[0]
futurecurCelX = (int) (mouseX / cellSize)
futurecurCelY = (int) (mouseY / cellSize)
if( (pastPastCelX != pastCelX or pastPastCelY != pastCelY) and (pastCelX != curCelX or pastCelY != curCelY)):
pastPastCelX = pastCelX
pastPastCelY = pastCelY
if( (pastCelX != curCelX or pastCelY != curCelY) and (curCelX != futurecurCelX or curCelY != futurecurCelY)):
pastCelX = curCelX
pastCelY = curCelY
curCelX = (int) (mouseX / cellSize)
curCelY = (int) (mouseY / cellSize)
if(colorGrid[curCelX][curCelY] != colorGrid[pastCelX][pastCelY] and ( (typeGrid[curCelX][curCelY] == 1 and typeGrid[pastCelX][pastCelY] == 1) or ((typeGrid[curCelX][curCelY] == 1 and typeGrid[pastCelX][pastCelY] == 2))) and (abs(curCelX-pastCelX) + abs(curCelY-pastCelY) == 1) ):
color = colorGrid[pastCelX][pastCelY]
elif(colorGrid[curCelX][curCelY] != black):
color = colorGrid[curCelX][curCelY]
else:
color = colorGrid[pastCelX][pastCelY]
if( (colorGrid[curCelX][curCelY] == black) and ( ((abs(curCelX - pastCelX) >= 1) ) and ((curCelY - pastCelY) >= 1) ) ):
return (curCelX, curCelY, pastCelX, pastCelY, pastPastCelX, pastPastCelY, colorGrid[pastCelX][pastCelY], False)
elif(mousePressed and ( ( (colorGrid[curCelX][curCelY] == colorGrid[pastCelX][pastCelY] and abs(curCelX - pastCelX) + abs(curCelY - pastCelY) <= 1 ) or (colorGrid[curCelX][curCelY] != colorGrid[pastCelX][pastCelY]) ) or (pastCelY == 0 and pastCelX == 0 and pastPastCelX == 0 and pastPastCelY == 0) )):
return (curCelX, curCelY, pastCelX, pastCelY, pastPastCelX, pastPastCelY, color, True)
else:
return (curCelX, curCelY, pastCelX, pastCelY, pastPastCelX, pastPastCelY, colorGrid[pastCelX][pastCelY], False)
# left down - 1
# left up - 2
# up right - 3
# up left - 4
# left down - 5
# left up - 6
# down right - 7
# down right - 8
lastTurn = [False, False, False, False, False, False, False, False]
def checkDrawing(curCelX, curCelY, pastCelX, pastCelY, pastPastCelX, pastPastCelY, color):
if((typeGrid[pastCelX][pastCelY] != 2)):
if(curCelX == pastCelX and curCelY > pastCelY and pastPastCelX < pastCelX and lastTurn[0] == False):
pygame.draw.rect(screen, black, (pixelPos(pastCelX) - circRad, pixelPos(pastCelY) - circRad / 2, circRad * 2, circRad), 0)
pygame.draw.circle(screen, color, (pixelPos(pastCelX), pixelPos(pastCelY)), circRad / 2)
pygame.draw.rect(screen, color, (pixelPos(pastCelX) - circRad, pixelPos(pastCelY) - circRad / 2, circRad, circRad))
pygame.draw.rect(screen, color, (pixelPos(pastCelX) - circRad / 2, pixelPos(pastCelY), circRad, circRad))
return
# draw right to up
elif(curCelX == pastCelX and curCelY < pastCelY and pastPastCelX < pastCelX and lastTurn[1] == False):
pygame.draw.rect(screen, black, (pixelPos(pastCelX) - circRad, pixelPos(pastCelY) - circRad / 2, circRad * 2, circRad), 0)
pygame.draw.circle(screen, color, (pixelPos(pastCelX), pixelPos(pastCelY)), circRad / 2)
pygame.draw.rect(screen, color, (pixelPos(pastCelX) - circRad, pixelPos(pastCelY) - circRad / 2, circRad, circRad))
pygame.draw.rect(screen, color, (pixelPos(pastCelX) - circRad / 2, pixelPos(pastCelY) - circRad, circRad, circRad))
return
# draw up to right
elif(curCelX > pastCelX and curCelY == pastCelY and pastPastCelY > pastCelY and lastTurn[2] == False):
pygame.draw.rect(screen, black, (pixelPos(pastCelX) - circRad / 2, pixelPos(pastCelY) - circRad, circRad, circRad * 2), 0)
pygame.draw.circle(screen, color, (pixelPos(pastCelX), pixelPos(pastCelY)), circRad / 2)
pygame.draw.rect(screen, color, (pixelPos(pastCelX), pixelPos(pastCelY) - circRad / 2, circRad, circRad))
pygame.draw.rect(screen, color, (pixelPos(pastCelX) - circRad / 2, pixelPos(pastCelY), circRad, circRad))
return
# draw up to left
elif(curCelX < pastCelX and curCelY == pastCelY and pastPastCelY > pastCelY and lastTurn[3] == False):
pygame.draw.rect(screen, black, (pixelPos(pastCelX) - circRad / 2, pixelPos(pastCelY) - circRad, circRad, circRad * 2), 0)
pygame.draw.circle(screen, color, (pixelPos(pastCelX), pixelPos(pastCelY)), circRad / 2)
pygame.draw.rect(screen, color, (pixelPos(pastCelX) - circRad, pixelPos(pastCelY) - circRad / 2, circRad, circRad))
pygame.draw.rect(screen, color, (pixelPos(pastCelX) - circRad / 2, pixelPos(pastCelY), circRad, circRad))
return
# draw left to down
elif(curCelX == pastCelX and curCelY > pastCelY and pastPastCelX > pastCelX and lastTurn[4] == False):
pygame.draw.rect(screen, black, (pixelPos(pastCelX) - circRad, pixelPos(pastCelY) - circRad / 2, circRad * 2, circRad), 0)
pygame.draw.circle(screen, color, (pixelPos(pastCelX), pixelPos(pastCelY)), circRad / 2)
pygame.draw.rect(screen, color, (pixelPos(pastCelX), pixelPos(pastCelY) - circRad / 2, circRad, circRad))
pygame.draw.rect(screen, color, (pixelPos(pastCelX) - circRad / 2, pixelPos(pastCelY), circRad, circRad))
return
# draw left to up
elif(curCelX == pastCelX and curCelY < pastCelY and pastPastCelX > pastCelX and lastTurn[5] == False):
pygame.draw.rect(screen, black, (pixelPos(pastCelX) - circRad, pixelPos(pastCelY) - circRad / 2, circRad * 2, circRad), 0)
pygame.draw.circle(screen, color, (pixelPos(pastCelX), pixelPos(pastCelY)), circRad / 2)
pygame.draw.rect(screen, color, (pixelPos(pastCelX), pixelPos(pastCelY) - circRad / 2, circRad, circRad))
pygame.draw.rect(screen, color, (pixelPos(pastCelX) - circRad / 2, pixelPos(pastCelY) - circRad, circRad, circRad))
return
# draw down to right
elif(curCelX > pastCelX and curCelY == pastCelY and pastPastCelY < pastCelY and lastTurn[6] == False):
pygame.draw.rect(screen, black, (pixelPos(pastCelX) - circRad / 2, pixelPos(pastCelY) - circRad, circRad, circRad * 2), 0)
pygame.draw.circle(screen, color, (pixelPos(pastCelX), pixelPos(pastCelY)), circRad / 2)
pygame.draw.rect(screen, color, (pixelPos(pastCelX), pixelPos(pastCelY) - circRad / 2, circRad, circRad))
pygame.draw.rect(screen, color, (pixelPos(pastCelX) - circRad / 2, pixelPos(pastCelY) - circRad, circRad, circRad))
return
# draw down to left
elif(curCelX < pastCelX and curCelY == pastCelY and pastPastCelY < pastCelY and lastTurn[7] == False):
pygame.draw.rect(screen, black, (pixelPos(pastCelX) - circRad / 2, pixelPos(pastCelY) - circRad, circRad, circRad * 2), 0)
pygame.draw.circle(screen, color, (pixelPos(pastCelX), pixelPos(pastCelY)), circRad / 2)
pygame.draw.rect(screen, color, (pixelPos(pastCelX) - circRad, pixelPos(pastCelY) - circRad / 2, circRad, circRad))
pygame.draw.rect(screen, color, (pixelPos(pastCelX) - circRad / 2, pixelPos(pastCelY) - circRad, circRad, circRad))
return
def DrawBoard(curCelX, curCelY, pastCelX, pastCelY, pastPastCelX, pastPastCelY, color, bleh):
print(str(curCelX) + " " + str(curCelY) + " " + str(pastCelX) + " " + str(pastCelY) + " " + str([pastPastCelX]) + " " + str(pastPastCelY) + " " + str(color))
# print(nodesDict.get(color))
if(typeGrid[curCelX][curCelY] == 2):
if(nodesDict.get(color) != None):
if( abs(nodesDict.get(color).x - curCelX) + abs(nodesDict.get(color).y - curCelY) == 1 and (nodesDict.get(color).head.x != curCelX or nodesDict.get(color).head.y != curCelY)):
checkDrawing(curCelX, curCelY, pastCelX, pastCelY, pastPastCelX, pastPastCelY, color)
return
curNode = nodesDict.get(color)
arr = cutToStart(curNode)
for i in arr:
typeGrid[i[0]][i[1]] = 0
colorGrid[i[0]][i[1]] = black
pygame.draw.rect(screen, black, (pixelPos(i[0]) - circRad, pixelPos(i[1]) - circRad, circRad * 2, circRad * 2), 0)
curNode = DoubleNode(curCelX, curCelY)
curNode = DoubleNode(curCelX, curCelY, curNode, curNode)
nodesDict.update({color : curNode})
else:
curNode = DoubleNode(curCelX, curCelY)
curNode = DoubleNode(curCelX, curCelY, curNode, curNode)
nodesDict.update({color : curNode})
elif(typeGrid[curCelX][curCelY] == 1):
if(colorGrid[curCelX][curCelY] == color):
if(nodesDict.get(color).pastNode.x != pastCelX and nodesDict.get(color).pastNode.y != pastCelY):
curNode = nodesDict.get(color)
if(typeGrid[pastCelX][pastCelY] == 2):
curNode = nodesDict.get(color)
arr = cutToStart(curNode)
for i in arr:
typeGrid[i[0]][i[1]] = 0
colorGrid[i[0]][i[1]] = black
pygame.draw.rect(screen, black, (pixelPos(i[0]) - circRad, pixelPos(i[1]) - circRad, circRad * 2, circRad * 2), 0)
curNode = DoubleNode(pastCelX, pastCelY)
curNode = DoubleNode(pastCelX, pastCelY, curNode, curNode)
curNode = DoubleNode(curCelX, curCelY, curNode)
nodesDict.update({color : curNode})
elif(curNode.pastNode == None):
return(curCelX, curCelY, 0, 0, 0, 0)
elif(curNode.pastNode.pastNode == None):
return(curCelX, curCelY, curNode.pastNode.x, curNode.pastNode.y, 0, 0)
else:
return(curCelX, curCelY, curNode.pastNode.x, curNode.pastNode.y, curNode.pastNode.pastNode.x, curNode.pastNode.pastNode.y)
else:
curNode = nodesDict.get(color)
curNode = DoubleNode(curCelX, curCelY, curNode)
nodesDict.update({color : curNode})
arr = cutBack(nodesDict.get(color))
newNode = arr[-1]
nodesDict.update({color: newNode})
arr.pop(-1)
for i in arr:
typeGrid[i[0]][i[1]] = 0
colorGrid[i[0]][i[1]] = black
pygame.draw.rect(screen, black, (pixelPos(i[0]) - circRad, pixelPos(i[1]) - circRad, circRad * 2, circRad * 2), 0)
curNode = nodesDict.get(color)
if(curNode.pastNode == None):
return(curCelX, curCelY, 0, 0, 0, 0)
elif(curNode.pastNode.pastNode == None):
return(curCelX, curCelY, curNode.pastNode.x, curNode.pastNode.y, 0, 0)
else:
return(curCelX, curCelY, curNode.pastNode.x, curNode.pastNode.y, curNode.pastNode.pastNode.x, curNode.pastNode.pastNode.y)
else:
print("dark age")
print(color)
if(typeGrid[pastCelX][pastCelY] == 2):
curNode = nodesDict.get(color)
arr = cutToStart(curNode)
for i in arr:
typeGrid[i[0]][i[1]] = 0
colorGrid[i[0]][i[1]] = black
pygame.draw.rect(screen, black, (pixelPos(i[0]) - circRad, pixelPos(i[1]) - circRad, circRad * 2, circRad * 2), 0)
curNode = DoubleNode(pastCelX, pastCelY)
curNode = DoubleNode(pastCelX, pastCelY, curNode, curNode)
nodesDict.update({color : curNode})
curNode = nodesDict.get(color)
curNode = DoubleNode(curCelX, curCelY, curNode)
nodesDict.update({color : curNode})
intersectingNode = nodesDict.get(colorGrid[curCelX][curCelY])
newIntersect = cutToPoint(intersectingNode, curNode)
intersectingNode = newIntersect[-1]
if(intersectingNode.x == curNode.x and intersectingNode.y == curNode.y):
intersectingNode = intersectingNode.pastNode
nodesDict.update({colorGrid[curCelX][curCelY] : intersectingNode})
newIntersect.pop(-1)
for i in newIntersect:
typeGrid[i[0]][i[1]] = 0
colorGrid[i[0]][i[1]] = black
pygame.draw.rect(screen, black, (pixelPos(i[0]) - circRad, pixelPos(i[1]) - circRad, circRad * 2, circRad * 2), 0)
if(curNode.head == None):
curNode = DoubleNode(curCelX, curCelY, curNode, curNode)
else:
curNode = DoubleNode(curCelX, curCelY, curNode)
if(curNode.head.x != nodesDict.get(color).head.x and curNode.head.y != nodesDict.get(color).head.y):
arr = cutToStart(nodesDict.get(color))
for i in arr:
typeGrid[i[0]][i[1]] = 0
colorGrid[i[0]][i[1]] = black
pygame.draw.rect(screen, black, (pixelPos(i[0]) - circRad, pixelPos(i[1]) - circRad, circRad * 2, circRad * 2), 0)
nodesDict.update({color: curNode})
else:
curNode = nodesDict.get(color)
if(typeGrid[pastCelX][pastCelY] == 2 and (curNode.head.x != pastCelX or curNode.head.y != pastCelY) ):
arr = cutToStart(curNode)
for i in arr:
typeGrid[i[0]][i[1]] = 0
colorGrid[i[0]][i[1]] = black
pygame.draw.rect(screen, black, (pixelPos(i[0]) - circRad, pixelPos(i[1]) - circRad, circRad * 2, circRad * 2), 0)
curNode = DoubleNode(pastCelX, pastCelY)
curNode = DoubleNode(pastCelX, pastCelY, curNode, curNode)
curNode = DoubleNode(curCelX, curCelY, curNode)
nodesDict.update({color : curNode})
elif(typeGrid[curNode.x][curNode.y] == 2 and (curNode.x != curCelX or curNode.y != curCelY)):
curNode = DoubleNode(curCelX, curCelY, curNode, curNode)
elif((curNode.x != curCelX or curNode.y != curCelY)):
curNode = DoubleNode(curCelX, curCelY, curNode)
nodesDict.update({color : curNode})
if((typeGrid[curCelX][curCelY] != 2) and (typeGrid[pastCelX][pastCelY] != 2)):
if(curCelX == pastCelX and curCelY > pastCelY and pastPastCelX < pastCelX and lastTurn[0] == False):
pygame.draw.rect(screen, black, (pixelPos(pastCelX) - circRad, pixelPos(pastCelY) - circRad / 2, circRad * 2, circRad), 0)
pygame.draw.circle(screen, color, (pixelPos(pastCelX), pixelPos(pastCelY)), circRad / 2)
pygame.draw.rect(screen, color, (pixelPos(pastCelX) - circRad, pixelPos(pastCelY) - circRad / 2, circRad, circRad))
pygame.draw.rect(screen, color, (pixelPos(pastCelX) - circRad / 2, pixelPos(pastCelY), circRad, circRad))
pygame.draw.rect(screen, color, (pixelPos(curCelX) - circRad / 2, pixelPos(curCelY) - circRad, circRad, circRad * 2), 0)
for i in range(len(lastTurn)):
lastTurn[i] = False
lastTurn[0] = True
colorGrid[curCelX][curCelY] = color
typeGrid[curCelX][curCelY] = 1
return
# draw right to up
elif(curCelX == pastCelX and curCelY < pastCelY and pastPastCelX < pastCelX and lastTurn[1] == False):
pygame.draw.rect(screen, black, (pixelPos(pastCelX) - circRad, pixelPos(pastCelY) - circRad / 2, circRad * 2, circRad), 0)
pygame.draw.circle(screen, color, (pixelPos(pastCelX), pixelPos(pastCelY)), circRad / 2)
pygame.draw.rect(screen, color, (pixelPos(pastCelX) - circRad, pixelPos(pastCelY) - circRad / 2, circRad, circRad))
pygame.draw.rect(screen, color, (pixelPos(pastCelX) - circRad / 2, pixelPos(pastCelY) - circRad, circRad, circRad))
pygame.draw.rect(screen, color, (pixelPos(curCelX) - circRad / 2, pixelPos(curCelY) - circRad, circRad, circRad * 2), 0)
for i in range(len(lastTurn)):
lastTurn[i] = False
lastTurn[1] = True
colorGrid[curCelX][curCelY] = color
typeGrid[curCelX][curCelY] = 1
return
# draw up to right
elif(curCelX > pastCelX and curCelY == pastCelY and pastPastCelY > pastCelY and lastTurn[2] == False):
pygame.draw.rect(screen, black, (pixelPos(pastCelX) - circRad / 2, pixelPos(pastCelY) - circRad, circRad, circRad * 2), 0)
pygame.draw.circle(screen, color, (pixelPos(pastCelX), pixelPos(pastCelY)), circRad / 2)
pygame.draw.rect(screen, color, (pixelPos(pastCelX), pixelPos(pastCelY) - circRad / 2, circRad, circRad))
pygame.draw.rect(screen, color, (pixelPos(pastCelX) - circRad / 2, pixelPos(pastCelY), circRad, circRad))
pygame.draw.rect(screen, color, (pixelPos(curCelX) - circRad, pixelPos(curCelY) - circRad / 2, circRad * 2, circRad), 0)
for i in range(len(lastTurn)):
lastTurn[i] = False
lastTurn[2] = True
colorGrid[curCelX][curCelY] = color
typeGrid[curCelX][curCelY] = 1
return
# draw up to left
elif(curCelX < pastCelX and curCelY == pastCelY and pastPastCelY > pastCelY and lastTurn[3] == False):
pygame.draw.rect(screen, black, (pixelPos(pastCelX) - circRad / 2, pixelPos(pastCelY) - circRad, circRad, circRad * 2), 0)
pygame.draw.circle(screen, color, (pixelPos(pastCelX), pixelPos(pastCelY)), circRad / 2)
pygame.draw.rect(screen, color, (pixelPos(pastCelX) - circRad, pixelPos(pastCelY) - circRad / 2, circRad, circRad))
pygame.draw.rect(screen, color, (pixelPos(pastCelX) - circRad / 2, pixelPos(pastCelY), circRad, circRad))
pygame.draw.rect(screen, color, (pixelPos(curCelX) - circRad, pixelPos(curCelY) - circRad / 2, circRad * 2, circRad), 0)
for i in range(len(lastTurn)):
lastTurn[i] = False
lastTurn[3] = True
colorGrid[curCelX][curCelY] = color
typeGrid[curCelX][curCelY] = 1
return
# draw left to down
elif(curCelX == pastCelX and curCelY > pastCelY and pastPastCelX > pastCelX and lastTurn[4] == False):
pygame.draw.rect(screen, black, (pixelPos(pastCelX) - circRad, pixelPos(pastCelY) - circRad / 2, circRad * 2, circRad), 0)
pygame.draw.circle(screen, color, (pixelPos(pastCelX), pixelPos(pastCelY)), circRad / 2)
pygame.draw.rect(screen, color, (pixelPos(pastCelX), pixelPos(pastCelY) - circRad / 2, circRad, circRad))
pygame.draw.rect(screen, color, (pixelPos(pastCelX) - circRad / 2, pixelPos(pastCelY), circRad, circRad))
pygame.draw.rect(screen, color, (pixelPos(curCelX) - circRad / 2, pixelPos(curCelY) - circRad, circRad, circRad * 2), 0)
for i in range(len(lastTurn)):
lastTurn[i] = False
lastTurn[4] = True
colorGrid[curCelX][curCelY] = color
typeGrid[curCelX][curCelY] = 1
return
# draw left to up
elif(curCelX == pastCelX and curCelY < pastCelY and pastPastCelX > pastCelX and lastTurn[5] == False):
pygame.draw.rect(screen, black, (pixelPos(pastCelX) - circRad, pixelPos(pastCelY) - circRad / 2, circRad * 2, circRad), 0)
pygame.draw.circle(screen, color, (pixelPos(pastCelX), pixelPos(pastCelY)), circRad / 2)
pygame.draw.rect(screen, color, (pixelPos(pastCelX), pixelPos(pastCelY) - circRad / 2, circRad, circRad))
pygame.draw.rect(screen, color, (pixelPos(pastCelX) - circRad / 2, pixelPos(pastCelY) - circRad, circRad, circRad))
pygame.draw.rect(screen, color, (pixelPos(curCelX) - circRad / 2, pixelPos(curCelY) - circRad, circRad, circRad * 2), 0)
for i in range(len(lastTurn)):
lastTurn[i] = False
lastTurn[5] = True
colorGrid[curCelX][curCelY] = color
typeGrid[curCelX][curCelY] = 1
return
# draw down to right
elif(curCelX > pastCelX and curCelY == pastCelY and pastPastCelY < pastCelY and lastTurn[6] == False):
pygame.draw.rect(screen, black, (pixelPos(pastCelX) - circRad / 2, pixelPos(pastCelY) - circRad, circRad, circRad * 2), 0)
pygame.draw.circle(screen, color, (pixelPos(pastCelX), pixelPos(pastCelY)), circRad / 2)
pygame.draw.rect(screen, color, (pixelPos(pastCelX), pixelPos(pastCelY) - circRad / 2, circRad, circRad))
pygame.draw.rect(screen, color, (pixelPos(pastCelX) - circRad / 2, pixelPos(pastCelY) - circRad, circRad, circRad))
pygame.draw.rect(screen, color, (pixelPos(curCelX) - circRad, pixelPos(curCelY) - circRad / 2, circRad * 2, circRad), 0)
for i in range(len(lastTurn)):
lastTurn[i] = False
lastTurn[6] = True
colorGrid[curCelX][curCelY] = color
typeGrid[curCelX][curCelY] = 1
return
# draw down to left
elif(curCelX < pastCelX and curCelY == pastCelY and pastPastCelY < pastCelY and lastTurn[7] == False):
pygame.draw.rect(screen, black, (pixelPos(pastCelX) - circRad / 2, pixelPos(pastCelY) - circRad, circRad, circRad * 2), 0)
pygame.draw.circle(screen, color, (pixelPos(pastCelX), pixelPos(pastCelY)), circRad / 2)
pygame.draw.rect(screen, color, (pixelPos(pastCelX) - circRad, pixelPos(pastCelY) - circRad / 2, circRad, circRad))
pygame.draw.rect(screen, color, (pixelPos(pastCelX) - circRad / 2, pixelPos(pastCelY) - circRad, circRad, circRad))
pygame.draw.rect(screen, color, (pixelPos(curCelX) - circRad, pixelPos(curCelY) - circRad / 2, circRad * 2, circRad), 0)
for i in range(len(lastTurn)):
lastTurn[i] = False
lastTurn[7] = True
colorGrid[curCelX][curCelY] = color
typeGrid[curCelX][curCelY] = 1
return
# draw normals
if(typeGrid[curCelX][curCelY] != 2 and curCelX != pastCelX):
pygame.draw.rect(screen, color, (pixelPos(curCelX) - circRad, pixelPos(curCelY) - circRad / 2, circRad * 2, circRad), 0)
colorGrid[curCelX][curCelY] = color
typeGrid[curCelX][curCelY] = 1
for i in range(len(lastTurn)):
lastTurn[i] = False
elif(typeGrid[curCelX][curCelY] != 2 and curCelY != pastCelY):
pygame.draw.rect(screen, color, (pixelPos(curCelX) - circRad / 2, pixelPos(curCelY) - circRad, circRad, circRad * 2), 0)
colorGrid[curCelX][curCelY] = color
typeGrid[curCelX][curCelY] = 1
for i in range(len(lastTurn)):
lastTurn[i] = False
first = True
# Game loop
running = True
while running:
pygame.time.delay(20)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
last = inputs
lastCelX = inputs[0]
lastCelY = inputs[1]
inputs = input(inputs[0], inputs[1], inputs[2], inputs[3], inputs[4], inputs[5])
# if(inputs[0] == lastCelX and inputs[1] == lastCelY):
# inputs = (inputs[0], inputs[1], inputs[2], inputs[3], inputs[4], inputs[5], inputs[6], False)
if(inputs[-1]):
arr = DrawBoard(inputs[0], inputs[1], inputs[2], inputs[3], inputs[4], inputs[5], inputs[6], inputs[7])
if(arr != None):
inputs = (inputs[0], inputs[1], arr[2], arr[3], arr[4], arr[5], inputs[6], inputs[7])
else:
inputs = last
continue
if(keys[pygame.K_q]):
break
drawGrid()
# Update the display
pygame.display.flip()
# Quit Pygame
pygame.quit()