-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
54 lines (45 loc) · 1.14 KB
/
main.py
File metadata and controls
54 lines (45 loc) · 1.14 KB
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
from TicTacToe import TicTacToe
def Main():
humanChoice = ''
aiChoice = ''
turn = ''
while 1 :
humanChoice = input('Select symbol X or O: ').lower()
if humanChoice == 'x':
aiChoice = 'o'
break
elif humanChoice == 'o':
aiChoice = 'x'
break
print('')
print('wrong choice')
print('')
while 1:
turn = input('Would you like to play first (y/n): ').lower()
if turn == 'y':
turn = 'human'
break
elif turn == 'n':
turn = 'ai'
break
print('')
print('wrong choice')
print('')
game = TicTacToe(humanChoice,aiChoice)
while not game.CheckFinalState() and len(game.GetEmptyCells()) > 0:
if turn == 'human':
game.HumanTime()
turn = 'ai'
else:
game.AiTime()
turn = 'human'
game.Clear()
game.Render()
if game.Winner(-1):
print('The human wins')
elif game.Winner(1):
print('The AI wins')
else:
print('tie')
if __name__ == '__main__':
Main()