-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.py
More file actions
94 lines (66 loc) · 2.46 KB
/
Node.py
File metadata and controls
94 lines (66 loc) · 2.46 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
from Constants import *
class Node:
def __init__(self, x, y):
self.x = x
self.y = y
self.piece = None
self.searched = False
self.ko = False
def showEllipse(self, xPos, yPos, sc=1):
ellipse(xPos + CELLDIM // 2, yPos + CELLDIM // 2, (CELLDIM-1)*sc, (CELLDIM-1)*sc)
def isEmpty(self):
return self.piece == None
def isBlack(self):
return self.piece == "b"
def isWhite(self):
return self.piece == "w"
def setBlack(self):
self.piece = "b"
def setWhite(self):
self.piece = "w"
def setEmpty(self):
self.piece = None
def getPos(self):
return (MARGIN + self.x * CELLDIM, MARGIN + self.y * CELLDIM)
def show(self):
noStroke()
fill(*CELLCOLOR)
xPos, yPos = self.getPos()
rect(xPos, yPos, CELLDIM, CELLDIM)
stroke(0)
if self.ko:
self.showKo()
elif self.piece == "b":
fill(*BLACKCOLOR)
self.showEllipse(xPos, yPos)
elif self.piece == "w":
fill(*WHITECOLOR)
self.showEllipse(xPos, yPos)
else:
stroke(*LINECOLOR)
if self.y == 0:
line(xPos+CELLDIM//2,yPos+CELLDIM//2,xPos+CELLDIM//2,yPos+CELLDIM)
elif self.y == SIZE - 1:
line(xPos+CELLDIM//2,yPos,xPos+CELLDIM//2,yPos+CELLDIM//2)
else:
line(xPos + CELLDIM // 2, yPos, xPos + CELLDIM // 2, yPos + CELLDIM)
if self.x == 0:
line(xPos+CELLDIM//2,yPos+CELLDIM//2,xPos+CELLDIM,yPos+CELLDIM//2)
elif self.x == SIZE - 1:
line(xPos,yPos+CELLDIM//2,xPos+CELLDIM//2,yPos+CELLDIM//2)
else:
line(xPos, yPos + CELLDIM // 2, xPos + CELLDIM, yPos + CELLDIM // 2)
stroke(0)
def showTransparent(self, side):
if self.isEmpty():
if side == "b":
fill(*TRANSPARENTBLACK)
elif side == "w":
fill(*TRANSPARENTWHITE)
xPos, yPos = self.getPos()
self.showEllipse(xPos, yPos)
def showKo(self):
# if self.isEmpty():
fill(0)
xPos, yPos = self.getPos()
self.showEllipse(xPos, yPos, .2)