-
Notifications
You must be signed in to change notification settings - Fork 0
/
WinCalculator.py
199 lines (196 loc) · 10.9 KB
/
WinCalculator.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
######################
#Ultimate Tic-Tac-Toe#
#####Samar Dhoat######
###December 19,2019###
######################
#This define function defines which team wins
def SetWin(Grid,Team,TotalGrid):
for x in range(9):
for y in range(9):
Grid[x][y] = Team
for x in TotalGrid:
for y in x:
y = Team
#This define function colors in the boxes if and when a team wins a big box
def winSetter(OC,Team,Grid,TotalGrid):
TotalGrid[OC[0]//3][OC[1]//3] = Team
for x in range((OC[0]//3) * 3,(OC[0]//3) *3 + 3):
for y in range((OC[1]//3) * 3,(OC[1]//3) *3 + 3):
Grid[x][y] = Team
for x in range(0,3):
if TotalGrid[x][0] == Team and TotalGrid[x][1] == Team and TotalGrid[x][2] == Team:
if Team == 1:
SetWin(Grid,1,TotalGrid)
import image
X = image.Image("xwins.gif")
X_w = X.getWidth()
X_h = X.getHeight()
wn = image.ImageWin(X_w * 2, X_h * 2)
X_new = image.EmptyImage(X_w * 2, X_h * 2)
for r in range(X_h):
for c in range(X_w):
pixel = X.getPixel(c , r)
X_new.setPixel(2*c, 2*r , pixel)
X_new.setPixel(2*c +1, 2*r , pixel)
X_new.setPixel(2*c, 2*r+1 , pixel)
X_new.setPixel(2*c +1, 2*r+1 , pixel)
X_new.draw(wn)
wn.exitonclick()
else:
SetWin(Grid,2,TotalGrid)
import image
O = image.Image("owins.gif")
O_w = O.getWidth()
O_h = O.getHeight()
wn = image.ImageWin(O_w * 2, O_h * 2)
O_new = image.EmptyImage(O_w * 2, O_h * 2)
for r in range(O_h):
for c in range(O_w):
pixel = O.getPixel(c , r)
O_new.setPixel(2*c, 2*r , pixel)
O_new.setPixel(2*c +1, 2*r , pixel)
O_new.setPixel(2*c, 2*r+1 , pixel)
O_new.setPixel(2*c +1, 2*r+1 , pixel)
O_new.draw(wn)
wn.exitonclick()
for y in range(0,3):
if TotalGrid[0][y] == Team and TotalGrid[1][y] == Team and TotalGrid[2][y] == Team:
if Team == 1:
SetWin(Grid,1,TotalGrid)
import image
X = image.Image("xwins.gif")
X_w = X.getWidth()
X_h = X.getHeight()
wn = image.ImageWin(X_w * 2, X_h * 2)
X_new = image.EmptyImage(X_w * 2, X_h * 2)
for r in range(X_h):
for c in range(X_w):
pixel = X.getPixel(c , r)
X_new.setPixel(2*c, 2*r , pixel)
X_new.setPixel(2*c +1, 2*r , pixel)
X_new.setPixel(2*c, 2*r+1 , pixel)
X_new.setPixel(2*c +1, 2*r+1 , pixel)
X_new.draw(wn)
wn.exitonclick()
else:
SetWin(Grid,2,TotalGrid)
import image
O = image.Image("owins.gif")
O_w = O.getWidth()
O_h = O.getHeight()
wn = image.ImageWin(O_w * 2, O_h * 2)
O_new = image.EmptyImage(O_w * 2, O_h * 2)
for r in range(O_h):
for c in range(O_w):
pixel = O.getPixel(c , r)
O_new.setPixel(2*c, 2*r , pixel)
O_new.setPixel(2*c +1, 2*r , pixel)
O_new.setPixel(2*c, 2*r+1 , pixel)
O_new.setPixel(2*c +1, 2*r+1 , pixel)
O_new.draw(wn)
wn.exitonclick()
if Team == 1:
SetWin(Grid,1,TotalGrid)
import image
X = image.Image("xwins.gif")
X_w = X.getWidth()
X_h = X.getHeight()
wn = image.ImageWin(X_w * 2, X_h * 2)
X_new = image.EmptyImage(X_w * 2, X_h * 2)
for r in range(X_h):
for c in range(X_w):
pixel = X.getPixel(c , r)
X_new.setPixel(2*c, 2*r , pixel)
X_new.setPixel(2*c +1, 2*r , pixel)
X_new.setPixel(2*c, 2*r+1 , pixel)
X_new.setPixel(2*c +1, 2*r+1 , pixel)
X_new.draw(wn)
wn.exitonclick()
else:
SetWin(Grid,2,TotalGrid)
import image
O = image.Image("owins.gif")
O_w = O.getWidth()
O_h = O.getHeight()
wn = image.ImageWin(O_w * 2, O_h * 2)
O_new = image.EmptyImage(O_w * 2, O_h * 2)
for r in range(O_h):
for c in range(O_w):
pixel = O.getPixel(c , r)
O_new.setPixel(2*c, 2*r , pixel)
O_new.setPixel(2*c +1, 2*r , pixel)
O_new.setPixel(2*c, 2*r+1 , pixel)
O_new.setPixel(2*c +1, 2*r+1 , pixel)
O_new.draw(wn)
wn.exitonclick()
#This define function describes all the ways to win, except for diagonal of the 3x3 big one
def winCalc(OuterCords,Grid,TotalGrid):
OC = OuterCords
IC = (OC[0]%3,OC[1]%3)
thisTileTeam = Grid[OC[0]][OC[1]]
Team = thisTileTeam
if IC == (0,0):
if Grid[OC[0]+1][OC[1]] == thisTileTeam and Grid[OC[0]+2][OC[1]] == thisTileTeam:
winSetter(OC,thisTileTeam,Grid,TotalGrid)
elif Grid[OC[0]][OC[1]+1] == thisTileTeam and Grid[OC[0]][OC[1]+2] == thisTileTeam:
winSetter(OC,thisTileTeam,Grid,TotalGrid)
elif Grid[OC[0]+1][OC[1]+1] == thisTileTeam and Grid[OC[0]+2][OC[1]+2] == thisTileTeam:
winSetter(OC,thisTileTeam,Grid,TotalGrid)
elif IC == (1,0):
if Grid[OC[0]+1][OC[1]] == thisTileTeam and Grid[OC[0]-1][OC[1]] == thisTileTeam:
winSetter(OC,thisTileTeam,Grid,TotalGrid)
elif Grid[OC[0]][OC[1]+1] == thisTileTeam and Grid[OC[0]][OC[1]+2] == thisTileTeam:
winSetter(OC,thisTileTeam,Grid,TotalGrid)
elif IC == (2,0):
if Grid[OC[0]-1][OC[1]] == thisTileTeam and Grid[OC[0]-2][OC[1]] == thisTileTeam:
winSetter(OC,thisTileTeam,Grid,TotalGrid)
elif Grid[OC[0]][OC[1]+1] == thisTileTeam and Grid[OC[0]][OC[1]+2] == thisTileTeam:
winSetter(OC,thisTileTeam,Grid,TotalGrid)
elif Grid[OC[0]-1][OC[1]+1] == thisTileTeam and Grid[OC[0]-2][OC[1]+2] == thisTileTeam:
winSetter(OC,thisTileTeam,Grid,TotalGrid)
elif IC == (0,1):
if Grid[OC[0]][OC[1]+1] == thisTileTeam and Grid[OC[0]][OC[1]-1] == thisTileTeam:
winSetter(OC,thisTileTeam,Grid,TotalGrid)
elif Grid[OC[0]+1][OC[1]] == thisTileTeam and Grid[OC[0]+2][OC[1]] == thisTileTeam:
winSetter(OC,thisTileTeam,Grid,TotalGrid)
elif IC == (1,1):
if Grid[OC[0]][OC[1]+1] == thisTileTeam and Grid[OC[0]][OC[1]-1] == thisTileTeam:
winSetter(OC,thisTileTeam,Grid,TotalGrid)
elif Grid[OC[0]+1][OC[1]] == thisTileTeam and Grid[OC[0]-1][OC[1]] == thisTileTeam:
winSetter(OC,thisTileTeam,Grid,TotalGrid)
elif Grid[OC[0]-1][OC[1]-1] == thisTileTeam and Grid[OC[0]+1][OC[1]+1] == thisTileTeam:
winSetter(OC,thisTileTeam,Grid,TotalGrid)
elif Grid[OC[0]-1][OC[1]+1] == thisTileTeam and Grid[OC[0]+1][OC[1]-1] == thisTileTeam:
winSetter(OC,thisTileTeam,Grid,TotalGrid)
elif IC == (2,1):
if Grid[OC[0]][OC[1]+1] == thisTileTeam and Grid[OC[0]][OC[1]-1] == thisTileTeam:
winSetter(OC,thisTileTeam,Grid,TotalGrid)
elif Grid[OC[0]-1][OC[1]] == thisTileTeam and Grid[OC[0]-2][OC[1]] == thisTileTeam:
winSetter(OC,thisTileTeam,Grid,TotalGrid)
elif IC == (0,2):
if Grid[OC[0]+1][OC[1]] == thisTileTeam and Grid[OC[0]+2][OC[1]] == thisTileTeam:
winSetter(OC,thisTileTeam,Grid,TotalGrid)
elif Grid[OC[0]][OC[1]-1] == thisTileTeam and Grid[OC[0]][OC[1]-2] == thisTileTeam:
winSetter(OC,thisTileTeam,Grid,TotalGrid)
elif Grid[OC[0]+1][OC[1]-1] == thisTileTeam and Grid[OC[0]+2][OC[1]-2] == thisTileTeam:
winSetter(OC,thisTileTeam,Grid,TotalGrid)
elif IC == (1,2):
if Grid[OC[0]+1][OC[1]] == thisTileTeam and Grid[OC[0]-1][OC[1]] == thisTileTeam:
winSetter(OC,thisTileTeam,Grid,TotalGrid)
elif Grid[OC[0]][OC[1]-1] == thisTileTeam and Grid[OC[0]][OC[1]-2] == thisTileTeam:
winSetter(OC,thisTileTeam,Grid,TotalGrid)
elif IC == (2,2):
if (Grid[OC[0]][OC[1]-1] == thisTileTeam and Grid[OC[0]][OC[1]-2] == thisTileTeam):
winSetter(OC,thisTileTeam,Grid,TotalGrid)
elif (Grid[OC[0]-1][OC[1]] == thisTileTeam and Grid[OC[0]-2][OC[1]] == thisTileTeam):
winSetter(OC,thisTileTeam,Grid,TotalGrid)
elif Grid[OC[0]-1][OC[1]-1] == thisTileTeam and Grid[OC[0]-2][OC[1]-2] == thisTileTeam:
winSetter(OC,thisTileTeam,Grid,TotalGrid)
amtused = 0
for x in range(OC[0]-IC[0],OC[0]-IC[0]+3):
for y in range(OC[1]-IC[1],OC[1]-IC[1]+3):
if Grid[x][y] != 0:
amtused = amtused + 1
if amtused == 9:
if TotalGrid[OC[0]//3][OC[1]//3] == 0:
TotalGrid[OC[0]//3][OC[1]//3] = -1