-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
44 lines (37 loc) · 1.01 KB
/
main.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
'''
Main file of execution
'''
from board import Board
from minimax import *
from os import system
from time import sleep
b = Board()
# b.random_board()
existLoser = False
turn = 0
while not existLoser:
system('clear')
print b
if turn % 2 == 0:
# person
piece = raw_input('what piece would you like to move?\n')
to = raw_input('where would you like to move it?\n')
options = [b.to_letter_number(item)
for item in b.list_possible_indexes(piece)]
if to in options and b.index(*b.to_index(piece)) in b.o_pos:
b.move(piece, to)
turn += 1
else:
print "please make a valid move"
sleep(2)
existLoser = b.check_lost("o")
else:
# AI
print "AI is thinking..."
oldboard = b.state
score, b = MiniMax(b, 5, True)
turn += 1
existLoser = b.check_lost("x")
if oldboard == b.state:
existLoser = True
print "The AI surrendered"