-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtic.py
47 lines (47 loc) · 2 KB
/
tic.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
# q | w | e
#---+---+---
# a | s | d
#---+---+---
# z | x | c
theBoard={'q':' ','w':' ','e':' ','a':' ','s':' ','d':' ','z':' ','x':' ','c':' '}
keyForSpaces={'q':' q ','w':' w ','e':' e ','a':' a ','s':' s ','d':' d ','z':' z ','x':' x ','c':' c '}
def printBoard(board):
print(board['q']+'|'+board['w']+'|'+board['e'])
print('---+---+---')
print(board['a']+'|'+board['s']+'|'+board['d'])
print('---+---+---')
print(board['z']+'|'+board['x']+'|'+board['c'])
printBoard(theBoard)
turn='X'
while(True):
print('Turn for '+turn+'. Move on which space?')
move=input()
try:
if theBoard[move]==' ':
theBoard[move]=' '+turn+' '
else:
print('Invalid')
continue
except KeyError:
print("Invalid key chosed\nRefer to the key spaces")
printBoard(keyForSpaces)
continue
printBoard(theBoard)
if(theBoard['q']==theBoard['w']==theBoard['e'] and theBoard['e']!=' ')or(theBoard['a']==theBoard['s']==theBoard['d'] and theBoard['d']!=' ')or(theBoard['z']==theBoard['x']==theBoard['c']and theBoard['c']!=' ')or(theBoard['q']==theBoard['s']==theBoard['c']and theBoard['c']!=' ')or(theBoard['e']==theBoard['s']==theBoard['z']and theBoard['e']!=' ')or(theBoard['q']==theBoard['a']==theBoard['z'] and theBoard['z']!=' ')or(theBoard['w']==theBoard['s']==theBoard['x'] and theBoard['x']!=' ')or(theBoard['e']==theBoard['d']==theBoard['c'] and theBoard['e']!=' '):
print(turn+" won!!\nCongradulations")
choice=input("\nPress r for restart game or q to quit :")
if(choice=='r' or choice=='R'):
theBoard={'q':' ','w':' ','e':' ','a':' ','s':' ','d':' ','z':' ','x':' ','c':' '}
printBoard(theBoard)
turn='X'
i=0
continue
elif(choice=='q' or choice=='Q'):
break
else:
print("Invalid Choice")
continue
if turn=='X':
turn='0'
else:
turn='X'