-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnect4Project.py
337 lines (313 loc) · 27.1 KB
/
Connect4Project.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
import sys
from termcolor import colored, cprint
'''
How to check for solutions in connect 4:
Note that "up" and "dowm" are going to be in reverse order since we want the bottom to fill first.
The bottom row will be row 0 and count up by one vertically.
Also, remmeber that the board fills from bottom to top.
Possible winning combinations:
Vertical: 21 solutions [Every Column A-F (7)] [3 winning possibilities per column (1-4, 2-5, 3-6)]
Horizontal: 24 solutions [Every Row 1-6] [4 winning possibilities per row (A-D, B-E, C-G, D-F]
Diagonal - Left to Right: 12 solutions - starting from top to bottom [[A-D (1-4, 2-5, 3-6)], [B-E (1-4, 2-5, 3-6)], [C-F (1-4, 2-5, 3-6)], [D-G (1-4, 2-5, 3-6)]]
Diagonal - Right to Left: 12 solutions - starting from top to bottom [[G-D (1-4, 2-5, 3-6)], [F-C (1-4, 2-5, 3-6)], [E-B (1-4, 2-5, 3-6)], [D-A (1-4, 2-5, 3-6)]]
'''
player = 1
colHeight = "colheight"
print_yellow_dot = lambda x: cprint(x, 'yellow',end="")
print_red_dot = lambda x: cprint(x, 'red',end="")
gameBoard = {
"col0":{"0":"","1":"","2":"","3":"","4":"","5":"","colheight":0},
"col1":{"0":"","1":"","2":"","3":"","4":"","5":"","colheight":0},
"col2":{"0":"","1":"","2":"","3":"","4":"","5":"","colheight":0},
"col3":{"0":"","1":"","2":"","3":"","4":"","5":"","colheight":0},
"col4":{"0":"","1":"","2":"","3":"","4":"","5":"","colheight":0},
"col5":{"0":"","1":"","2":"","3":"","4":"","5":"","colheight":0},
"col6":{"0":"","1":"","2":"","3":"","4":"","5":"","colheight":0},
}
rowInput = 0
# this function draws grid
# multiplying rows and columns by 2 to account for lines.
# number of rows and columns will be actual boxes to place red and yellow circles
# Note - red and yellow dots don't render well on half a screen for some reason? Used cprint
def func1(row,column):
print("----------------------")
row = row*2
column = (column*2)
for r in range(0,row+1):
if r%2 == 0:
for c in range(0,column+1):
if c%2 == 1:
if c < column - 1:
print(" |", end="")
elif c == column - 1:
if c < 8:
square = gameBoard["col" + str(int((c)/2))][str(int((r)/2))]
if square == "":
print(" |")
else:
print(gameBoard["col" + str(int((c)/2))][str(int((r)/2))])
else:
if c/2 <= 6:
square = gameBoard["col" + str(int((c)/2))][str(int((r)/2))]
if c == 0:
print("|", end="")
if square == "":
print(" ", end = "")
else:
if square == "X":
print_yellow_dot(u'\u2B24')
elif square == "O":
print_red_dot(u'\u2B24')
else:
if r == row-1:
break
else:
print("\n")
print("-"*(column+6))
print("\n----------------------")
def checkForWinner(col):
#Vertical Checks - We only need to check "down"
if gameBoard["col" + str(col)][colHeight] > 3:
if gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col)][str(rowInput-1)] == "X" and gameBoard["col" + str(col)][str(rowInput-2)] == "X" and gameBoard["col" + str(col)][str(rowInput-3)]== "X":
print ("Player 1 is the winner!")
exit()
elif gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col)][str(rowInput-1)] == "O" and gameBoard["col" + str(col)][str(rowInput-2)] == "O" and gameBoard["col" + str(col)][str(rowInput-3)]== "O":
print("Player 2 is the winner!")
exit()
# Horizontal Checks - Checks left and right based on each column
for col in range (7):
# checks for player 1
if gameBoard["col" + str(0)][str(rowInput)] == "X" and gameBoard["col" + str(1)][str(rowInput)] == "X" and gameBoard["col" + str(2)][str(rowInput)] == "X" and gameBoard["col" + str(3)][str(rowInput)] == "X":
print("Player 1 is the winner!")
func1(6,8)
exit()
elif gameBoard["col" + str(1)][str(rowInput)] == "X" and gameBoard["col" + str(2)][str(rowInput)] == "X" and gameBoard["col" + str(3)][str(rowInput)] == "X" and gameBoard["col" + str(4)][str(rowInput)] == "X":
print("Player 1 is the winner!")
func1(6,8)
exit()
elif gameBoard["col" + str(2)][str(rowInput)] == "X" and gameBoard["col" + str(3)][str(rowInput)] == "X" and gameBoard["col" + str(4)][str(rowInput)] == "X" and gameBoard["col" + str(5)][str(rowInput)] == "X":
print("Player 1 is the winner!")
func1(6,8)
exit()
elif gameBoard["col" + str(3)][str(rowInput)] == "X" and gameBoard["col" + str(4)][str(rowInput)] == "X" and gameBoard["col" + str(5)][str(rowInput)] == "X" and gameBoard["col" + str(6)][str(rowInput)] == "X":
print("Player 1 is the winner!")
func1(6,8)
exit()
#player 2
if gameBoard["col" + str(0)][str(rowInput)] == "O" and gameBoard["col" + str(1)][str(rowInput)] == "O" and gameBoard["col" + str(2)][str(rowInput)] == "O" and gameBoard["col" + str(3)][str(rowInput)] == "O":
print("Player 2 is the winner!")
func1(6,8)
exit()
elif gameBoard["col" + str(1)][str(rowInput)] == "O" and gameBoard["col" + str(2)][str(rowInput)] == "O" and gameBoard["col" + str(3)][str(rowInput)] == "O" and gameBoard["col" + str(4)][str(rowInput)] == "O":
print("Player 2 is the winner!")
func1(6,8)
exit()
elif gameBoard["col" + str(2)][str(rowInput)] == "O" and gameBoard["col" + str(3)][str(rowInput)] == "O" and gameBoard["col" + str(4)][str(rowInput)] == "O" and gameBoard["col" + str(5)][str(rowInput)] == "O":
print("Player 2 is the winner!")
func1(6,8)
exit()
elif gameBoard["col" + str(3)][str(rowInput)] == "O" and gameBoard["col" + str(4)][str(rowInput)] == "O" and gameBoard["col" + str(5)][str(rowInput)] == "O" and gameBoard["col" + str(6)][str(rowInput)] == "O":
print("Player 2 is the winner!")
func1(6,8)
exit()
# Diagional checks
# 4 quadrants when checking diagionally - Left to right (positive slope) = --,++ || Right to left (negative slope) = -+, +-
try: ## "Positive" slope Bottom left to top right
for col in range (7):
if col == 0:
if gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col+1)][str(rowInput+1)] == "X" and gameBoard["col" + str(col+2)][str(rowInput+2)] == "X" and gameBoard["col" + str(col+3)][str(rowInput+3)] == "X":
print("Player 1 is the winner!")
func1(6,8)
exit()
if gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col+1)][str(rowInput+1)] == "O" and gameBoard["col" + str(col+2)][str(rowInput+2)] == "O" and gameBoard["col" + str(col+3)][str(rowInput+3)] == "O":
print("Player 2 is the winner!")
func1(6,8)
exit()
if col == 1:
if (gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col+1)][str(rowInput+1)] == "X" and gameBoard["col" + str(col+2)][str(rowInput+2)] == "X" and gameBoard["col" + str(col+3)][str(rowInput+3)] == "X" or
gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col-1)][str(rowInput-1)] == "X" and gameBoard["col" + str(col+1)][str(rowInput+1)] == "X" and gameBoard["col" + str(col+2)][str(rowInput+2)] == "X"):
print("Player 1 is the winner!")
func1(6,8)
exit()
if (gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col+1)][str(rowInput+1)] == "O" and gameBoard["col" + str(col+2)][str(rowInput+2)] == "O" and gameBoard["col" + str(col+3)][str(rowInput+3)] == "O" or
gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col-1)][str(rowInput-1)] == "O" and gameBoard["col" + str(col+1)][str(rowInput+1)] == "O" and gameBoard["col" + str(col+2)][str(rowInput+2)] == "O"):
print("Player 2 is the winner!")
func1(6,8)
exit()
if col == 2:
if (gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col+1)][str(rowInput+1)] == "X" and gameBoard["col" + str(col+2)][str(rowInput+2)] == "X" and gameBoard["col" + str(col+3)][str(rowInput+3)] == "X" or
gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col-1)][str(rowInput-1)] == "X" and gameBoard["col" + str(col+1)][str(rowInput+1)] == "X" and gameBoard["col" + str(col+2)][str(rowInput+2)] == "X" or
gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col-2)][str(rowInput-2)] == "X" and gameBoard["col" + str(col-1)][str(rowInput-1)] == "X" and gameBoard["col" + str(col+1)][str(rowInput+1)] == "X"):
print("Player 1 is the winner!")
func1(6,8)
exit()
if (gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col+1)][str(rowInput+1)] == "O" and gameBoard["col" + str(col+2)][str(rowInput+2)] == "O" and gameBoard["col" + str(col+3)][str(rowInput+3)] == "O" or
gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col-1)][str(rowInput-1)] == "O" and gameBoard["col" + str(col+1)][str(rowInput+1)] == "O" and gameBoard["col" + str(col+2)][str(rowInput+2)] == "O" or
gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col-2)][str(rowInput-2)] == "O" and gameBoard["col" + str(col-1)][str(rowInput-1)] == "O" and gameBoard["col" + str(col+1)][str(rowInput+1)] == "O"):
print("Player 2 is the winner!")
func1(6,8)
exit()
if col == 3:
if (gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col+1)][str(rowInput+1)] == "X" and gameBoard["col" + str(col+2)][str(rowInput+2)] == "X" and gameBoard["col" + str(col+3)][str(rowInput+3)] == "X" or
gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col-1)][str(rowInput-1)] == "X" and gameBoard["col" + str(col+1)][str(rowInput+1)] == "X" and gameBoard["col" + str(col+2)][str(rowInput+2)] == "X" or
gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col-2)][str(rowInput-2)] == "X" and gameBoard["col" + str(col-1)][str(rowInput-1)] == "X" and gameBoard["col" + str(col+1)][str(rowInput+1)] == "X" or
gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col-3)][str(rowInput-3)] == "X" and gameBoard["col" + str(col-2)][str(rowInput-2)] == "X" and gameBoard["col" + str(col-1)][str(rowInput-1)] == "X"):
print("Player 1 is the winner!")
func1(6,8)
exit()
if (gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col+1)][str(rowInput+1)] == "O" and gameBoard["col" + str(col+2)][str(rowInput+2)] == "O" and gameBoard["col" + str(col+3)][str(rowInput+3)] == "O" or
gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col-1)][str(rowInput-1)] == "O" and gameBoard["col" + str(col+1)][str(rowInput+1)] == "O" and gameBoard["col" + str(col+2)][str(rowInput+2)] == "O" or
gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col-2)][str(rowInput-2)] == "O" and gameBoard["col" + str(col-1)][str(rowInput-1)] == "O" and gameBoard["col" + str(col+1)][str(rowInput+1)] == "O" or
gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col-3)][str(rowInput-3)] == "O" and gameBoard["col" + str(col-2)][str(rowInput-2)] == "O" and gameBoard["col" + str(col-1)][str(rowInput-1)] == "O"):
print("Player 2 is the winner!")
func1(6,8)
exit()
if col == 4:
if (gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col-1)][str(rowInput-1)] == "X" and gameBoard["col" + str(col-2)][str(rowInput-2)] == "X" and gameBoard["col" + str(col-3)][str(rowInput-3)] == "X" or
gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col+1)][str(rowInput+1)] == "X" and gameBoard["col" + str(col-1)][str(rowInput-1)] == "X" and gameBoard["col" + str(col-2)][str(rowInput-2)] == "X" or
gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col+2)][str(rowInput+2)] == "X" and gameBoard["col" + str(col+1)][str(rowInput+1)] == "X" and gameBoard["col" + str(col-1)][str(rowInput-1)] == "X"):
print("Player 1 is the winner!")
func1(6,8)
exit()
if (gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col-1)][str(rowInput-1)] == "O" and gameBoard["col" + str(col-2)][str(rowInput-2)] == "O" and gameBoard["col" + str(col-3)][str(rowInput-3)] == "O" or
gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col+1)][str(rowInput+1)] == "O" and gameBoard["col" + str(col-1)][str(rowInput-1)] == "O" and gameBoard["col" + str(col-2)][str(rowInput-2)] == "O" or
gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col+2)][str(rowInput+2)] == "O" and gameBoard["col" + str(col+1)][str(rowInput+1)] == "O" and gameBoard["col" + str(col-1)][str(rowInput-1)] == "O"):
print("Player 2 is the winner!")
func1(6,8)
exit()
if col == 5:
if (gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col-1)][str(rowInput-1)] == "X" and gameBoard["col" + str(col-2)][str(rowInput-2)] == "X" and gameBoard["col" + str(col-3)][str(rowInput-3)] == "X" or
gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col+1)][str(rowInput+1)] == "X" and gameBoard["col" + str(col-1)][str(rowInput-1)] == "X" and gameBoard["col" + str(col-2)][str(rowInput-2)] == "X"):
print("Player 1 is the winner!")
func1(6,8)
exit()
if (gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col-1)][str(rowInput-1)] == "O" and gameBoard["col" + str(col-2)][str(rowInput-2)] == "O" and gameBoard["col" + str(col-3)][str(rowInput-3)] == "O" or
gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col+1)][str(rowInput+1)] == "O" and gameBoard["col" + str(col-1)][str(rowInput-1)] == "O" and gameBoard["col" + str(col-2)][str(rowInput-2)] == "O"):
print("Player 2 is the winner!")
func1(6,8)
exit()
if col == 6:
if gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col-1)][str(rowInput-1)] == "X" and gameBoard["col" + str(col-2)][str(rowInput-2)] == "X" and gameBoard["col" + str(col-3)][str(rowInput-3)] == "X":
print("Player 1 is the winner!")
func1(6,8)
exit()
if gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col-1)][str(rowInput-1)] == "O" and gameBoard["col" + str(col-2)][str(rowInput-2)] == "O" and gameBoard["col" + str(col-3)][str(rowInput-3)] == "O":
print("Player 2 is the winner!")
func1(6,8)
exit()
except KeyError:
print("\n")
try: ## "Negative" slope Bottom right to top left
for col in range (7):
if col == 0:
if gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col+1)][str(rowInput-1)] == "X" and gameBoard["col" + str(col+2)][str(rowInput-2)] == "X" and gameBoard["col" + str(col+3)][str(rowInput-3)] == "X":
print("Player 1 is the winner!")
func1(6,8)
exit()
if gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col+1)][str(rowInput-1)] == "O" and gameBoard["col" + str(col+2)][str(rowInput-2)] == "O" and gameBoard["col" + str(col+3)][str(rowInput-3)] == "O":
print("Player 2 is the winner!")
func1(6,8)
exit()
if col == 1:
if (gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col+1)][str(rowInput-1)] == "X" and gameBoard["col" + str(col+2)][str(rowInput-2)] == "X" and gameBoard["col" + str(col+3)][str(rowInput-3)] == "X" or
gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col-1)][str(rowInput+1)] == "X" and gameBoard["col" + str(col+1)][str(rowInput-1)] == "X" and gameBoard["col" + str(col+2)][str(rowInput-2)] == "X"):
print("Player 1 is the winner!")
func1(6,8)
exit()
if (gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col+1)][str(rowInput-1)] == "O" and gameBoard["col" + str(col+2)][str(rowInput-2)] == "O" and gameBoard["col" + str(col+3)][str(rowInput-3)] == "O" or
gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col-1)][str(rowInput+1)] == "O" and gameBoard["col" + str(col+1)][str(rowInput-1)] == "O" and gameBoard["col" + str(col+2)][str(rowInput-2)] == "O"):
print("Player 2 is the winner!")
func1(6,8)
exit()
if col == 2:
if (gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col+1)][str(rowInput-1)] == "X" and gameBoard["col" + str(col+2)][str(rowInput-2)] == "X" and gameBoard["col" + str(col+3)][str(rowInput-3)] == "X" or
gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col-1)][str(rowInput+1)] == "X" and gameBoard["col" + str(col+1)][str(rowInput-1)] == "X" and gameBoard["col" + str(col+2)][str(rowInput-2)] == "X" or
gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col-2)][str(rowInput+2)] == "X" and gameBoard["col" + str(col-1)][str(rowInput+1)] == "X" and gameBoard["col" + str(col+1)][str(rowInput-1)] == "X"):
print("Player 1 is the winner!")
func1(6,8)
exit()
if (gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col+1)][str(rowInput-1)] == "O" and gameBoard["col" + str(col+2)][str(rowInput-2)] == "O" and gameBoard["col" + str(col+3)][str(rowInput-3)] == "O" or
gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col-1)][str(rowInput+1)] == "O" and gameBoard["col" + str(col+1)][str(rowInput-1)] == "O" and gameBoard["col" + str(col+2)][str(rowInput-2)] == "O" or
gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col-2)][str(rowInput+2)] == "O" and gameBoard["col" + str(col-1)][str(rowInput+1)] == "O" and gameBoard["col" + str(col+1)][str(rowInput-1)] == "O"):
print("Player 2 is the winner!")
func1(6,8)
exit()
if col == 3:
if (gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col+1)][str(rowInput-1)] == "X" and gameBoard["col" + str(col+2)][str(rowInput-2)] == "X" and gameBoard["col" + str(col+3)][str(rowInput-3)] == "X" or
gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col-1)][str(rowInput+1)] == "X" and gameBoard["col" + str(col+1)][str(rowInput-1)] == "X" and gameBoard["col" + str(col+2)][str(rowInput-2)] == "X" or
gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col-2)][str(rowInput+2)] == "X" and gameBoard["col" + str(col-1)][str(rowInput+1)] == "X" and gameBoard["col" + str(col+1)][str(rowInput-1)] == "X" or
gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col-3)][str(rowInput+3)] == "X" and gameBoard["col" + str(col-2)][str(rowInput+2)] == "X" and gameBoard["col" + str(col-1)][str(rowInput+1)] == "X"):
print("Player 1 is the winner!")
func1(6,8)
exit()
if (gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col+1)][str(rowInput-1)] == "O" and gameBoard["col" + str(col+2)][str(rowInput-2)] == "O" and gameBoard["col" + str(col+3)][str(rowInput-3)] == "O" or
gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col-1)][str(rowInput+1)] == "O" and gameBoard["col" + str(col+1)][str(rowInput-1)] == "O" and gameBoard["col" + str(col+2)][str(rowInput-2)] == "O" or
gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col-2)][str(rowInput+2)] == "O" and gameBoard["col" + str(col-1)][str(rowInput+1)] == "O" and gameBoard["col" + str(col+1)][str(rowInput-1)] == "O" or
gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col-3)][str(rowInput+3)] == "O" and gameBoard["col" + str(col-2)][str(rowInput+2)] == "O" and gameBoard["col" + str(col-1)][str(rowInput+1)] == "O"):
print("Player 2 is the winner!")
func1(6,8)
exit()
if col == 4:
if (gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col-1)][str(rowInput+1)] == "X" and gameBoard["col" + str(col-2)][str(rowInput+2)] == "X" and gameBoard["col" + str(col-3)][str(rowInput+3)] == "X" or
gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col+1)][str(rowInput-1)] == "X" and gameBoard["col" + str(col-1)][str(rowInput+1)] == "X" and gameBoard["col" + str(col-2)][str(rowInput+2)] == "X" or
gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col+2)][str(rowInput-2)] == "X" and gameBoard["col" + str(col+1)][str(rowInput-1)] == "X" and gameBoard["col" + str(col-1)][str(rowInput+1)] == "X"):
print("Player 1 is the winner!")
func1(6,8)
exit()
if (gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col-1)][str(rowInput+1)] == "O" and gameBoard["col" + str(col-2)][str(rowInput+2)] == "O" and gameBoard["col" + str(col-3)][str(rowInput+3)] == "O" or
gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col+1)][str(rowInput-1)] == "O" and gameBoard["col" + str(col-1)][str(rowInput+1)] == "O" and gameBoard["col" + str(col-2)][str(rowInput+2)] == "O" or
gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col+2)][str(rowInput-2)] == "O" and gameBoard["col" + str(col+1)][str(rowInput-1)] == "O" and gameBoard["col" + str(col-1)][str(rowInput+1)] == "O"):
print("Player 2 is the winner!")
func1(6,8)
exit()
if col == 5:
if (gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col-1)][str(rowInput+1)] == "X" and gameBoard["col" + str(col-2)][str(rowInput+2)] == "X" and gameBoard["col" + str(col-3)][str(rowInput+3)] == "X" or
gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col+1)][str(rowInput-1)] == "X" and gameBoard["col" + str(col-1)][str(rowInput+1)] == "X" and gameBoard["col" + str(col-2)][str(rowInput+2)] == "X"):
print("Player 1 is the winner!")
func1(6,8)
exit()
if (gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col-1)][str(rowInput+1)] == "O" and gameBoard["col" + str(col-2)][str(rowInput+2)] == "O" and gameBoard["col" + str(col-3)][str(rowInput+3)] == "O" or
gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col+1)][str(rowInput-1)] == "O" and gameBoard["col" + str(col-1)][str(rowInput+1)] == "O" and gameBoard["col" + str(col-2)][str(rowInput+2)] == "O"):
print("Player 2 is the winner!")
func1(6,8)
exit()
if col == 6:
if gameBoard["col" + str(col)][str(rowInput)] == "X" and gameBoard["col" + str(col-1)][str(rowInput+1)] == "X" and gameBoard["col" + str(col-2)][str(rowInput+2)] == "X" and gameBoard["col" + str(col-3)][str(rowInput+3)] == "X":
print("Player 1 is the winner!")
func1(6,8)
exit()
if gameBoard["col" + str(col)][str(rowInput)] == "O" and gameBoard["col" + str(col-1)][str(rowInput+1)] == "O" and gameBoard["col" + str(col-2)][str(rowInput+2)] == "O" and gameBoard["col" + str(col-3)][str(rowInput+3)] == "O":
print("Player 2 is the winner!")
func1(6,8)
exit()
except KeyError:
print("\n")
# This loop will initiate the game and continue to alternate turns between players until someone wins.
while(True):
# columns start on row 0 but player may not realize that so making them 1-7 for user instead of 0-6.
print("\n\n")
print("It is player", str(player) +"'s turn.")
columnSelection = int(input("Which column do you want to place your chip? Choose 1, 2, 3, 4, 5, 6 or 7. "))-1
# Since the connect four board is filled from bottom to top, we are going to iterate on 'colheight' in each column, based on how many "chips" in col.
# This will tell us what row (0-5) to put the next move
rowInput = int(gameBoard["col" + str(columnSelection)][colHeight])
if rowInput > 5:
print("That column is full, please select another cloumn.")
elif columnSelection >= 7 or columnSelection < 0:
print("Please select an appropriate column number.")
else:
if player == 1:
gameBoard["col" + str(columnSelection)][str(rowInput)] = 'X'
gameBoard["col" + str(columnSelection)][colHeight] += 1
checkForWinner(columnSelection)
rowInput +=1
player = 2
#print(gameBoard)
elif player == 2:
gameBoard["col" + str(columnSelection)][str(rowInput)] = 'O'
gameBoard["col" + str(columnSelection)][colHeight] += 1
checkForWinner(columnSelection)
rowInput += 1
player = 1
#print(gameBoard)
func1(6,8)