Repository navigation
Expand file tree
/
Copy pathConnect_Four.py
More file actions
75 lines (57 loc) · 1.62 KB
/
Copy pathConnect_Four.py
File metadata and controls
75 lines (57 loc) · 1.62 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
#==================================================================
# Global Variables
#==================================================================
num_rows = 6
column_0 = []
column_1 = []
column_2 = []
column_3 = []
column_4 = []
column_5 = []
column_6 = []
board = [column_0, column_1, column_2, column_3, column_4, column_5, column_6]
#==================================================================
# Functions
#==================================================================
def display_row(board, row):
if not 0 <= row <= 5:
return
for column in board:
try:
# print(f"row {row}: '{column[row]}'", end = ' ')
print(f"'{column[row]}'", end = ' ')
except:
# print(f"row {row}: '_'", end = ' ')
print(f"'_'", end = ' ')
print()
def show_board(board):
global num_rows
for row in range(num_rows - 1, -1, -1):
display_row(board, row)
def drop_coin(board, column, player):
global num_rows
if player:
coin = 'Y'
else:
coin = 'R'
if len(board[column]) < num_rows:
board[column].append(coin)
return True
else:
return False
#==================================================================
# Main Program
#==================================================================
# show_board(board)
# board[3].append('X')
# board[3].append('X')
# board[3].append('X')
drop_coin(board, 3, 0)
drop_coin(board, 3, 1)
drop_coin(board, 3, 0)
drop_coin(board, 3, 0)
drop_coin(board, 3, 1)
print(drop_coin(board, 3, 0))
print(drop_coin(board, 3, 1))
show_board(board)
print(board)