-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnalyzer.cpp
82 lines (75 loc) · 1.63 KB
/
Analyzer.cpp
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
//
// Created by Louis GARCZYNSKI on 3/30/16.
//
#include "Analyzer.hpp"
#include "Board.hpp"
Score Analyzer::fillScore(Board &board)
{
Score score = 0;
for (int y = 0; y < BOARD_HEIGHT; y++)
{
for (int x = 0; x < BOARD_WIDTH; x++)
{
BoardSquare color = board._data[y][x];
if (color != BoardSquare::empty)
{
Score squareScore = 0;
for (int dirX = -1; dirX <= 1; dirX++)
{
for (int dirY = -1; dirY <= 1; dirY++)
{
if (dirX || dirY)
{
const int maxX = CLAMP(x + 5 * dirX, -1, BOARD_WIDTH);
const int maxY = CLAMP(y + 5 * dirY, -1, BOARD_HEIGHT);
int value = 1;
int emptyCount = 0;
int _x = x + dirX;
int _y = y + dirY;
while ((dirX == 0 || _x != maxX) && (dirY == 0 || _y != maxY))
{
BoardSquare square = board._data[_y][_x];
if (square == empty)
{
squareScore += value;
emptyCount++;
}
else if (square == color)
{
value <<= 3;
}
else
{
break;
}
_x += dirX, _y+= dirY;
}
value >>= 2;
squareScore += value * emptyCount;
}
}
}
score += (color == BoardSquare::white) ? squareScore : -squareScore;
}
}
}
return score;
}
Score Analyzer::getScore(Board &board, bool considerCapture)
{
Score score = fillScore(board);
if (considerCapture)
{
score += 1 << board._capturedBlacks / 2;
score -= 1 << board._capturedWhites / 2;
}
if (board._victoryFlag == whitePlayer)
{
score += pinfinity / 2;
}
else if (board._victoryFlag == blackPlayer)
{
score -= pinfinity / 2;
}
return score;
}