forked from iliyahoo/Automate-The-Boring-Stuff-With-Python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathticTacToe.py
More file actions
38 lines (34 loc) · 775 Bytes
/
ticTacToe.py
File metadata and controls
38 lines (34 loc) · 775 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
28
29
30
31
32
33
34
35
36
37
38
theBoard = {
'1': ' ',
'2': ' ',
'3': ' ',
'4': ' ',
'5': ' ',
'6': ' ',
'7': ' ',
'8': ' ',
'9': ' ',
}
POS = '123456789'
def printBoard(board):
print(board['7'] + '|' + board['8'] + '|' +board['9'])
print('-+-+-')
print(board['4'] + '|' + board['5'] + '|' +board['6'])
print('-+-+-')
print(board['1'] + '|' + board['2'] + '|' +board['3'])
turn = 'X'
turn_number = 9
while True:
if turn_number < 0:
break
printBoard(theBoard)
move = input('\nTurn for %s.\nMove on which space?\n\n' % (turn))
if move not in POS or theBoard[move] != ' ':
continue
theBoard[move] = turn
if turn == 'X':
turn = 'O'
else:
turn = 'X'
turn_number -= 1
printBoard(theBoard)