-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluate.cpp
87 lines (68 loc) · 2.48 KB
/
evaluate.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
83
84
85
86
87
#include "evaluate.hpp"
#include "bitboard.hpp"
float evaluate::evaluateBoard(const bitboard::BitBoard &board)
{
float score = 0;
bitboard::PieceBits white_board = board.getWhiteBoard();
bitboard::PieceBits black_board = board.getBlackBoard();
bitboard::PieceBits kings = board.getKings();
for (int y = 0; y < constants::BOARD_SIZE; y++)
{
for (int x = 0; x < constants::BOARD_SIZE; x++)
{
pos::Pos current_pos = pos::Pos(x, y);
// Black score
if (bitboard::hasBitAt(black_board, current_pos))
{
// Material score
if (bitboard::hasBitAt(kings, current_pos))
{
score += constants::KING_VALUE;
}
else
{
score += constants::PIECE_VALUE;
// Peasants get extra score for being advanced
score += (y * constants::ADVANCE_BONUS);
// Peasants get extra score for protecting the back rank
if (y == 0)
{
score += constants::INTACT_BACK_ROW_BONUS;
}
}
// Bonus for being in the center
if (current_pos.inBounds(2, constants::BOARD_SIZE - 3))
{
score += constants::CENTER_CONTROL_BONUS;
}
continue;
}
// White score
if (bitboard::hasBitAt(white_board, current_pos))
{
if (bitboard::hasBitAt(kings, current_pos))
{
score -= constants::KING_VALUE;
}
else
{
score -= constants::PIECE_VALUE;
// Peasants get extra score for being advanced
score -= (((constants::BOARD_SIZE - 1) - y) * constants::ADVANCE_BONUS);
// Peasants get extra score for protecting the back rank
if (y == 7)
{
score -= constants::INTACT_BACK_ROW_BONUS;
}
}
// Bonus for being in the center
if (current_pos.inBounds(2, constants::BOARD_SIZE - 3))
{
score -= constants::CENTER_CONTROL_BONUS;
}
continue;
}
}
}
return score;
}