added positional evaluation
This commit is contained in:
1 parent
f7286d37a4
commit
3507637d8f
3 files changed
+118
-8
No files matched your search
+31
-4
@@ -1,14 +1,41 @@
|
||||
#include "evaluate.h"
|
||||
|
||||
static int GetMaterialScore(Board &board, int type, int color) {
|
||||
int side = color ? -1 : 1;
|
||||
|
||||
return (board.pieces[type] & board.colors[color]).PopCount()
|
||||
* materialValues[type] * side;
|
||||
}
|
||||
|
||||
static int GetPositionalScore(Board &board, int type, int color) {
|
||||
int score = 0;
|
||||
int side = color ? -1 : 1;
|
||||
|
||||
Bitboard pieces = board.pieces[type] & board.colors[color];
|
||||
|
||||
while (pieces.GetBoard()) {
|
||||
int square = pieces.getLS1BIndex();
|
||||
|
||||
// White
|
||||
if (!color) {
|
||||
score += pieceSquareScores[type][scoreSquares[square]] * side;
|
||||
} else {
|
||||
score += pieceSquareScores[type][square] * side;
|
||||
}
|
||||
|
||||
pieces.PopBit(square);
|
||||
}
|
||||
|
||||
return score;
|
||||
}
|
||||
|
||||
int Evaluate(Board &board) {
|
||||
int score = 0;
|
||||
|
||||
for (int color = White; color <= Black; color++) {
|
||||
for (int type = Pawn; type <= King; type++) {
|
||||
int side = color ? -1 : 1;
|
||||
|
||||
score += (board.pieces[type] & board.colors[color]).PopCount()
|
||||
* materialValues[type] * side;
|
||||
score += GetMaterialScore(board, type, color);
|
||||
score += GetPositionalScore(board, type, color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+84
-1
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "board.h"
|
||||
|
||||
constexpr int materialValues[] {
|
||||
constexpr int materialValues[6] {
|
||||
100, // Pawn
|
||||
300, // Knight
|
||||
350, // Bishop
|
||||
@@ -10,4 +10,87 @@ constexpr int materialValues[] {
|
||||
10000 // King
|
||||
};
|
||||
|
||||
constexpr int pieceSquareScores[7][64] {
|
||||
// Pawn
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,
|
||||
50, 50, 50, 50, 50, 50, 50, 50,
|
||||
10, 10, 20, 30, 30, 20, 10, 10,
|
||||
5, 5, 10, 25, 25, 10, 5, 5,
|
||||
0, 0, 0, 20, 20, 0, 0, 0,
|
||||
5, -5,-10, 0, 0,-10, -5, 5,
|
||||
5, 10, 10,-20,-20, 10, 10, 5,
|
||||
0, 0, 0, 0, 0, 0, 0, 0},
|
||||
|
||||
// Knight
|
||||
{-50,-40,-30,-30,-30,-30,-40,-50,
|
||||
-40,-20, 0, 0, 0, 0,-20,-40,
|
||||
-30, 0, 10, 15, 15, 10, 0,-30,
|
||||
-30, 5, 15, 20, 20, 15, 5,-30,
|
||||
-30, 0, 15, 20, 20, 15, 0,-30,
|
||||
-30, 5, 10, 15, 15, 10, 5,-30,
|
||||
-40,-20, 0, 5, 5, 0,-20,-40,
|
||||
-50,-40,-30,-30,-30,-30,-40,-50},
|
||||
|
||||
// Bishop
|
||||
{-20,-10,-10,-10,-10,-10,-10,-20,
|
||||
-10, 0, 0, 0, 0, 0, 0,-10,
|
||||
-10, 0, 5, 10, 10, 5, 0,-10,
|
||||
-10, 5, 5, 10, 10, 5, 5,-10,
|
||||
-10, 0, 10, 10, 10, 10, 0,-10,
|
||||
-10, 10, 10, 10, 10, 10, 10,-10,
|
||||
-10, 5, 0, 0, 0, 0, 5,-10,
|
||||
-20,-10,-10,-10,-10,-10,-10,-20},
|
||||
|
||||
// Rook
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,
|
||||
5, 10, 10, 10, 10, 10, 10, 5,
|
||||
-5, 0, 0, 0, 0, 0, 0, -5,
|
||||
-5, 0, 0, 0, 0, 0, 0, -5,
|
||||
-5, 0, 0, 0, 0, 0, 0, -5,
|
||||
-5, 0, 0, 0, 0, 0, 0, -5,
|
||||
-5, 0, 0, 0, 0, 0, 0, -5,
|
||||
0, 0, 0, 5, 5, 0, 0, 0},
|
||||
|
||||
// Queen
|
||||
{-20,-10,-10, -5, -5,-10,-10,-20,
|
||||
-10, 0, 0, 0, 0, 0, 0,-10,
|
||||
-10, 0, 5, 5, 5, 5, 0,-10,
|
||||
-5, 0, 5, 5, 5, 5, 0, -5,
|
||||
0, 0, 5, 5, 5, 5, 0, -5,
|
||||
-10, 5, 5, 5, 5, 5, 0,-10,
|
||||
-10, 0, 5, 0, 0, 0, 0,-10,
|
||||
-20,-10,-10, -5, -5,-10,-10,-20},
|
||||
|
||||
// King middle game
|
||||
{-30,-40,-40,-50,-50,-40,-40,-30,
|
||||
-30,-40,-40,-50,-50,-40,-40,-30,
|
||||
-30,-40,-40,-50,-50,-40,-40,-30,
|
||||
-30,-40,-40,-50,-50,-40,-40,-30,
|
||||
-20,-30,-30,-40,-40,-30,-30,-20,
|
||||
-10,-20,-20,-20,-20,-20,-20,-10,
|
||||
20, 20, 0, 0, 0, 0, 20, 20,
|
||||
20, 30, 10, 0, 0, 10, 30, 20},
|
||||
|
||||
// King end game
|
||||
{-30,-40,-40,-50,-50,-40,-40,-30,
|
||||
-30,-40,-40,-50,-50,-40,-40,-30,
|
||||
-30,-40,-40,-50,-50,-40,-40,-30,
|
||||
-30,-40,-40,-50,-50,-40,-40,-30,
|
||||
-20,-30,-30,-40,-40,-30,-30,-20,
|
||||
-10,-20,-20,-20,-20,-20,-20,-10,
|
||||
20, 20, 0, 0, 0, 0, 20, 20,
|
||||
20, 30, 10, 0, 0, 10, 30, 20}
|
||||
};
|
||||
|
||||
constexpr int scoreSquares[64] {
|
||||
a8, b8, c8, d8, e8, f8, g8, h8,
|
||||
a7, b7, c7, d7, e7, f7, g7, h7,
|
||||
a6, b6, c6, d6, e6, f6, g6, h6,
|
||||
a5, b5, c5, d5, e5, f5, g5, h5,
|
||||
a4, b4, c4, d4, e4, f4, g4, h4,
|
||||
a3, b3, c3, d3, e3, f3, g3, h3,
|
||||
a2, b2, c2, d2, e2, f2, g2, h2,
|
||||
a1, b1, c1, d1, e1, f1, g1, h1
|
||||
};
|
||||
|
||||
int Evaluate(Board &board);
|
||||
+3
-3
@@ -9,9 +9,9 @@ int main() {
|
||||
initLeaperAttacks();
|
||||
initSliderAttacks();
|
||||
|
||||
Board board;
|
||||
|
||||
Board board;
|
||||
|
||||
std::cout << Evaluate(board) << '\n';
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user