-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeight.cpp
More file actions
180 lines (155 loc) · 5.43 KB
/
Copy pathWeight.cpp
File metadata and controls
180 lines (155 loc) · 5.43 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include "Weight.h"
void KillShotCountWeight::initialize(GameState* g) {
Weight::initialize(g);
watchPoints.clear();
pinnedWatchPoints.clear();
unpinnedWatchPoints.clear();
//set watchpoints to queen and her surroudings
//if there is no movement in these zones, the
//default value do not have to be recalculated
queenCount = 0;
for (auto& queen : parentGameState->queens.splitIntoBitboards()){
//watch points for piece movements
watchPoints.unionWith(queen);
Bitboard queenPerimeter = queen.getPerimeter();
watchPoints.unionWith(queenPerimeter);
queenCount++;
queenPerimeter.intersectionWith(parentGameState->allPieces);
PieceColor queenColor = parentGameState->findBottomPieceColor(queen);
//watch points for friendly piece mobility
for (auto& piece: queenPerimeter.splitIntoBitboards()){
if (parentGameState->findTopPieceColor(piece) == queenColor &&
!parentGameState->upperLevelPieces.containsAny(piece)){
if (parentGameState->pinned.containsAny(piece) ) {
pinnedWatchPoints.unionWith(piece);
} else {
unpinnedWatchPoints.unionWith(piece);
}
}
}
}
auto result = recalculate();
scores[PieceColor::WHITE] = result[WHITE];
scores[PieceColor::BLACK] = result[BLACK];
}
vector<int> KillShotCountWeight::recalculate() {
vector<int> killShotCount{0,0};
for (auto& queen : parentGameState->queens.splitIntoBitboards()){
Bitboard queenPerimeter = queen.getPerimeter();
PieceColor queenColor = parentGameState->findBottomPieceColor(queen);
MoveGenerator moveGen(&parentGameState->allPieces);
moveGen.setPieceStacks(&parentGameState->pieceStacks);
moveGen.setUpperLevelPieces(&parentGameState->upperLevelPieces);
//calculate and store default values
queenPerimeter.intersectionWith(parentGameState->allPieces);
for (auto& piece: queenPerimeter.splitIntoBitboards()){
//if the pieceStack > 1, it takes too long to remove the piece
if (parentGameState->upperLevelPieces.containsAny(piece)){
killShotCount[queenColor]++;
continue;
}
if (parentGameState->findTopPieceColor(piece) == queenColor){
if (!parentGameState->pinned.containsAny(piece)){
//if the unpinned friendly piece can move
PieceName name = parentGameState->findTopPieceName(piece);
moveGen.setGeneratingName(&name);
moveGen.setGeneratingPieceBoard(&piece);
if (moveGen.getMoves().count()){
killShotCount[queenColor] += .16666;
continue;
}
}
}
killShotCount[queenColor]++;
}
}
return killShotCount;
}
/*
* Assumes that the player that is maximizing the score
* is the one that just moved
*/
double KillShotCountWeight::evaluate(MoveInfo move){
double result;
Bitboard b(parentGameState->pinned);
b.notIntersectionWith(pinnedWatchPoints);
//see if necessary to recalculate weight
if ( watchPoints.containsAny(move.newPieceLocation) ||
watchPoints.containsAny(move.oldPieceLocation) ||
unpinnedWatchPoints.containsAny(parentGameState->pinned) ||
b.count() ||
queenCount < 2)
{
auto killShotCounts = recalculate();
result = killShotCounts[WHITE] - killShotCounts[BLACK];
} else {
result = scores[WHITE] - scores[BLACK];
}
//initially assumed maximizing player is WHITE
//correct assumptions if necessary
if (parentGameState->turnColor == WHITE) result = -result;
return result*multiplier;
}
double PinnedWeight::evaluate(MoveInfo move){
int result = 0;
Bitboard whiteQueenPerimeter, blackQueenPerimeter;
for (auto& piece: parentGameState->queens.splitIntoBitboards()){
if (parentGameState->findBottomPieceColor(piece) == WHITE)
whiteQueenPerimeter = piece.getPerimeter();
else
blackQueenPerimeter = piece.getPerimeter();
}
for (Bitboard& piece : parentGameState->allPieces.splitIntoBitboards()){
//don't count piece if not pinned or if on top of hive
if (parentGameState->upperLevelPieces.containsAny(piece)
|| !(parentGameState->pinned.containsAny(piece)))
{
//don't count piece if pinned beside opposing queen
if (parentGameState->findTopPieceColor(piece) == WHITE
&& !blackQueenPerimeter.containsAny(piece))
{
result++;
} else if (parentGameState->findTopPieceColor(piece) == BLACK
&& !whiteQueenPerimeter.containsAny(piece))
{
result--;
}
}
}
if (parentGameState->turnColor == WHITE)
result = -result;
return result * multiplier;
}
void PieceCountWeight::initialize(GameState * gameState){
Weight::initialize(gameState);
for (int i = PieceColor::WHITE; i < PieceColor::NONE; i++){
for (auto element : gameState->unusedPieces[i]) {
pieceCounts[i] = HivePLM[i][element.first] - element.second;
}
}
}
double PieceCountWeight::evaluate(MoveInfo move) {
double result = pieceCounts[WHITE] - pieceCounts[BLACK];
if (!(move.newPieceLocation == Bitboard()) && move.oldPieceLocation == Bitboard()) {
if (parentGameState->findTopPieceColor(move.newPieceLocation) == WHITE)
result++;
else
result--;
}
if (parentGameState->turnColor == WHITE)
result = -result;
return result*multiplier;
}
double PinningPowerWeight::evaluate(MoveInfo move){
Bitboard unpinned = parentGameState->pinned;
unpinned.xorWith(parentGameState->allPieces);
Bitboard pinningPieces;
for (auto& testPiece : pinningPieces.splitIntoBitboards()){
Bitboard testPiecePerimeter = testPiece.getPerimeter();
testPiecePerimeter.intersectionWith(parentGameState->allPieces);
testPiecePerimeter.notIntersectionWith(unpinned);
if (testPiecePerimeter.count())
pinningPieces.unionWith(testPiece);
}
return 0;
}