Skip to content

Commit

Permalink
optimize Board::evaluate
Browse files Browse the repository at this point in the history
  • Loading branch information
spiroskou committed Sep 9, 2024
1 parent 6a9f23a commit f8aaa30
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 27 deletions.
38 changes: 34 additions & 4 deletions Board/Board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,24 +427,54 @@ std::vector<Move> Board::getPossibleMoves(PieceColor color) const
return moves;
}

int Board::evaluate() const
int Board::evaluate() const
{
int score = 0;

// Positional piece-square tables for more strategic play
static const int pawnTable[8][8] = {
{ 0, 0, 0, 0, 0, 0, 0, 0 },
{ 5, 10, 10, -20, -20, 10, 10, 5 },
{ 5, -5, -10, 0, 0, -10, -5, 5 },
{ 0, 0, 0, 20, 20, 0, 0, 0 },
{ 5, 5, 10, 25, 25, 10, 5, 5 },
{ 10, 10, 20, 30, 30, 20, 10, 10 },
{ 50, 50, 50, 50, 50, 50, 50, 50 },
{ 0, 0, 0, 0, 0, 0, 0, 0 }
};

for (int row = 0; row < ROWS; ++row) {
for (int col = 0; col < COLS; ++col) {
auto piece = getPiece(row, col);
if (piece) {
int pieceValue = piece->getValue();
int positionalBonus = 0;

// Use piece-square tables for pawns
if (piece->getType() == PieceType::Pawn) {
if (piece->getColor() == PieceColor::White) {
positionalBonus = pawnTable[row][col];
}
else {
positionalBonus = pawnTable[7 - row][col];
}
}

// Apply positional bonuses to the score
if (piece->getColor() == getCurrentPlayerColor()) {
score -= piece->getValue();
} else {
score += piece->getValue();
score -= (pieceValue + positionalBonus);
}
else {
score += (pieceValue + positionalBonus);
}
}
}
}

return score;
}


int minimax(int depth, int alpha, int beta, bool isMaximizingPlayer)
{
if (depth == 0 || board->isCheckmate() || board->isStalemate()) {
Expand Down
Loading

0 comments on commit f8aaa30

Please sign in to comment.