Merge pull request #10 from rektdie/tapered_eval
implemented tapered eval
This commit was merged in pull request #10.
This commit is contained in:
2 files changed
+96
-16
No files matched your search
+23
-4
@@ -1,5 +1,16 @@
|
||||
#include "evaluate.h"
|
||||
|
||||
static int GetPhaseWeight(Board &board, int color) {
|
||||
int phase = 0;
|
||||
|
||||
// For all piece types other than pawn and king
|
||||
for (int piece = Knight; piece <= Queen; piece++) {
|
||||
phase += board.pieces[piece].PopCount() * phaseValues[piece - 1];
|
||||
}
|
||||
|
||||
return phase;
|
||||
}
|
||||
|
||||
static int GetMaterialScore(Board &board, int type, int color) {
|
||||
int side = color ? -1 : 1;
|
||||
|
||||
@@ -8,7 +19,11 @@ static int GetMaterialScore(Board &board, int type, int color) {
|
||||
}
|
||||
|
||||
static int GetPositionalScore(Board &board, int type, int color) {
|
||||
int score = 0;
|
||||
int middleEval = 0;
|
||||
int endEval = 0;
|
||||
|
||||
int phaseWeight = GetPhaseWeight(board, color);
|
||||
|
||||
int side = color ? -1 : 1;
|
||||
|
||||
Bitboard pieces = board.pieces[type] & board.colors[color];
|
||||
@@ -18,15 +33,19 @@ static int GetPositionalScore(Board &board, int type, int color) {
|
||||
|
||||
// White
|
||||
if (!color) {
|
||||
score += pieceSquareScores[type][scoreSquares[square]] * side;
|
||||
middleEval += middlePieceScores[type][scoreSquares[square]] * side;
|
||||
endEval += endPieceSquares[type][scoreSquares[square]] * side;
|
||||
} else {
|
||||
score += pieceSquareScores[type][square] * side;
|
||||
middleEval += middlePieceScores[type][square] * side;
|
||||
endEval += endPieceSquares[type][square] * side;
|
||||
}
|
||||
|
||||
pieces.PopBit(square);
|
||||
}
|
||||
|
||||
return score;
|
||||
int finalEval = (middleEval * phaseWeight + endEval * (phaseMax - phaseWeight)) / phaseMax;
|
||||
|
||||
return finalEval;
|
||||
}
|
||||
|
||||
int Evaluate(Board &board) {
|
||||
|
||||
+73
-12
@@ -1,6 +1,15 @@
|
||||
#pragma once
|
||||
#include "board.h"
|
||||
|
||||
constexpr int phaseMax = 24;
|
||||
|
||||
constexpr int phaseValues[4] {
|
||||
1, // Knight
|
||||
1, // Bishop
|
||||
2, // Rook
|
||||
4 // Queen
|
||||
};
|
||||
|
||||
constexpr int materialValues[6] {
|
||||
100, // Pawn
|
||||
300, // Knight
|
||||
@@ -10,7 +19,7 @@ constexpr int materialValues[6] {
|
||||
10000 // King
|
||||
};
|
||||
|
||||
constexpr int pieceSquareScores[7][64] {
|
||||
constexpr int middlePieceScores[6][64] {
|
||||
// Pawn
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,
|
||||
50, 50, 50, 50, 50, 50, 50, 50,
|
||||
@@ -61,7 +70,7 @@ constexpr int pieceSquareScores[7][64] {
|
||||
-10, 0, 5, 0, 0, 0, 0,-10,
|
||||
-20,-10,-10, -5, -5,-10,-10,-20},
|
||||
|
||||
// King middle game
|
||||
// King
|
||||
{-30,-40,-40,-50,-50,-40,-40,-30,
|
||||
-30,-40,-40,-50,-50,-40,-40,-30,
|
||||
-30,-40,-40,-50,-50,-40,-40,-30,
|
||||
@@ -70,16 +79,68 @@ constexpr int pieceSquareScores[7][64] {
|
||||
-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 endPieceSquares[6][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, 30, 30,-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, 5, 10, 10, 5, 0,-30,
|
||||
-30, 5, 10, 15, 15, 10, 5,-30,
|
||||
-30, 0, 10, 15, 15, 10, 0,-30,
|
||||
-30, 5, 5, 10, 10, 5, 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, 15, 15, 5, 5,-10,
|
||||
-10, 0, 10, 15, 15, 10, 0,-10,
|
||||
-10, 10, 10, 15, 15, 10, 10,-10,
|
||||
-10, 5, 0, 5, 5, 0, 5,-10,
|
||||
-20,-10,-10,-10,-10,-10,-10,-20},
|
||||
|
||||
// Rook
|
||||
{0, 0, 0, 5, 5, 0, 0, 0,
|
||||
5, 10, 10, 10, 10, 10, 10, 5,
|
||||
-5, 0, 0, 0, 0, 0, 0, -5,
|
||||
-5, 0, 0, 5, 5, 0, 0, -5,
|
||||
-5, 0, 0, 5, 5, 0, 0, -5,
|
||||
-5, 0, 0, 5, 5, 0, 0, -5,
|
||||
-5, 0, 0, 5, 5, 0, 0, -5,
|
||||
0, 0, 5, 10, 10, 5, 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
|
||||
{-50,-40,-30,-20,-20,-30,-40,-50,
|
||||
-30,-20,-10, 0, 0,-10,-20,-30,
|
||||
-30,-10, 20, 30, 30, 20,-10,-30,
|
||||
-30,-10, 30, 40, 40, 30,-10,-30,
|
||||
-30,-10, 30, 40, 40, 30,-10,-30,
|
||||
-30,-10, 20, 30, 30, 20,-10,-30,
|
||||
-30,-20,-10, 0, 0,-10,-20,-30,
|
||||
-50,-40,-30,-20,-20,-30,-40,-50},
|
||||
};
|
||||
|
||||
constexpr int scoreSquares[64] {
|
||||
|
||||
Reference in new issue
Block a user