-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathttt.py
More file actions
27 lines (25 loc) · 781 Bytes
/
ttt.py
File metadata and controls
27 lines (25 loc) · 781 Bytes
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
board = [['*' for i in range(3)] for j in range(3)]
def askmove(piece):
while True:
try:
x,y = map(int, input('\n> '))
if board[x-1][y-1] == '*':
board[x-1][y-1] = piece
else:
continue
except (ValueError, IndexError):
pass
else:
break
print('', *(' '.join(row) for row in board), sep='\n')
if ([piece] * 3 in board or
(piece,) * 3 in zip(*board) or
all(board[i][i] == piece for i in range(3)) or
all(board[i][2-i] == piece for i in range(3))):
print(piece, 'wins.')
elif all(p!='*' for row in board for p in row):
print('Tie.')
else:
return True
while askmove('X') and askmove('O'):
pass