-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathheuristics.py
149 lines (117 loc) · 4.08 KB
/
heuristics.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
from BoardLogic import *
def numberOfPiecesHeuristic(board, isStage1):
'''
Heuristic that looks at the number of pieces on the board
'''
numPlayerOneTokens = numOfValue(board, "1")
numPlayerTwoTokens = numOfValue(board, "2")
moveablePiecesPlayer2 = 0
if not isStage1:
movablePiecesBlack = len(stage23Moves(board))
if not isStage1:
if numPlayerTwoTokens <= 2 or movablePiecesBlack == 0:
evaluation = float('inf')
elif numPlayerOneTokens <= 2:
evaluation = float('-inf')
else:
evaluation = 200 * (numPlayerOneTokens - numPlayerTwoTokens)
else:
evaluation = 100 * (numPlayerOneTokens - numPlayerTwoTokens)
return evaluation
def potentialMillsHeuristic(board, isStage1):
'''
Heuristic that looks at the number of potential mills on the board
'''
evaluation = 0
numPlayerOneTokens = numOfValue(board, "1")
numPlayerTwoTokens = numOfValue(board, "2")
numPossibleMillsPlayer1 = getPossibleMillCount(board, "1")
numPossibleMillsPlayer2 = getPossibleMillCount(board, "2")
moveablePiecesPlayer2 = 0
if not isStage1:
movablePiecesBlack = len(stage23Moves(board))
potentialMillsPlayer1 = getPiecesInPotentialMillFormation(board, "1")
potentialMillsPlayer2 = getPiecesInPotentialMillFormation(board, "2")
if not isStage1:
if numPlayerTwoTokens <= 2 or movablePiecesBlack == 0:
evaluation = float('inf')
elif numPlayerOneTokens <= 2:
evaluation = float('-inf')
else:
if (numPlayerOneTokens < 4):
evaluation += 100 * numPossibleMillsPlayer1
evaluation += 200 * potentialMillsPlayer2
else:
evaluation += 200 * numPossibleMillsPlayer1
evaluation += 100 * potentialMillsPlayer2
else:
if numPlayerOneTokens < 4:
evaluation += 100 * numPossibleMillsPlayer1
evaluation += 200 * potentialMillsPlayer2
else:
evaluation += 200 * numPossibleMillsPlayer1
evaluation += 100 * potentialMillsPlayer2
return evaluation
def numberOfMoveablePiecesHeuristic(board, isStage1):
'''
Heuristic that looks at the number of pieces and if they can move
'''
evaluation = 0
numPlayerOneTokens = numOfValue(board, "1")
numPlayerTwoTokens = numOfValue(board, "2")
moveablePiecesPlayer1 = 0
moveablePiecesPlayer2 = 0
if not isStage1:
movablePiecesBlack = len(stage23Moves(board))
if not isStage1:
if numPlayerTwoTokens <= 2 or movablePiecesBlack == 0:
evaluation = float('inf')
elif numPlayerOneTokens <= 2:
evaluation = float('-inf')
else:
evaluation = 100 * (numPlayerOneTokens - numPlayerTwoTokens)
evaluation -= 50 * movablePiecesBlack
else:
evaluation = 100 * (numPlayerOneTokens - numPlayerTwoTokens)
evaluation -= 50 * moveablePiecesPlayer2
return evaluation
def AdvancedHeuristic(board, isStage1):
'''
Heuristic that looks at the number of pieces and the potential mills
that could be formed
'''
evaluation = 0
numPlayerOneTokens = numOfValue(board, "1")
numPlayerTwoTokens = numOfValue(board, "2")
numPossibleMillsPlayer1 = getPossibleMillCount(board, "1")
numPossibleMillsPlayer2 = getPossibleMillCount(board, "2")
moveablePiecesPlayer1 = 0
moveablePiecesPlayer2 = 0
if not isStage1:
movablePiecesBlack = len(stage23Moves(board))
potentialMillsPlayer1 = getPiecesInPotentialMillFormation(board, "1")
potentialMillsPlayer2 = getPiecesInPotentialMillFormation(board, "2")
if not isStage1:
if numPlayerTwoTokens <= 2 or movablePiecesBlack == 0:
evaluation = float('inf')
elif numPlayerOneTokens <= 2:
evaluation = float('-inf')
else:
if (numPlayerOneTokens < 4):
evaluation += 100 * numPossibleMillsPlayer1
evaluation += 200 * potentialMillsPlayer2
else:
evaluation += 200 * numPossibleMillsPlayer1
evaluation += 100 * potentialMillsPlayer2
evaluation -= 25 * movablePiecesBlack
evaluation += 50 * (numPlayerOneTokens - numPlayerTwoTokens)
else:
if numPlayerOneTokens < 4:
evaluation += 100 * numPossibleMillsPlayer1
evaluation += 200 * potentialMillsPlayer2
else:
evaluation += 200 * numPossibleMillsPlayer1
evaluation += 100 * potentialMillsPlayer2
evaluation -= 25 * moveablePiecesPlayer2
evaluation += 50 * (numPlayerOneTokens - numPlayerTwoTokens)
return evaluation