/
game.py
30 lines (26 loc) · 885 Bytes
/
game.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
from board import Board
if __name__ == '__main__':
board = Board()
while board.check_results() == Board.CONTINUE:
try:
cell = list(map(int, str(input("Input cell coordinates (separated by space): ")).split()))
except KeyboardInterrupt:
print("Error: incorrect value")
continue
try:
board.make_move(cell)
print(board)
except AssertionError as e:
print(e)
continue
if board.check_results() != Board.CONTINUE:
break
board = board.computer_move()
print(board)
result = board.check_results()
if result == Board.CROSS_WON:
print("Player has won")
elif result == Board.NOUGHT_WON:
print("Computer has won")
elif result == Board.FINISH:
print("No one has won")