-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
35 lines (33 loc) · 1023 Bytes
/
main.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
# -*- coding: utf-8 -*-
"""
Simple Tic Tac Toe game.
"""
from tictac import TicTac, NotInTurnError, InvalidMoveError
from pprint import pprint
def play():
"""
Simple interaction with a game of tic tac toe.
"""
print "Welcome to the game of Tic Tac Toe."
game = TicTac()
while not game.is_over():
for row in game.show_game_board():
pprint(row)
print "Make a move: "
try:
input_x = int(raw_input('Position X: '))
input_y = int(raw_input('Position Y: '))
try:
game.player_one.make_move(input_x, input_y)
except NotInTurnError:
game.player_two.make_move(input_x, input_y)
except InvalidMoveError as error:
print error.message
if game.is_a_draw():
print "Ended in a draw."
else:
for row in game.show_game_board():
pprint(row)
print 'Player {} won.'.format(game.who_won().player_mark)
if __name__ == '__main__':
play()