-
Notifications
You must be signed in to change notification settings - Fork 0
/
console_only.py
67 lines (55 loc) · 2.1 KB
/
console_only.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
#Spencer Wittrock 84023369 & Emma Lisowski 26903080
from connectfour import *
def game_board_gui(GameState) ->str:
'''prints a readable gameboard where 0s are represented by dots, 1 is represented by R and 2 is represented by Y'''
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 determine_winner(GameState:GameState):
'''checks the gamestate to see if a player has won'''
if winner(GameState) == RED:
return 'Red player wins'
elif winner(GameState) == YELLOW:
return 'Yellow player wins'
def command_choice(choice:str, column_choice:int, GameState: 'GameState'):
'''handles the drio ir pop input logic'''
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():
'''initializes the gameboard and runs the drop or pop logic'''
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"
GameState = command_choice(choice, column_choice, GameState)
if determine_winner(GameState) != None:
print(determine_winner(GameState))
break
except:
print('ERROR')
if __name__ == '__main__':
run_game()