/
AI.py
59 lines (34 loc) · 1.24 KB
/
AI.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
48
49
50
51
52
53
54
55
56
57
58
59
from checkConstraintfinal1 import CheckConstraints
import position
def winstrike(board, position, temp_symbol):
temp_winstrike = dict()
for i in position:
temp_winstrike[i] = CheckConstraints(i, board, 1, temp_symbol, "")
return temp_winstrike
def Play(board, Comp_position, Opp_position, Comp_symbol, player_symbol, pos_remain):
comp_winstrike = dict()
player_winstrike = dict()
comp_winstrike = winstrike(board, Comp_position, Comp_symbol)
player_winstrike = winstrike(board, Opp_position, player_symbol)
for i in comp_winstrike:
keys = comp_winstrike[i].keys()
values = comp_winstrike[i].values()
if 2 in values:
ind = values.index(2)
key = keys[ind]
return CheckConstraints(i, board, 3, Comp_symbol, key)
for i in player_winstrike:
keys = player_winstrike[i].keys()
values = player_winstrike[i].values()
if 2 in values:
ind = values.index(2)
key = keys[ind]
return CheckConstraints(i, board, 3, player_symbol, key)
corner = [1, 3, 7, 9]
for i in corner:
if (i in Comp_position) or (i in Opp_position):
continue
else:
return position.positionnum(i)
return position.positionnum(random.choise(pos_remain))
##win_Strike counts the number of places needed to win the game for a player