Skip to content

Commit

Permalink
Force king cornering via psqt
Browse files Browse the repository at this point in the history
  • Loading branch information
bdmendes committed Apr 21, 2024
1 parent 366f0f5 commit c513baa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/evaluation/position/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ mod rooks;
pub const MAX_POSITIONAL_GAIN: ValueScore = 200;

fn midgame_ratio(position: &Position) -> u8 {
if position.board.occupancy_bb_all().count_ones() <= 4 {
// We are in a "mating" position.
// The only goal is to corner the king.
return 0;
}

Piece::list().iter().fold(0, |acc, piece| {
acc.saturating_add(
position.board.pieces_bb(*piece).count_ones() as u8
Expand Down Expand Up @@ -68,7 +74,7 @@ impl Evaluable for Position {
}

let midgame_ratio = midgame_ratio(self);
let endgame_ratio = 255 - midgame_ratio;
let endgame_ratio = u8::MAX - midgame_ratio;
let occupancy = self.board.occupancy_bb_all();

let base_score = Piece::list().iter().fold(0, |acc, piece| {
Expand Down
5 changes: 5 additions & 0 deletions src/evaluation/psqt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ const ENDGAME_PAWN_PSQT: PieceSquareTable = [
];

pub fn psqt_value(piece: Piece, square: Square, color: Color, endgame_ratio: u8) -> ValueScore {
if endgame_ratio == u8::MAX && matches!(piece, Piece::Queen | Piece::Rook) {
// We are in a mating position, so there is no point in evaluating the PSQT.
return 0;
}

let midgame_psqt = match piece {
Piece::Pawn => &MIDGAME_PAWN_PSQT,
Piece::Knight => &MIDGAME_KNIGHT_PSQT,
Expand Down

0 comments on commit c513baa

Please sign in to comment.