-
Notifications
You must be signed in to change notification settings - Fork 0
/
drawBoard.py
95 lines (80 loc) · 1.78 KB
/
drawBoard.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
from turtle import Turtle, colormode
def startTurtle():
t = Turtle()
t.speed(10)
t.up()
t.setpos(-dim/2,-dim/2)
colormode(255)
return t
def drawQuare(t):
t.fillcolor(34,139,34)#GREEN
t.begin_fill()
t.down()
t.forward(dim)
t.left(90)
t.forward(dim)
t.left(90)
t.forward(dim)
t.left(90)
t.forward(dim)
t.left(90)
t.end_fill()
t.up
def drawFrames(t,lines):
t.down()
for i in range(lines):
t.forward(scale)
x = t.xcor()
y = t.ycor()
t.goto(x,y+dim)
y = t.ycor()
t.goto(x,y-dim)
t.left(90)
for i in range(lines):
t.forward(scale)
x = t.xcor()
y = t.ycor()
t.goto(x-dim,y)
x = t.xcor()
t.goto(x+dim,y)
t.up()
t.setpos(0,0)
t.setpos(-dim/2,-dim/2)
t.right(90)
def drawCircle(t,player):
if(player > 0):
t.fillcolor(0,0,0)
else:
t.fillcolor(255,255,255)
t.down()
t.begin_fill()
t.circle((scale)*0.40)
t.end_fill()
t.up()
def calcMovement(t,x,y):
x = t.xcor() + x*scale + 0.5*scale
y = t.ycor() + y*scale + 0.1*scale
t.setx(x)
t.sety(y)
def drawValues(t,b):
xOri = t.xcor()
yOri = t.ycor()
for x in range(len(b)):
for y in range(len(b)):
if(b[y][x] > 0):
calcMovement(t,x,y)
drawCircle(t,1)
elif (b[y][x] < 0):
calcMovement(t,x,y)
drawCircle(t,-1)
t.goto(xOri,yOri)
t.up()
def drawBoard(b):
global scale
global dim
scale = 100
dim = scale * len(b)
t = startTurtle()
drawQuare(t)
drawFrames(t,len(b))
drawValues(t,b)