-
Notifications
You must be signed in to change notification settings - Fork 0
/
play.py
56 lines (42 loc) · 1.25 KB
/
play.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
import pdb
from board import Board
# adjust for enter key
def get_player():
player = input("Would you like to play as X or O? ").upper()
if player not in "XO":
print("Sorry, that's not an option.")
get_player()
else:
return player
def get_ai(player):
if player == 'X': return 'O'
elif player == 'O': return 'X'
def get_move(moves):
try:
move = int(input("Where would you like to move? "))
if move > 9 or move < 1:
print("That spot doesn't exist")
get_move(moves)
if move in moves:
print("That spot is taken.")
get_move(moves)
moves.append(move)
return move
except ValueError:
print("That spot doesn't exist")
get_move(moves)
if __name__ == "__main__":
board = Board()
print("Welcome to the world's premier Tick Tack Toe experience!")
board.draw()
player = get_player()
ai = get_ai(player)
print('AI: ', ai)
moves = []
while len(moves) < 9:
move = get_move(moves)
board.draw(move, player)
winner = board.check()
if winner:
print ("{} won!".format(winner))
print("The board is full. The game is over")