Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/evaluation.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ int evaluate(board* position) {
// penalties
//int double_pawns = 0;

// passer pawn count
int passedPawnCount = 0;

// loop over piece bitboards
for (int bb_piece = P; bb_piece <= k; bb_piece++) {
// init piece bitboard copy
Expand Down Expand Up @@ -351,6 +354,7 @@ int evaluate(board* position) {
if ((whitePassedMasks[square] & position->bitboards[p]) == 0) {
// give passed pawn bonus
if (game_phase == endgame) {
passedPawnCount += 1;

int whiteKingDistance = (getLS1BIndex(position->bitboards[K]) - square) / 8;
int blackKingDistance = (getLS1BIndex(position->bitboards[k]) - square) / 8;
Expand Down Expand Up @@ -508,6 +512,8 @@ int evaluate(board* position) {
if ((blackPassedMasks[square] & position->bitboards[P]) == 0) {
// give passed pawn bonus
if (game_phase == endgame) {
passedPawnCount -= 1;

int whiteKingDistance = (getLS1BIndex(position->bitboards[K]) - square) / 8;
int blackKingDistance = (getLS1BIndex(position->bitboards[k]) - square) / 8;
int kingDistance = whiteKingDistance - blackKingDistance;
Expand Down Expand Up @@ -631,6 +637,20 @@ int evaluate(board* position) {
popBit(bitboard, square);
}
}

int infiltriation = 0;
if (!position->side && get_rank[getLS1BIndex(position->bitboards[K])] > 5) {
infiltriation = 20;
} else if (position->side && get_rank[getLS1BIndex(position->bitboards[k])] < 2) {
infiltriation = -20;
}
// winnable
int winnableScore = 6 * passedPawnCount +
8 * (countBits(position->bitboards[P]) - countBits(position->bitboards[p])) +
infiltriation
;
score += winnableScore;

int tempo = 10;
// return final evaluation based on side
return (position->side == white) ? score + tempo : -(score - tempo);
Expand Down