-
Notifications
You must be signed in to change notification settings - Fork 0
/
shared_functions.py
62 lines (53 loc) · 1.9 KB
/
shared_functions.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
#Spencer Wittrock 84023369 & Emma Lisowski 26903080
from connectfour import *
def game_board_gui(GameState) ->str:
zero_list = []
for x in range(BOARD_COLUMNS):
print(x+1,end=' ')
print()
for column in GameState.board:
column_list = []
for row in column:
if row == 0:
column_list.append('.')
elif row == 1:
column_list.append('R')
elif row == 2:
column_list.append('Y')
zero_list.append(column_list)
for column in zip(*zero_list):
print(*column)
def command_choice(choice: str, column_choice: int, GameState: 'GameState'):
if choice == 'drop' or choice == 'DROP':
game_board_gui(drop(GameState, column_choice))
return drop(GameState, column_choice)
elif choice == 'pop' or choice == 'POP':
game_board_gui(pop(GameState, column_choice))
return pop(GameState, column_choice)
def run_game():
new_game()
game_board_gui(new_game())
GameState = new_game()
while True:
try:
print('Player', GameState.turn)
choice = input('drop, or pop? ')
if choice == 'drop' or choice == 'pop':
column_choice = int(input('Which column? (1-{})'.format(BOARD_COLUMNS))) - 1
else:
raise "error"
# print(command_choice(choice, column_choice, GameState))
GameState = command_choice(choice, column_choice, GameState)
if winner(GameState) == RED:
print('Red player wins')
break
elif winner(GameState) == YELLOW:
print('Yellow player wins')
break
except:
print('ERROR')
def determine_winner(GameState:GameState):
if winner(GameState) == RED:
return 'Red player wins'
elif winner(GameState) == YELLOW:
return 'Yellow player wins'