diff --git a/eval/src/hand_crafted_eval.rs b/eval/src/hand_crafted_eval.rs index 010574e..ba4dcca 100644 --- a/eval/src/hand_crafted_eval.rs +++ b/eval/src/hand_crafted_eval.rs @@ -256,10 +256,10 @@ impl HandCraftedEval { match p.piece_side() { Side::White => { self.squares_relative_to_king += diff as Score - * piece_table.square_relative_to_friendly_king + * piece_table.piece_relative_to_friendly_king [(OFFSET + square.relative_to(kings[Side::White as usize])) as usize]; self.squares_relative_to_king -= diff as Score - * piece_table.square_relative_to_enemy_king[(OFFSET + * piece_table.piece_relative_to_enemy_king[(OFFSET + square .flip_vertical() .relative_to(kings[Side::Black as usize].flip_vertical())) @@ -267,13 +267,13 @@ impl HandCraftedEval { } Side::Black => { self.squares_relative_to_king -= diff as Score - * piece_table.square_relative_to_friendly_king[(OFFSET + * piece_table.piece_relative_to_friendly_king[(OFFSET + square .flip_vertical() .relative_to(kings[Side::Black as usize].flip_vertical())) as usize]; self.squares_relative_to_king += diff as Score - * piece_table.square_relative_to_enemy_king + * piece_table.piece_relative_to_enemy_king [(OFFSET + square.relative_to(kings[Side::White as usize])) as usize]; } } @@ -328,33 +328,87 @@ impl HandCraftedEval { fn update_passed_pawn_scores(&mut self, eval_data: &EvalData) { #[cfg(feature = "trace")] - self.coeffs.passed_pawn.fill(Coeff(0)); + { + self.coeffs.passed_pawn.fill(Coeff(0)); + self.coeffs + .passed_pawn_relative_to_friendly_king + .fill(Coeff(0)); + self.coeffs + .passed_pawn_relative_to_enemy_king + .fill(Coeff(0)); + } + const OFFSET_RELATIVE_TO_KING: i8 = ((Rank::NUM_RANKS - 2) * File::NUM_FILES) as i8; self.passed_pawn_scores = ScorePair(0, 0); - // Ignore the rank just before promotion (7th for white, 2nd for black). - // Pawns on these ranks are always passed, so they are already - // considered by the pawn PSTs. let mut white_passed = Self::passed_pawns_one_side( eval_data.pawns[Side::White as usize], eval_data.pawns[Side::Black as usize], Side::White, - ) & !Bitboard::RANK_7; + ); while white_passed != Bitboard::EMPTY { let square = white_passed.square_scan_forward_reset(); self.passed_pawn_scores += params::PASSED_PAWN[square.idx()]; + self.passed_pawn_scores += params::PASSED_PAWN_RELATIVE_TO_FRIENDLY_KING + [(OFFSET_RELATIVE_TO_KING + + square.relative_to(eval_data.kings[Side::White as usize])) + as usize]; + self.passed_pawn_scores -= params::PASSED_PAWN_RELATIVE_TO_ENEMY_KING + [(OFFSET_RELATIVE_TO_KING + + square + .flip_vertical() + .relative_to(eval_data.kings[Side::Black as usize].flip_vertical())) + as usize]; #[cfg(feature = "trace")] - (*self.coeffs.passed_pawn[square.fold_to_queenside().idx()] += 1); + { + // White pawns on the 7th rank are always passed, so they are + // already considered by the pawn PSTs. + if square.rank() != Rank::R7 { + *self.coeffs.passed_pawn[square.fold_to_queenside().idx()] += 1; + } + *self.coeffs.passed_pawn_relative_to_friendly_king[(OFFSET_RELATIVE_TO_KING + + square.relative_to(eval_data.kings[Side::White as usize])) + as usize] += 1; + *self.coeffs.passed_pawn_relative_to_enemy_king[(OFFSET_RELATIVE_TO_KING + + square + .flip_vertical() + .relative_to(eval_data.kings[Side::Black as usize].flip_vertical())) + as usize] -= 1; + } } let mut black_passed = Self::passed_pawns_one_side( eval_data.pawns[Side::Black as usize], eval_data.pawns[Side::White as usize], Side::Black, - ) & !Bitboard::RANK_2; + ); while black_passed != Bitboard::EMPTY { let square = black_passed.square_scan_forward_reset(); self.passed_pawn_scores -= params::PASSED_PAWN[square.flip_vertical().idx()]; + self.passed_pawn_scores -= params::PASSED_PAWN_RELATIVE_TO_FRIENDLY_KING + [(OFFSET_RELATIVE_TO_KING + + square + .flip_vertical() + .relative_to(eval_data.kings[Side::Black as usize].flip_vertical())) + as usize]; + self.passed_pawn_scores += params::PASSED_PAWN_RELATIVE_TO_ENEMY_KING + [(OFFSET_RELATIVE_TO_KING + + square.relative_to(eval_data.kings[Side::White as usize])) + as usize]; #[cfg(feature = "trace")] - (*self.coeffs.passed_pawn[square.flip_vertical().fold_to_queenside().idx()] -= 1); + { + // Black pawns on the 2nd rank are always passed, so they are + // already considered by the pawn PSTs. + if square.rank() != Rank::R2 { + *self.coeffs.passed_pawn[square.flip_vertical().fold_to_queenside().idx()] -= 1; + } + *self.coeffs.passed_pawn_relative_to_friendly_king[(OFFSET_RELATIVE_TO_KING + + square + .flip_vertical() + .relative_to(eval_data.kings[Side::Black as usize].flip_vertical())) + as usize] -= 1; + *self.coeffs.passed_pawn_relative_to_enemy_king[(OFFSET_RELATIVE_TO_KING + + square.relative_to(eval_data.kings[Side::White as usize])) + as usize] += 1; + } } } diff --git a/eval/src/hand_crafted_eval_coeffs.rs b/eval/src/hand_crafted_eval_coeffs.rs index ae749e9..5ea3058 100644 --- a/eval/src/hand_crafted_eval_coeffs.rs +++ b/eval/src/hand_crafted_eval_coeffs.rs @@ -61,16 +61,18 @@ pub struct HandCraftedEvalCoeffs { pub rook_mobility: [Coeff; params::ROOK_MOB_LEN], pub queen_mobility: [Coeff; params::QUEEN_MOB_LEN], pub bishop_pair: Coeff, - pub pawn_square_relative_to_friendly_king: [Coeff; params::SQUARE_RELATIVE_TO_KING_LEN], - pub pawn_square_relative_to_enemy_king: [Coeff; params::SQUARE_RELATIVE_TO_KING_LEN], - pub knight_square_relative_to_friendly_king: [Coeff; params::SQUARE_RELATIVE_TO_KING_LEN], - pub knight_square_relative_to_enemy_king: [Coeff; params::SQUARE_RELATIVE_TO_KING_LEN], - pub bishop_square_relative_to_friendly_king: [Coeff; params::SQUARE_RELATIVE_TO_KING_LEN], - pub bishop_square_relative_to_enemy_king: [Coeff; params::SQUARE_RELATIVE_TO_KING_LEN], - pub rook_square_relative_to_friendly_king: [Coeff; params::SQUARE_RELATIVE_TO_KING_LEN], - pub rook_square_relative_to_enemy_king: [Coeff; params::SQUARE_RELATIVE_TO_KING_LEN], - pub queen_square_relative_to_friendly_king: [Coeff; params::SQUARE_RELATIVE_TO_KING_LEN], - pub queen_square_relative_to_enemy_king: [Coeff; params::SQUARE_RELATIVE_TO_KING_LEN], + pub pawn_square_relative_to_friendly_king: [Coeff; params::PIECE_RELATIVE_TO_KING_LEN], + pub pawn_square_relative_to_enemy_king: [Coeff; params::PIECE_RELATIVE_TO_KING_LEN], + pub knight_square_relative_to_friendly_king: [Coeff; params::PIECE_RELATIVE_TO_KING_LEN], + pub knight_square_relative_to_enemy_king: [Coeff; params::PIECE_RELATIVE_TO_KING_LEN], + pub bishop_square_relative_to_friendly_king: [Coeff; params::PIECE_RELATIVE_TO_KING_LEN], + pub bishop_square_relative_to_enemy_king: [Coeff; params::PIECE_RELATIVE_TO_KING_LEN], + pub rook_square_relative_to_friendly_king: [Coeff; params::PIECE_RELATIVE_TO_KING_LEN], + pub rook_square_relative_to_enemy_king: [Coeff; params::PIECE_RELATIVE_TO_KING_LEN], + pub queen_square_relative_to_friendly_king: [Coeff; params::PIECE_RELATIVE_TO_KING_LEN], + pub queen_square_relative_to_enemy_king: [Coeff; params::PIECE_RELATIVE_TO_KING_LEN], + pub passed_pawn_relative_to_friendly_king: [Coeff; params::PASSED_PAWNS_RELATIVE_TO_KING_LEN], + pub passed_pawn_relative_to_enemy_king: [Coeff; params::PASSED_PAWNS_RELATIVE_TO_KING_LEN], } impl Default for HandCraftedEvalCoeffs { @@ -93,18 +95,20 @@ impl Default for HandCraftedEvalCoeffs { rook_mobility: Default::default(), queen_mobility: Default::default(), bishop_pair: Default::default(), - pawn_square_relative_to_friendly_king: [Coeff(0); params::SQUARE_RELATIVE_TO_KING_LEN], - pawn_square_relative_to_enemy_king: [Coeff(0); params::SQUARE_RELATIVE_TO_KING_LEN], - knight_square_relative_to_friendly_king: [Coeff(0); - params::SQUARE_RELATIVE_TO_KING_LEN], - knight_square_relative_to_enemy_king: [Coeff(0); params::SQUARE_RELATIVE_TO_KING_LEN], - bishop_square_relative_to_friendly_king: [Coeff(0); - params::SQUARE_RELATIVE_TO_KING_LEN], - bishop_square_relative_to_enemy_king: [Coeff(0); params::SQUARE_RELATIVE_TO_KING_LEN], - rook_square_relative_to_friendly_king: [Coeff(0); params::SQUARE_RELATIVE_TO_KING_LEN], - rook_square_relative_to_enemy_king: [Coeff(0); params::SQUARE_RELATIVE_TO_KING_LEN], - queen_square_relative_to_friendly_king: [Coeff(0); params::SQUARE_RELATIVE_TO_KING_LEN], - queen_square_relative_to_enemy_king: [Coeff(0); params::SQUARE_RELATIVE_TO_KING_LEN], + pawn_square_relative_to_friendly_king: [Coeff(0); params::PIECE_RELATIVE_TO_KING_LEN], + pawn_square_relative_to_enemy_king: [Coeff(0); params::PIECE_RELATIVE_TO_KING_LEN], + knight_square_relative_to_friendly_king: [Coeff(0); params::PIECE_RELATIVE_TO_KING_LEN], + knight_square_relative_to_enemy_king: [Coeff(0); params::PIECE_RELATIVE_TO_KING_LEN], + bishop_square_relative_to_friendly_king: [Coeff(0); params::PIECE_RELATIVE_TO_KING_LEN], + bishop_square_relative_to_enemy_king: [Coeff(0); params::PIECE_RELATIVE_TO_KING_LEN], + rook_square_relative_to_friendly_king: [Coeff(0); params::PIECE_RELATIVE_TO_KING_LEN], + rook_square_relative_to_enemy_king: [Coeff(0); params::PIECE_RELATIVE_TO_KING_LEN], + queen_square_relative_to_friendly_king: [Coeff(0); params::PIECE_RELATIVE_TO_KING_LEN], + queen_square_relative_to_enemy_king: [Coeff(0); params::PIECE_RELATIVE_TO_KING_LEN], + passed_pawn_relative_to_friendly_king: [Coeff(0); + params::PASSED_PAWNS_RELATIVE_TO_KING_LEN], + passed_pawn_relative_to_enemy_king: [Coeff(0); + params::PASSED_PAWNS_RELATIVE_TO_KING_LEN], } } } @@ -126,21 +130,16 @@ impl HandCraftedEvalCoeffs { } pub fn clear_squares_relative_to_king(&mut self) { - self.pawn_square_relative_to_friendly_king = - [Coeff(0); params::SQUARE_RELATIVE_TO_KING_LEN]; - self.pawn_square_relative_to_enemy_king = [Coeff(0); params::SQUARE_RELATIVE_TO_KING_LEN]; - self.knight_square_relative_to_friendly_king = - [Coeff(0); params::SQUARE_RELATIVE_TO_KING_LEN]; - self.knight_square_relative_to_enemy_king = [Coeff(0); params::SQUARE_RELATIVE_TO_KING_LEN]; - self.bishop_square_relative_to_friendly_king = - [Coeff(0); params::SQUARE_RELATIVE_TO_KING_LEN]; - self.bishop_square_relative_to_enemy_king = [Coeff(0); params::SQUARE_RELATIVE_TO_KING_LEN]; - self.rook_square_relative_to_friendly_king = - [Coeff(0); params::SQUARE_RELATIVE_TO_KING_LEN]; - self.rook_square_relative_to_enemy_king = [Coeff(0); params::SQUARE_RELATIVE_TO_KING_LEN]; - self.queen_square_relative_to_friendly_king = - [Coeff(0); params::SQUARE_RELATIVE_TO_KING_LEN]; - self.queen_square_relative_to_enemy_king = [Coeff(0); params::SQUARE_RELATIVE_TO_KING_LEN]; + self.pawn_square_relative_to_friendly_king.fill(Coeff(0)); + self.pawn_square_relative_to_enemy_king.fill(Coeff(0)); + self.knight_square_relative_to_friendly_king.fill(Coeff(0)); + self.knight_square_relative_to_enemy_king.fill(Coeff(0)); + self.bishop_square_relative_to_friendly_king.fill(Coeff(0)); + self.bishop_square_relative_to_enemy_king.fill(Coeff(0)); + self.rook_square_relative_to_friendly_king.fill(Coeff(0)); + self.rook_square_relative_to_enemy_king.fill(Coeff(0)); + self.queen_square_relative_to_friendly_king.fill(Coeff(0)); + self.queen_square_relative_to_enemy_king.fill(Coeff(0)); } pub fn add_squares_relative_to_king( @@ -224,5 +223,7 @@ impl HandCraftedEvalCoeffs { .chain(self.rook_square_relative_to_enemy_king.iter()) .chain(self.queen_square_relative_to_friendly_king.iter()) .chain(self.queen_square_relative_to_enemy_king.iter()) + .chain(self.passed_pawn_relative_to_friendly_king.iter()) + .chain(self.passed_pawn_relative_to_enemy_king.iter()) } } diff --git a/eval/src/params.rs b/eval/src/params.rs index 7b45140..3f6a669 100644 --- a/eval/src/params.rs +++ b/eval/src/params.rs @@ -10,8 +10,10 @@ pub const ROOK_MOB_LEN: usize = 15; pub const QUEEN_MOB_LEN: usize = 28; pub const MOB_LEN: usize = KNIGHT_MOB_LEN + BISHOP_MOB_LEN + ROOK_MOB_LEN + QUEEN_MOB_LEN; -pub const DISTANCE_LEN: usize = 8; -pub const SQUARE_RELATIVE_TO_KING_LEN: usize = (2 * Rank::NUM_RANKS - 1) * File::NUM_FILES; +pub const PIECE_RELATIVE_TO_KING_LEN: usize = (2 * Rank::NUM_RANKS - 1) * File::NUM_FILES; +// Pawns are never on ranks 1 or 8, so we can ignore them +pub const PASSED_PAWNS_RELATIVE_TO_KING_LEN: usize = + (2 * (Rank::NUM_RANKS - 1) - 1) * File::NUM_FILES; // (middlegame, endgame) const MATERIAL_KING: ScorePair = ScorePair(0, 0); @@ -22,270 +24,308 @@ const MATERIAL_KNIGHT: ScorePair = ScorePair(0, 0); const MATERIAL_PAWN: ScorePair = ScorePair(0, 0); // The side to move gets a small bonus -pub const TEMPO: ScorePair = ScorePair(30, 29); +pub const TEMPO: ScorePair = ScorePair(29, 29); #[rustfmt::skip] const PASSED_PAWN_MG_EG: ([Score; 32], [Score; 32]) = ( [ 0, 0, 0, 0, 0, 0, 0, 0, - 16, 8, -9, -17, - 19, 22, 15, 6, - 23, -3, -10, -7, - 18, 22, 5, -16, - 9, 11, 10, -11, + -30, -13, -18, -27, + -32, -12, -10, -22, + -21, -46, -40, -49, + -7, -3, -23, -41, + 2, 13, -13, -36, 0, 0, 0, 0, ], [ 0, 0, 0, 0, 0, 0, 0, 0, - 138, 121, 107, 82, - 64, 63, 43, 43, - 30, 35, 20, 18, - 10, 9, 4, 1, - 13, 18, -3, -4, + 129, 114, 106, 86, + 61, 61, 44, 49, + 26, 34, 20, 24, + -2, -2, -6, -7, + -8, -9, -23, -23, 0, 0, 0, 0, ], ); -pub const ISOLATED_PAWN: ScorePair = ScorePair(-17, -8); +pub const ISOLATED_PAWN: ScorePair = ScorePair(-16, -9); pub const BACKWARD_PAWN: ScorePair = ScorePair(-11, -3); -pub const DOUBLED_PAWN: ScorePair = ScorePair(-7, -9); +pub const DOUBLED_PAWN: ScorePair = ScorePair(-8, -7); -pub const BISHOP_PAIR: ScorePair = ScorePair(31, 41); +pub const BISHOP_PAIR: ScorePair = ScorePair(30, 40); const MOBILITY_KNIGHT_MG_EG: ([Score; KNIGHT_MOB_LEN], [Score; KNIGHT_MOB_LEN]) = ( - [19, 48, 59, 64, 70, 71, 73, 74, 73], - [-18, -24, -29, -32, -32, -29, -30, -34, -33], + [19, 46, 56, 61, 68, 69, 70, 72, 70], + [-19, -25, -30, -32, -32, -29, -31, -34, -33], ); const MOBILITY_BISHOP_MG_EG: ([Score; BISHOP_MOB_LEN], [Score; BISHOP_MOB_LEN]) = ( - [24, 35, 47, 51, 56, 61, 66, 68, 72, 73, 82, 87, 94, 68], - [-46, -31, -32, -23, -15, -6, -3, 4, 8, 11, 5, 9, 9, 18], + [22, 33, 44, 49, 54, 59, 64, 65, 69, 70, 79, 84, 95, 68], + [-44, -30, -31, -21, -13, -4, -1, 5, 9, 12, 7, 9, 7, 19], ); const MOBILITY_ROOK_MG_EG: ([Score; ROOK_MOB_LEN], [Score; ROOK_MOB_LEN]) = ( - [-1, 8, 10, 15, 17, 26, 30, 35, 39, 47, 53, 55, 65, 82, 91], - [ - -40, -29, -18, -13, -10, -10, -11, -5, -1, -2, 1, 6, 10, 5, -3, - ], + [-3, 6, 8, 12, 15, 23, 27, 31, 36, 43, 49, 51, 61, 78, 85], + [-39, -27, -16, -12, -8, -8, -8, -3, 2, 1, 4, 10, 12, 8, 0], ); const MOBILITY_QUEEN_MG_EG: ([Score; QUEEN_MOB_LEN], [Score; QUEEN_MOB_LEN]) = ( [ - 37, 50, 54, 55, 62, 66, 71, 71, 69, 76, 79, 78, 79, 82, 86, 91, 95, 92, 102, 102, 95, 112, - 116, 133, 92, 77, 73, 57, + 36, 48, 52, 53, 60, 64, 69, 69, 67, 73, 76, 76, 77, 79, 84, 88, 92, 89, 99, 99, 92, 110, + 113, 126, 91, 74, 75, 58, ], [ - 5, -7, -19, -8, -25, 3, -3, 4, 26, 34, 38, 49, 55, 61, 64, 57, 58, 75, 72, 71, 85, 71, 67, - 62, 76, 94, 89, 91, + 6, -6, -18, -8, -23, 4, -3, 4, 26, 34, 38, 48, 54, 60, 63, 57, 59, 75, 71, 70, 85, 69, 67, + 63, 74, 93, 89, 93, ], ); -const PAWN_SQUARE_RELATIVE_TO_FRIENDLY_KING_MG_EG: ( - [Score; SQUARE_RELATIVE_TO_KING_LEN], - [Score; SQUARE_RELATIVE_TO_KING_LEN], +const PAWN_RELATIVE_TO_FRIENDLY_KING_MG_EG: ( + [Score; PIECE_RELATIVE_TO_KING_LEN], + [Score; PIECE_RELATIVE_TO_KING_LEN], ) = ( [ - 0, 0, 0, 0, 0, 0, 0, 0, 2, -9, -1, 0, 2, -1, 4, 0, 5, -8, 11, -2, -3, -14, -9, 3, -21, -20, - -31, -15, -9, -36, -24, -5, -21, -29, -44, -73, -45, -72, -88, -9, 9, -47, -27, -79, -66, - -80, -64, -32, 17, -8, 16, -16, -21, -35, -47, -23, 0, 45, 21, 6, -4, -18, -32, -24, 69, - 48, 17, 15, -1, -20, -6, -12, 68, 37, 32, 13, 10, -7, -8, -12, 48, 35, 19, 15, 16, 2, 6, - -2, 39, 24, 20, 23, 20, 18, 15, 15, 12, 5, 0, 9, 21, 18, 23, -1, -7, -22, 5, -12, -9, 3, - 54, -24, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 2, -11, -3, -3, -1, -4, 1, -1, 4, -5, 8, -7, -3, -17, -12, 3, -24, + -25, -29, -15, -12, -40, -26, -4, -25, -36, -35, -69, -36, -61, -82, -10, -4, -35, -30, + -74, -61, -69, -62, -28, 19, -11, 9, -13, -11, -30, -40, -18, 0, 44, 16, 6, -2, -14, -28, + -10, 65, 46, 15, 14, 0, -19, -5, 2, 64, 34, 29, 10, 9, -8, -9, 0, 43, 31, 16, 12, 14, -1, + 3, 8, 36, 26, 20, 22, 20, 18, 10, 22, 25, 31, 7, -1, 11, 9, -1, 4, -6, -16, -5, -11, 1, 8, + 42, -19, 0, 0, 0, 0, 0, 0, 0, 0, ], [ - 0, 0, 0, 0, 0, 0, 0, 0, 35, 30, 26, 26, 45, 9, 36, 10, 56, 55, 45, 35, 42, 64, 36, 24, 40, - 49, 31, 33, 39, 45, 41, 23, 28, 32, 31, 30, 31, 33, 44, 33, 14, 34, 17, 29, 31, 35, 30, 37, - 17, 12, 11, 17, 19, 21, 27, 17, 0, 12, 8, 5, 9, 11, 21, 10, -8, -8, 6, 3, 4, 13, 9, 8, -7, - -3, -4, -4, -4, 2, 3, 7, -21, -19, -19, -14, -13, -2, -6, -5, -35, -24, -32, -31, -16, -19, - -8, -23, -38, -21, -28, -31, -27, -14, -4, -12, -61, -48, -62, -26, -22, -28, -16, 24, 0, - 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 33, 14, 17, 8, 22, -15, 20, 6, 34, 32, 19, 4, 11, 24, 12, 13, 16, + 34, 5, 1, 3, 13, 22, 18, 14, 23, 14, 8, 8, 11, 27, 22, 11, 26, 15, 21, 15, 19, 22, 30, 9, + 13, 11, 12, 8, 12, 17, 19, 0, 9, 10, 4, 4, 4, 15, 6, -8, -8, 7, 4, 3, 11, 6, 8, -3, 1, 0, + 1, 0, 4, 4, 11, -12, -11, -11, -6, -8, 3, -2, 3, -20, -19, -24, -24, -10, -13, -7, -15, 9, + -14, -17, -10, -11, -12, -4, 0, -15, -10, -17, -2, -6, -14, -11, 26, 0, 0, 0, 0, 0, 0, 0, + 0, ], ); -const PAWN_SQUARE_RELATIVE_TO_ENEMY_KING_MG_EG: ( - [Score; SQUARE_RELATIVE_TO_KING_LEN], - [Score; SQUARE_RELATIVE_TO_KING_LEN], +const PAWN_RELATIVE_TO_ENEMY_KING_MG_EG: ( + [Score; PIECE_RELATIVE_TO_KING_LEN], + [Score; PIECE_RELATIVE_TO_KING_LEN], ) = ( [ - 0, 0, 0, 0, 0, 0, 0, 0, -4, -2, 4, -3, -7, 0, -3, -1, -2, -2, 0, -1, -3, 9, -5, -1, 1, 16, - 24, 17, -1, 7, 4, 10, 15, 57, 30, 33, 51, 48, 28, 3, 66, 86, 76, 88, 65, 61, 38, 34, 53, - 113, 7, 43, 57, 52, 32, 29, 0, -15, -58, 28, 56, 44, 46, 29, 24, -88, -47, 0, -6, 18, 11, - 1, -42, -45, -25, -19, -4, 0, -6, 18, -16, -31, -27, -12, -17, -19, -17, 5, -14, -26, -26, - -28, -22, -25, -35, -5, -17, -25, -30, -31, -26, -29, -33, 1, -21, -26, -30, -29, -27, -26, - -41, -5, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, -4, 0, 3, -3, -7, 0, -3, -2, 1, 3, 3, 4, -1, 11, -2, -2, 9, 25, 28, + 17, 3, 11, 5, 8, 19, 61, 33, 38, 51, 43, 23, 4, 67, 76, 72, 79, 60, 48, 30, 34, 49, 71, + -19, 23, 47, 38, 28, 28, 0, 11, -61, 19, 26, 30, 32, 24, -8, -85, -29, 14, -24, 4, 9, -2, + -33, -25, -18, -10, -8, 5, -2, 3, -10, -23, -22, -7, -13, -15, -11, -4, -9, -20, -21, -23, + -18, -19, -27, -13, -12, -20, -25, -27, -21, -23, -25, -6, -17, -21, -26, -25, -23, -21, + -33, -11, 0, 0, 0, 0, 0, 0, 0, 0, ], [ - 0, 0, 0, 0, 0, 0, 0, 0, -16, -18, 9, -33, -43, -24, -32, -6, -67, -73, -70, -63, -69, -61, - -75, -51, -84, -60, -68, -61, -40, -69, -68, -28, -47, -44, -30, -36, -50, -59, -39, -7, - -11, -10, -17, -31, -35, -33, -29, -14, 26, 16, 34, -3, -19, -27, -19, -20, 0, 71, 54, 12, - -10, -13, -24, -12, 68, 33, 44, 16, 9, -7, -12, -7, 34, 35, 24, 21, 9, -1, -5, -15, 26, 24, - 24, 19, 12, 6, 1, -19, 22, 24, 24, 23, 16, 9, 9, -9, 23, 21, 22, 23, 16, 11, 9, -8, 27, 21, - 22, 20, 18, 12, 11, -7, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, -13, -7, 2, -29, -41, -23, -24, -5, -44, -39, -39, -43, -43, -43, + -50, -47, -39, -31, -36, -37, -22, -26, -43, -24, 2, -8, 11, 5, -6, -29, -22, -9, 26, 22, + 19, 14, 1, -13, -19, -11, 38, 30, 36, 16, 3, -13, -16, -21, 0, 41, 38, 17, -1, -8, -20, + -23, 34, -3, 28, 11, 13, -1, -11, -5, 14, 16, 12, 10, 6, -6, -10, -18, 15, 13, 12, 6, 0, + -3, -8, -27, 10, 11, 10, 8, 3, -5, -4, -21, 9, 7, 6, 7, 1, -5, -6, -24, 10, 5, 5, 3, 0, -5, + -8, -28, 0, 0, 0, 0, 0, 0, 0, 0, ], ); -const KNIGHT_SQUARE_RELATIVE_TO_FRIENDLY_KING_MG_EG: ( - [Score; SQUARE_RELATIVE_TO_KING_LEN], - [Score; SQUARE_RELATIVE_TO_KING_LEN], +const KNIGHT_RELATIVE_TO_FRIENDLY_KING_MG_EG: ( + [Score; PIECE_RELATIVE_TO_KING_LEN], + [Score; PIECE_RELATIVE_TO_KING_LEN], ) = ( [ - -1, -1, 0, 0, 0, 0, 0, 0, -1, -4, -6, -3, -1, 1, -2, 0, -6, -3, -9, -5, -6, -2, -2, 0, -6, - -7, -15, -10, -25, -3, -16, 0, -6, -29, -2, -22, -14, -11, -2, 0, -30, 2, 8, -11, -10, -39, - 1, -5, 39, 12, 34, 22, -6, 8, 14, 0, 0, 26, 19, 29, 2, 18, 16, 3, 48, 37, 28, 23, 17, 8, - 22, -27, 37, 35, 35, 24, 12, 16, 8, -23, 23, 27, 24, 21, 29, 29, 17, 1, -3, 20, 6, 20, 32, - 11, 27, -36, 26, -11, -1, -21, 17, 16, 28, 23, 14, 7, -5, 5, -46, 20, 6, 16, 28, 5, 25, - -14, -48, -56, 18, 22, + -1, -1, -1, 0, 0, 0, 0, 0, -2, -4, -5, -4, -1, 0, -1, 0, -6, -2, -9, -5, -6, -2, -2, 0, -5, + -6, -14, -9, -22, -4, -15, 0, -6, -29, -1, -21, -14, -10, -2, 0, -28, -1, 7, -11, -9, -42, + 1, -5, 41, 12, 34, 22, -7, 6, 14, 0, 0, 27, 19, 28, 2, 18, 17, 5, 48, 37, 29, 23, 16, 8, + 22, -25, 38, 35, 35, 25, 12, 17, 8, -23, 24, 26, 24, 20, 29, 28, 17, 3, -3, 18, 6, 18, 30, + 9, 22, -36, 27, -11, -3, -21, 16, 15, 26, 25, 13, 6, -7, 3, -48, 19, 3, 14, 26, 2, 26, -15, + -46, -57, 18, 22, ], [ - -7, -6, -2, 0, 0, 0, -7, 0, -11, -18, -28, -6, -5, -3, -5, -2, -17, -4, -9, -23, -4, -2, 3, - -2, -37, -23, -35, -36, -35, -14, -22, -2, -31, -28, -21, -29, -16, -23, -15, -1, -14, -16, - -10, 1, -12, -29, -28, -13, -16, -8, -20, -13, -6, -28, -46, 1, 0, -5, -11, -16, -8, -24, - -35, -34, -2, -11, -6, -5, -9, -14, -18, -16, 3, -8, 0, -1, -1, -3, 6, -3, 4, 4, 10, 0, 2, - -4, 12, 17, 21, 22, 23, 29, 4, 21, 7, -9, 20, 32, 25, 42, 31, 11, 18, 20, 21, 23, 33, 39, - 42, 24, 26, 17, 33, -16, 13, 28, 25, 24, 30, 21, + -7, -4, -4, 1, 0, 0, 0, 0, -16, -31, -25, -9, -6, -4, -3, -1, -27, 3, -10, -18, -8, -6, 2, + -2, -34, -27, -37, -34, -36, -17, -17, 3, -33, -26, -19, -34, -12, -24, -14, 1, -17, -13, + -9, 3, -15, -24, -24, -12, -18, -9, -21, -13, -4, -24, -43, 4, 0, -8, -12, -16, -7, -23, + -33, -33, -5, -13, -8, -7, -9, -13, -14, -10, 0, -10, -2, -2, -3, -3, 7, -1, 0, 2, 8, 0, 3, + -3, 13, 19, 19, 22, 22, 30, 4, 22, 12, -8, 18, 32, 24, 41, 30, 10, 23, 19, 18, 22, 33, 39, + 42, 23, 30, 13, 33, -15, 11, 27, 25, 24, 29, 21, ], ); -const KNIGHT_SQUARE_RELATIVE_TO_ENEMY_KING_MG_EG: ( - [Score; SQUARE_RELATIVE_TO_KING_LEN], - [Score; SQUARE_RELATIVE_TO_KING_LEN], +const KNIGHT_RELATIVE_TO_ENEMY_KING_MG_EG: ( + [Score; PIECE_RELATIVE_TO_KING_LEN], + [Score; PIECE_RELATIVE_TO_KING_LEN], ) = ( [ - 0, -1, 0, 1, 0, 0, -1, 0, -1, 2, 5, 1, 2, 0, 1, 3, 13, 13, 10, 5, 9, 7, 1, -1, 5, 21, 2, 8, - 10, 3, 2, 0, 24, 3, -1, 2, 11, 17, -3, 1, -13, -10, 6, 44, -1, 15, 15, 4, 15, 6, -76, 6, - -7, 30, 6, -2, 0, 21, -20, -4, -34, 14, 66, -16, -46, -20, -162, -22, 6, -5, 15, 12, -33, - -129, -17, -9, -18, 10, 14, 14, -13, -25, -5, -18, 4, 5, -6, -18, -15, -2, -10, 4, -2, -6, - -13, 36, -9, -7, -7, -1, -16, -3, -11, 35, -10, -18, -15, -25, -17, 6, -3, -23, -28, -11, - -27, -19, -20, -35, -36, -19, + 0, -1, 0, 1, 0, 0, -1, 0, -1, 2, 5, 1, 1, 0, 1, 3, 13, 12, 9, 5, 8, 7, 1, -1, 4, 19, -1, 6, + 8, 3, 1, 0, 24, -3, -3, 1, 11, 16, -4, 2, -15, -13, 4, 39, -2, 16, 15, 5, 13, 6, -76, 10, + -10, 26, 10, -2, 0, 22, -17, -5, -36, 12, 68, -14, -43, -19, -158, -21, 5, -5, 12, 12, -30, + -124, -15, -7, -18, 9, 14, 15, -11, -23, -3, -17, 4, 5, -7, -18, -13, -1, -9, 5, -1, -5, + -12, 35, -8, -6, -6, 0, -15, -2, -10, 34, -9, -17, -14, -23, -16, 7, -2, -21, -27, -10, + -25, -18, -19, -33, -35, -18, ], [ - 0, 0, 1, 7, 7, 1, 0, 0, -4, 15, 19, 9, 20, 1, 1, 7, 19, 37, 21, 26, 58, 33, 6, -4, 18, 59, - 22, 31, 39, 46, 9, 7, 33, 32, 50, -10, 32, 50, 9, 5, 20, 6, 46, 23, 15, 26, 38, 6, 49, 18, - 5, -2, 12, 8, 15, -5, 0, 29, 2, 4, -6, -3, -31, 11, 31, -2, 1, -15, -2, -3, -4, 8, -6, -33, - -3, -11, -27, -18, -9, -14, -14, -31, -12, -52, -31, -23, -21, 17, -21, -19, -27, -24, -25, - -17, -18, -33, -13, -19, -21, -27, -19, -23, -16, 4, 0, -17, -12, -7, -1, -8, -19, -8, 0, - -25, -12, -28, -19, 8, 7, -3, + 0, 0, 0, 7, 6, 1, 2, 0, -3, 15, 20, 9, 16, 0, 1, 6, 19, 39, 17, 37, 54, 34, 12, -2, 15, 61, + 18, 33, 48, 47, 6, 8, 32, 32, 49, -10, 35, 48, 3, 6, 18, 2, 46, 24, 14, 25, 40, 8, 48, 17, + 2, -6, 12, 13, 15, -1, 0, 26, -2, 5, -5, 0, -34, 9, 28, -4, -1, -15, -2, -1, 0, 14, -9, + -36, -4, -12, -26, -15, -6, -11, -15, -32, -13, -51, -30, -22, -17, 20, -23, -20, -28, -24, + -23, -17, -16, -29, -14, -19, -22, -28, -19, -22, -15, 6, -2, -19, -14, -8, -1, -8, -20, + -5, -3, -27, -14, -29, -20, 7, 6, -3, ], ); -const BISHOP_SQUARE_RELATIVE_TO_FRIENDLY_KING_MG_EG: ( - [Score; SQUARE_RELATIVE_TO_KING_LEN], - [Score; SQUARE_RELATIVE_TO_KING_LEN], +const BISHOP_RELATIVE_TO_FRIENDLY_KING_MG_EG: ( + [Score; PIECE_RELATIVE_TO_KING_LEN], + [Score; PIECE_RELATIVE_TO_KING_LEN], ) = ( [ - -4, -4, -5, -1, -5, 1, 0, 0, -1, -4, -8, -1, -2, 1, -1, -1, -14, 4, -2, -8, 2, -1, 4, -7, - -14, -27, -20, -33, -16, -1, -2, -2, -20, -35, -10, -21, -46, -26, -1, -1, 24, 3, -11, -17, - 25, -25, -10, -1, -4, 14, 8, 21, 18, 22, -37, -7, 0, 17, 33, 28, 34, 17, -1, -10, 48, 49, - 35, 30, 14, 16, 17, -2, 48, 26, 37, 17, 26, 21, 29, 11, 30, 35, 25, 30, 16, 29, 30, 9, 20, - -4, 31, 20, 25, 18, 10, -25, 32, 22, 14, 20, 0, 27, 14, -7, -10, 11, 0, 13, 14, 31, 65, 47, - 17, 16, -29, 5, 10, 25, 30, -11, + -5, -4, -4, -1, -5, 1, 0, 0, -1, -4, -9, -2, -3, 1, 0, -1, -15, 5, -2, -7, 1, 0, 4, -7, + -11, -25, -21, -32, -18, -1, -1, -1, -21, -34, -11, -20, -45, -24, 0, 0, 21, 3, -12, -19, + 24, -28, -10, 1, -6, 13, 7, 20, 15, 20, -40, -6, 0, 16, 32, 27, 33, 16, -2, -9, 48, 49, 35, + 29, 14, 16, 18, -2, 47, 26, 36, 16, 25, 22, 28, 13, 30, 35, 24, 30, 16, 28, 30, 12, 20, -3, + 31, 20, 25, 17, 9, -22, 31, 24, 14, 21, 0, 26, 12, -8, -12, 10, 0, 12, 13, 30, 62, 42, 16, + 19, -28, 4, 10, 26, 29, -12, ], [ - -15, -8, -2, -1, -6, 8, 0, 2, 11, -21, -16, -1, -19, 16, -4, -4, -6, -13, 5, 0, 8, -9, 18, - -22, -27, -5, -5, -2, -4, 12, -4, -5, -29, -17, -2, -14, -8, -24, -1, 15, -18, -12, -19, - -10, -21, -4, -8, 27, 4, -13, -6, -12, -12, -18, -15, -13, 0, -4, -14, -17, -31, -25, -5, - -10, -7, -11, -4, -8, -2, -9, -15, -2, -12, 0, 2, 5, -10, 1, -8, -1, 1, -3, 2, -2, 3, -2, - -2, -11, 1, 17, -3, 10, 9, 8, 5, 8, 10, 17, 14, 14, 17, 10, 2, 14, 36, 12, 28, 30, 12, 4, - 12, 28, 16, 24, 22, 10, 15, 7, 29, 14, + -17, -12, -2, -1, -5, 6, 0, 2, 18, -20, -15, -5, -19, 20, 0, -4, -11, -7, 1, -1, 0, -7, 17, + -20, -23, -3, 0, 1, 2, 10, -3, -2, -25, -18, 1, -10, -7, -19, 0, 15, -17, -13, -18, -9, + -18, -4, -4, 30, 3, -14, -6, -13, -10, -15, -10, -10, 0, -6, -14, -19, -30, -25, -2, -7, + -9, -13, -6, -8, -2, -9, -14, 2, -12, -2, 1, 4, -10, 1, -7, -2, -1, -4, 0, -3, 2, -1, 0, + -7, 0, 14, -4, 8, 8, 8, 7, 11, 7, 14, 13, 12, 16, 9, 3, 14, 34, 10, 25, 27, 10, 3, 15, 29, + 12, 20, 19, 8, 13, 6, 30, 13, ], ); -const BISHOP_SQUARE_RELATIVE_TO_ENEMY_KING_MG_EG: ( - [Score; SQUARE_RELATIVE_TO_KING_LEN], - [Score; SQUARE_RELATIVE_TO_KING_LEN], +const BISHOP_RELATIVE_TO_ENEMY_KING_MG_EG: ( + [Score; PIECE_RELATIVE_TO_KING_LEN], + [Score; PIECE_RELATIVE_TO_KING_LEN], ) = ( [ - 1, 1, 1, 1, 2, 0, 0, 0, 3, 3, 7, 1, 2, 2, 0, 0, 8, 7, 2, -1, 4, -1, 3, 2, 12, 20, 0, 12, - -4, 3, -1, 2, 27, 13, 23, -8, 11, 0, 1, 5, 16, 45, -6, 5, -23, 18, 3, 5, 15, -15, 48, 25, - -26, 11, 58, -8, 0, -34, -39, 20, -2, 39, 0, 24, -45, -180, -9, -13, 6, 20, 32, 32, -39, - -25, -97, -18, -18, 14, 6, -3, -31, -28, -16, -22, -11, -18, -2, -1, -14, -8, -26, -15, - -32, -14, -32, 26, -7, -23, -13, -25, -20, -34, -18, -27, -23, -20, -25, -24, -35, -28, - -41, -16, -20, -36, -31, -41, -37, -30, -51, -25, + 1, 1, 0, 2, 2, 0, 0, 0, 3, 3, 7, 1, 2, 2, -1, 0, 7, 4, 1, -1, 3, -2, 3, 2, 12, 19, 0, 10, + -5, 2, -2, 2, 26, 13, 26, -7, 9, 0, -1, 6, 17, 41, -7, 11, -23, 20, 5, 6, 13, -15, 46, 25, + -22, 9, 59, -8, 0, -32, -37, 19, -2, 42, 1, 26, -43, -178, -8, -12, 5, 19, 29, 29, -35, + -22, -94, -16, -17, 12, 5, -5, -30, -26, -15, -22, -11, -18, -3, -4, -13, -7, -24, -14, + -32, -13, -31, 26, -7, -22, -12, -25, -19, -33, -17, -27, -23, -20, -24, -23, -34, -27, + -39, -16, -19, -35, -30, -39, -36, -29, -49, -25, ], [ - 11, 3, 1, 8, 12, 1, -1, 0, 27, 13, 7, 7, 0, 10, 0, 1, 25, 4, 15, 4, 4, -7, -8, 9, 5, 34, 2, - 30, -24, 9, -19, 3, 25, -2, 16, -2, 14, 11, 15, 23, 3, 22, -32, 18, 3, 11, 9, 2, 24, -25, - 14, -7, 14, 0, 3, 7, 0, 38, 15, 11, -13, 3, -1, -2, 41, -11, 19, -8, 4, -11, -16, -15, 5, - 12, -38, 8, -10, 2, -19, 8, 16, -4, 5, -50, -1, -16, -11, -4, -17, 3, -10, 1, -25, 2, -11, - -12, 2, -11, -2, -7, -11, -26, -14, -14, -3, 3, -16, 0, -5, 4, -19, 15, -8, -13, 1, -12, 8, - -13, 12, -21, + 10, 0, 0, 8, 11, 0, -1, 0, 22, 12, 4, -1, -4, 12, -5, 1, 25, -3, 11, 1, -2, -15, -8, 11, 4, + 29, -5, 27, -26, 3, -23, 9, 23, -6, 13, -9, 8, 4, 7, 26, 2, 21, -34, 17, 3, 9, 12, -2, 24, + -29, 13, -9, 14, 1, 6, 3, 0, 37, 14, 12, -11, 4, 3, 4, 40, -9, 18, -8, 6, -7, -9, -9, 4, + 10, -36, 8, -8, 7, -13, 16, 17, -3, 6, -48, 2, -12, -6, 0, -16, 5, -8, 2, -21, 4, -9, -12, + 4, -10, 0, -6, -10, -23, -12, -12, -3, 4, -15, 2, -4, 6, -20, 17, -7, -13, 2, -12, 8, -10, + 15, -20, ], ); -const ROOK_SQUARE_RELATIVE_TO_FRIENDLY_KING_MG_EG: ( - [Score; SQUARE_RELATIVE_TO_KING_LEN], - [Score; SQUARE_RELATIVE_TO_KING_LEN], +const ROOK_RELATIVE_TO_FRIENDLY_KING_MG_EG: ( + [Score; PIECE_RELATIVE_TO_KING_LEN], + [Score; PIECE_RELATIVE_TO_KING_LEN], ) = ( [ - -3, -5, -13, 5, 2, -5, -1, -1, -4, -12, -7, -11, -6, 0, -3, -3, -11, -1, -13, -12, -25, -2, - -6, 0, -15, -16, -47, -45, -2, -45, -30, -22, -17, 8, -22, -13, -29, -16, -56, -8, -19, -7, - -10, 0, -24, 5, -3, -26, -11, 0, -3, -15, -12, -20, -16, -15, 0, 19, 33, 41, 34, 37, 28, - 35, 88, 35, 30, 32, 52, 25, 40, -22, 50, 37, 34, 23, 38, 20, 14, -57, 28, 18, 36, 24, 30, - 24, 17, -7, 21, 31, 24, 57, 25, 25, 23, -24, 32, 30, 34, 15, 33, 22, 5, -15, 43, 21, -32, - -38, -20, 1, -18, -13, -8, 43, 4, 32, 23, 12, 38, -3, + -3, -4, -11, 5, 2, -4, -2, -2, -4, -11, -7, -11, -4, -1, -3, -3, -9, -4, -15, -10, -24, -3, + -4, 1, -17, -17, -44, -43, -1, -41, -28, -21, -19, 1, -24, -14, -31, -15, -57, -9, -18, + -11, -11, 0, -27, 2, -8, -28, -13, -1, -4, -17, -13, -22, -19, -15, 0, 19, 32, 41, 33, 36, + 28, 36, 91, 35, 29, 30, 50, 24, 38, -24, 54, 36, 33, 22, 36, 17, 13, -57, 27, 18, 35, 22, + 28, 23, 16, -6, 20, 29, 23, 56, 25, 25, 21, -19, 30, 30, 35, 14, 33, 25, 4, -16, 42, 23, + -30, -37, -19, 2, -18, -12, -10, 41, 5, 28, 23, 12, 40, -5, ], [ - -10, -8, -45, -10, -6, -27, -13, -6, -25, -53, -50, -36, -3, -15, -7, -18, -48, -48, -38, - -47, -45, -23, -8, -8, -53, -35, -25, -45, -51, -39, -24, -11, -44, -37, -20, -37, -10, - -15, -8, -3, -29, -22, -21, -28, -21, -22, -13, -1, -25, -25, -16, -15, -12, -5, -8, 1, 0, - -10, -20, -26, -16, -15, -13, -15, -27, -13, 0, -6, -13, -4, -10, 7, 0, 2, 8, 9, 3, 5, 6, - 21, 0, 18, 12, 12, 13, 17, 19, 22, 13, 24, 26, 14, 19, 22, 18, 29, 22, 30, 30, 34, 34, 30, - 36, 37, 34, 39, 63, 63, 58, 53, 52, 46, 51, 50, 64, 55, 52, 53, 48, 6, + -10, -3, -33, -6, -5, -19, -13, -10, -20, -43, -46, -28, 8, -11, -1, -19, -41, -37, -38, + -42, -41, -17, 2, -5, -47, -30, -23, -39, -46, -33, -19, -8, -41, -32, -15, -32, -6, -8, + -4, 2, -28, -19, -20, -26, -16, -17, -6, 3, -24, -25, -15, -13, -11, -2, -4, 0, 0, -11, + -20, -26, -15, -14, -12, -14, -31, -16, -2, -6, -12, -3, -9, 10, -6, -2, 5, 7, 2, 5, 7, 23, + -4, 14, 8, 10, 12, 17, 20, 25, 8, 20, 21, 11, 16, 19, 17, 27, 16, 23, 22, 29, 29, 25, 34, + 37, 28, 31, 55, 55, 50, 47, 48, 44, 43, 42, 56, 49, 45, 47, 41, 3, ], ); -const ROOK_SQUARE_RELATIVE_TO_ENEMY_KING_MG_EG: ( - [Score; SQUARE_RELATIVE_TO_KING_LEN], - [Score; SQUARE_RELATIVE_TO_KING_LEN], +const ROOK_RELATIVE_TO_ENEMY_KING_MG_EG: ( + [Score; PIECE_RELATIVE_TO_KING_LEN], + [Score; PIECE_RELATIVE_TO_KING_LEN], ) = ( [ - 7, 22, 11, 5, 4, 0, -1, 1, 13, 20, 22, 17, 19, 11, 10, 3, 21, 5, -7, 19, 14, 18, 12, 1, 1, - 4, 12, 4, 28, 18, 11, 0, -7, 3, 16, 24, 22, 6, 17, 10, -31, -4, 42, 11, 18, 41, 44, 22, - -62, -73, -10, -14, -11, 1, 6, 13, 0, -177, -64, -68, -43, -25, -8, 19, -194, -81, -22, - -24, -5, 22, 21, 29, -59, -33, -16, -11, 25, 17, -3, 16, -40, -18, -14, -6, -1, 7, 11, 52, - -19, -25, -8, -10, 2, 11, 0, 35, -27, -15, -4, -5, 13, 3, 14, 14, -15, -25, -15, -5, 7, 4, - -3, 21, -38, -40, -35, -32, -26, -31, -26, -6, + 5, 19, 9, 5, 4, -1, -1, 0, 9, 19, 20, 15, 18, 8, 10, 2, 18, 6, -8, 18, 12, 17, 11, 1, 1, 4, + 14, 4, 27, 18, 9, 1, -6, 7, 12, 25, 23, 6, 16, 10, -30, -2, 45, 10, 18, 35, 49, 24, -62, + -70, -9, -16, -11, 0, 9, 11, 0, -176, -62, -68, -42, -23, -7, 18, -188, -76, -21, -25, -4, + 20, 21, 28, -56, -29, -14, -9, 25, 19, 0, 13, -35, -16, -11, -3, 1, 8, 14, 51, -18, -24, + -6, -10, 3, 13, 2, 33, -22, -15, -3, -5, 12, 2, 13, 15, -15, -24, -15, -5, 8, 4, -4, 22, + -36, -38, -33, -31, -24, -30, -24, -3, ], [ - 36, 72, 37, 24, 19, 0, -1, 2, 59, 98, 75, 62, 58, 50, 40, 10, 69, 82, 67, 74, 89, 77, 50, - 15, 54, 63, 57, 64, 64, 64, 53, 22, 27, 45, 45, 44, 47, 46, 31, 32, 19, 39, 29, 31, 30, 27, - 33, 23, -69, 66, 32, 31, 32, 30, 33, 25, 0, -32, 15, 1, 1, 1, 7, -2, -22, 39, -2, -9, -9, - -18, -19, -10, -17, -3, -13, -21, -33, -32, -25, -22, -23, -18, -29, -30, -37, -34, -47, - -37, -29, -26, -40, -43, -43, -52, -48, -53, -26, -39, -47, -51, -59, -59, -68, -53, -48, - -44, -57, -63, -71, -67, -72, -89, -50, -47, -56, -62, -63, -63, -75, -70, + 25, 65, 29, 20, 19, -2, -2, 2, 41, 86, 65, 54, 53, 39, 35, 9, 60, 74, 64, 65, 79, 69, 42, + 16, 44, 57, 52, 56, 58, 56, 47, 23, 21, 40, 41, 40, 42, 44, 27, 29, 14, 35, 25, 28, 29, 27, + 31, 24, -67, 65, 30, 30, 31, 30, 32, 28, 0, -34, 13, 0, 1, 2, 8, 1, -23, 36, -2, -7, -7, + -15, -16, -7, -19, -3, -12, -20, -31, -29, -22, -17, -24, -15, -26, -27, -31, -29, -41, + -30, -25, -22, -35, -36, -38, -47, -42, -45, -25, -34, -41, -46, -52, -52, -61, -48, -43, + -39, -51, -58, -66, -61, -65, -86, -47, -42, -51, -57, -58, -57, -70, -69, ], ); -const QUEEN_SQUARE_RELATIVE_TO_FRIENDLY_KING_MG_EG: ( - [Score; SQUARE_RELATIVE_TO_KING_LEN], - [Score; SQUARE_RELATIVE_TO_KING_LEN], +const QUEEN_RELATIVE_TO_FRIENDLY_KING_MG_EG: ( + [Score; PIECE_RELATIVE_TO_KING_LEN], + [Score; PIECE_RELATIVE_TO_KING_LEN], ) = ( [ - 4, -4, 2, 2, -2, 0, -3, 2, 3, 0, 0, 9, 5, -3, -2, 4, -1, -2, 7, 6, -10, 1, -4, 0, 0, -23, - 2, -10, -5, 0, 7, -2, -5, 1, 5, -11, -16, -7, -7, 0, -3, -17, 39, -19, -11, -27, 8, 0, -3, - -6, 9, 25, 38, 1, -10, -26, 0, 34, 20, 34, 22, 28, 8, 4, 53, 52, 45, 35, 29, 34, 43, 9, 57, - 49, 53, 41, 37, 35, 40, 36, 47, 43, 47, 31, 57, 63, 53, 4, 29, 39, 32, 46, 44, 59, 47, 17, - 7, 37, 24, 31, 46, 12, 39, 20, 66, 48, 18, 38, 52, 59, 65, 16, 40, 60, 35, -27, 16, 43, - 103, 4, + 4, -4, 2, 3, -1, 0, -4, 1, 2, 0, 1, 9, 4, -4, -3, 4, -2, -1, 6, 5, -11, 0, -4, 1, -2, -22, + -1, -10, -6, -1, 5, -1, -8, 0, 3, -13, -16, -8, -8, 1, -6, -20, 32, -19, -10, -24, 8, 1, + -2, -7, 6, 23, 35, -1, -10, -26, 0, 33, 19, 33, 22, 28, 7, 4, 52, 51, 44, 35, 29, 33, 42, + 9, 56, 48, 52, 40, 36, 35, 40, 40, 47, 43, 46, 31, 56, 62, 52, 6, 28, 39, 31, 45, 45, 58, + 44, 21, 5, 37, 24, 32, 46, 14, 38, 25, 64, 47, 17, 36, 51, 57, 62, 15, 41, 60, 35, -24, 16, + 43, 101, 6, ], [ - 8, -8, 5, 3, -3, 0, -4, 4, 7, -1, -3, 15, 5, -6, -6, 5, 3, -5, 17, 11, -18, 5, -9, 0, 3, - -29, 9, -8, 2, -1, 7, -4, -10, 8, 11, -20, -7, 0, -14, -1, 5, 34, -32, 17, 17, -1, 1, -17, - -2, 9, 9, -4, -25, 11, -3, -1, 0, -4, 18, 9, 11, 1, 31, -24, -3, 11, 1, 18, 28, 21, -10, - -20, 5, 15, -2, 18, 8, 17, -11, 1, -10, 24, 17, 21, -9, -8, -3, 39, 12, 21, 27, 29, 25, - -10, 16, 22, 39, 42, 68, 31, 13, 46, 40, 3, 29, 33, 57, 56, 36, 30, 51, 40, 36, 28, 28, 79, - 44, 26, 42, 9, + 8, -8, 4, 3, -1, 0, -4, 2, 5, -1, -2, 16, 5, -7, -6, 5, 1, -4, 15, 10, -20, 4, -10, 0, 2, + -26, 3, -9, 1, -2, 6, -3, -14, 8, 8, -21, -9, -1, -14, 0, 0, 31, -30, 14, 18, 2, 2, -15, + -3, 8, 8, -7, -23, 13, -1, 3, 0, -7, 16, 7, 10, 1, 32, -20, -4, 9, -1, 16, 26, 23, -7, -15, + 2, 14, -4, 17, 9, 17, -9, 7, -12, 22, 17, 20, -8, -5, 5, 44, 12, 20, 27, 28, 24, -7, 22, + 27, 41, 40, 68, 29, 14, 46, 41, 5, 30, 30, 56, 57, 35, 29, 55, 41, 37, 27, 27, 78, 41, 25, + 43, 8, ], ); -const QUEEN_SQUARE_RELATIVE_TO_ENEMY_KING_MG_EG: ( - [Score; SQUARE_RELATIVE_TO_KING_LEN], - [Score; SQUARE_RELATIVE_TO_KING_LEN], +const QUEEN_RELATIVE_TO_ENEMY_KING_MG_EG: ( + [Score; PIECE_RELATIVE_TO_KING_LEN], + [Score; PIECE_RELATIVE_TO_KING_LEN], ) = ( [ - 2, 22, 4, 10, 27, 6, 13, 5, 6, 21, 22, 17, 20, 26, 8, 6, 3, 12, 24, 1, 27, 5, 26, 4, -11, - 33, -2, 19, -2, 23, 19, 10, -26, -41, -7, -35, 31, 5, 15, 6, -44, -27, -57, -38, -2, -5, 9, - -21, -29, -40, -12, -60, 8, 24, 43, 46, 0, -142, -141, -41, -13, 19, 68, 30, -415, -375, - -61, -24, -4, 35, 46, 76, -106, -81, -114, -52, -16, 27, 34, 35, -85, -57, -57, -44, -35, - -37, 10, -5, -57, -43, -43, -35, -19, -13, -4, 7, -36, -37, -23, -38, -27, -26, -23, -19, - -41, -32, -25, -34, -25, -10, -34, -13, -46, -30, -34, -30, -34, -38, -17, -2, + 3, 22, 4, 10, 26, 8, 12, 6, 6, 21, 24, 17, 17, 25, 7, 7, 1, 8, 22, 0, 25, 2, 26, 4, -16, + 31, -4, 17, -3, 19, 16, 8, -27, -39, -9, -35, 29, 1, 14, 6, -45, -26, -58, -40, -4, -6, 7, + -21, -29, -41, -11, -56, 9, 22, 43, 46, 0, -143, -134, -36, -11, 19, 67, 26, -415, -369, + -58, -23, -1, 34, 43, 72, -102, -78, -109, -49, -13, 27, 32, 32, -81, -54, -54, -41, -32, + -35, 12, -5, -55, -41, -42, -34, -18, -11, -3, 9, -35, -35, -21, -36, -25, -23, -22, -15, + -38, -29, -23, -32, -22, -8, -31, -11, -44, -28, -32, -27, -31, -35, -14, -1, ], [ - 4, 29, 8, 18, 40, 15, 23, 2, 10, 44, 30, 41, 42, 33, 16, 9, 23, 34, 34, 17, 50, 6, 36, 6, - 1, 48, 6, 48, 9, 59, 28, 16, -25, 13, 15, -28, 44, 5, 24, 14, -64, -2, -60, 4, -2, -1, 16, - -24, -37, -55, -13, 20, 9, 0, 29, 39, 0, -134, -66, -48, -49, -49, -49, 1, -202, -145, -20, - -50, -18, -46, -12, -1, -92, -18, -105, -7, -46, -51, -59, -10, -42, -39, -23, -53, -10, - -34, -53, -6, -30, -17, -25, -35, -55, -23, -58, -24, -4, -20, -46, -16, -38, -2, 13, -32, - 2, 1, -25, -4, -29, -30, 2, 8, 42, 30, -5, -14, 6, -5, 5, 9, + 5, 29, 10, 18, 39, 18, 21, 3, 11, 43, 32, 39, 38, 33, 15, 9, 18, 31, 31, 13, 48, 0, 36, 6, + -7, 43, 1, 42, 8, 52, 26, 13, -27, 12, 13, -28, 39, 2, 22, 15, -66, -2, -64, 2, -2, -3, 15, + -24, -37, -56, -14, 17, 9, -1, 27, 42, 0, -135, -69, -50, -50, -47, -48, 4, -199, -144, + -21, -47, -18, -43, -5, 5, -90, -16, -104, -8, -45, -47, -51, -7, -40, -38, -22, -52, -10, + -30, -50, -4, -27, -16, -23, -34, -50, -21, -53, -25, -3, -19, -45, -16, -35, 0, 14, -33, + 2, 3, -24, -2, -29, -30, 3, 9, 44, 32, -5, -13, 6, -5, 5, 10, + ], +); + +const PASSED_PAWN_RELATIVE_TO_FRIENDLY_KING_MG_EG: ( + [Score; PASSED_PAWNS_RELATIVE_TO_KING_LEN], + [Score; PASSED_PAWNS_RELATIVE_TO_KING_LEN], +) = ( + [ + -4, -5, 3, -2, -3, 0, 0, 0, 7, 2, 6, 0, 5, -1, -1, 1, 8, -4, 9, -5, 12, -5, 3, -5, 12, 22, + 4, 14, 19, 12, -14, -15, 70, -19, -15, 16, 10, -7, -23, -10, 37, 16, -3, -20, -17, -15, + -19, -38, 0, -17, -7, -45, -30, -56, -24, -35, -15, -27, -6, -29, -20, -7, -10, -37, -5, + -14, -13, -15, -6, 11, 14, -13, 5, -4, -6, 12, 2, 23, 30, -11, -3, -31, -26, -1, -3, 15, + 52, 22, -34, -71, -15, 6, 23, 31, 94, 15, -6, -16, -5, -11, 1, 8, 42, -19, + ], + [ + 2, 8, 10, -10, 5, 2, 2, -2, 24, 22, 13, 15, 5, 0, 4, -3, 56, 27, 32, 38, 38, 14, 17, -5, + 60, 48, 54, 24, 8, 16, 11, 11, 47, 61, 46, 18, 20, 6, -2, -15, 45, 57, 41, 28, 21, 6, 10, + -16, 0, 56, 37, 26, 19, 24, 9, 1, 52, 48, 33, 25, 16, 3, 4, -2, 29, 29, 21, 16, 7, 0, -4, + -7, 13, 17, 13, 1, 11, -1, -4, -9, 1, 28, 19, 11, 8, 1, 0, -7, -26, 24, 10, -7, -7, 4, -9, + -13, -15, -10, -17, -2, -6, -14, -11, 26, + ], +); +const PASSED_PAWN_RELATIVE_TO_ENEMY_KING_MG_EG: ( + [Score; PASSED_PAWNS_RELATIVE_TO_KING_LEN], + [Score; PASSED_PAWNS_RELATIVE_TO_KING_LEN], +) = ( + [ + -4, 0, 3, -3, -7, 0, -3, -2, -2, 2, 4, 3, -1, 10, -4, -1, 4, 27, 24, 22, -2, 10, 10, 10, + 15, 53, 38, 39, 40, 49, 22, 10, 60, 86, 84, 79, 68, 77, 38, 28, 10, 84, 25, 36, 59, 60, 18, + 36, 0, -71, -31, 5, 46, 47, 56, 31, 21, -17, -48, -32, 32, 30, 17, 22, -13, -64, -41, -42, + -3, -17, -12, 29, -39, -55, -45, -36, -32, -21, -30, 3, -44, -47, -42, -42, -24, -31, -32, + 21, -55, -51, -57, -22, -31, -11, -20, 30, -66, -68, -32, -22, -24, 6, -15, 21, + ], + [ + -13, -7, 2, -29, -41, -23, -24, -5, -52, -45, -38, -53, -38, -34, -52, -45, -52, -44, -49, + -33, -26, -60, -40, -21, -69, -57, -62, -61, -66, -55, -35, -22, -61, -53, -63, -76, -69, + -50, -33, -30, -4, -10, 5, -30, -48, -41, -22, -27, 0, 70, 39, -7, -22, -29, -35, -9, 70, + 73, 40, 9, -21, -32, -26, -40, 63, 55, 35, 20, -9, -13, -14, -27, 42, 38, 29, 22, 11, -7, + -11, -18, 34, 31, 23, 19, 6, 1, -7, -29, 29, 23, 23, 4, -3, -1, -9, -19, 37, 31, 12, 4, -4, + -18, -15, -2, ], ); @@ -296,138 +336,138 @@ const QUEEN_SQUARE_RELATIVE_TO_ENEMY_KING_MG_EG: ( const PST_PAWN_MG_EG: ([Score; 32], [Score; 32]) = ( [ 0, 0, 0, 0, - 117, 155, 151, 170, - 63, 88, 133, 108, - 55, 68, 66, 87, - 36, 55, 65, 77, - 55, 57, 64, 59, - 44, 76, 65, 50, + 111, 153, 152, 164, + 75, 87, 128, 102, + 60, 71, 69, 90, + 41, 60, 70, 83, + 57, 61, 68, 64, + 45, 78, 67, 53, 0, 0, 0, 0, ], [ 0, 0, 0, 0, - 311, 314, 297, 280, - 114, 122, 122, 138, - 106, 110, 117, 111, - 97, 99, 104, 105, - 81, 90, 98, 108, - 78, 80, 101, 111, + 289, 291, 276, 262, + 107, 113, 108, 124, + 97, 98, 103, 95, + 86, 86, 89, 88, + 71, 77, 85, 93, + 68, 70, 89, 97, 0, 0, 0, 0, ], ); #[rustfmt::skip] const PST_KNIGHT_MG_EG: ([Score; 32], [Score; 32]) = ( [ - 186, 278, 252, 308, - 299, 294, 398, 324, - 295, 354, 349, 403, - 333, 342, 336, 356, - 311, 319, 342, 343, - 306, 328, 328, 341, - 309, 317, 318, 321, - 264, 291, 307, 301, - ], - [ - 239, 266, 290, 292, - 270, 291, 277, 293, - 282, 285, 313, 297, - 286, 299, 318, 318, - 282, 299, 311, 318, - 277, 290, 299, 312, - 276, 287, 298, 300, - 278, 296, 299, 301, + 185, 278, 255, 307, + 300, 294, 398, 325, + 296, 353, 349, 402, + 333, 342, 336, 355, + 310, 318, 340, 342, + 304, 326, 326, 339, + 307, 316, 316, 319, + 262, 291, 305, 301, + ], + [ + 240, 266, 288, 290, + 268, 290, 275, 291, + 281, 284, 312, 297, + 285, 299, 318, 318, + 283, 300, 312, 318, + 279, 292, 301, 314, + 276, 287, 299, 300, + 278, 295, 300, 300, ], ); #[rustfmt::skip] const PST_BISHOP_MG_EG: ([Score; 32], [Score; 32]) = ( [ - 302, 312, 294, 252, - 295, 355, 337, 340, - 344, 344, 365, 339, - 329, 326, 332, 346, - 315, 327, 327, 350, - 340, 333, 346, 329, - 320, 351, 333, 323, - 332, 321, 312, 313, + 303, 309, 292, 252, + 296, 356, 337, 342, + 343, 342, 364, 338, + 328, 324, 331, 345, + 314, 326, 325, 349, + 339, 331, 344, 328, + 318, 349, 332, 321, + 331, 320, 311, 313, ], [ - 292, 289, 293, 302, - 295, 293, 294, 287, + 291, 291, 292, 301, + 293, 293, 293, 286, 298, 299, 299, 302, - 295, 299, 301, 305, - 295, 292, 303, 300, - 284, 295, 296, 305, - 295, 292, 293, 299, - 290, 303, 312, 311, + 296, 300, 301, 305, + 296, 293, 305, 301, + 285, 297, 298, 306, + 296, 294, 295, 301, + 290, 303, 311, 311, ], ); #[rustfmt::skip] const PST_ROOK_MG_EG: ([Score; 32], [Score; 32]) = ( [ - 542, 572, 563, 560, - 566, 544, 562, 553, - 538, 525, 520, 520, - 506, 503, 511, 498, - 497, 491, 487, 491, - 510, 507, 505, 516, - 475, 508, 498, 511, - 489, 483, 511, 511, - ], - [ - 515, 505, 505, 504, - 499, 511, 506, 502, - 499, 503, 503, 503, - 495, 498, 502, 503, - 488, 494, 500, 503, - 477, 482, 485, 487, - 484, 482, 496, 490, - 480, 493, 490, 495, + 540, 567, 560, 560, + 564, 539, 560, 550, + 537, 522, 519, 519, + 506, 502, 511, 499, + 497, 491, 487, 492, + 507, 505, 504, 515, + 473, 505, 496, 508, + 488, 481, 509, 508, + ], + [ + 515, 507, 506, 504, + 500, 513, 507, 504, + 499, 503, 504, 504, + 495, 499, 503, 504, + 489, 496, 501, 504, + 480, 484, 488, 490, + 485, 484, 498, 492, + 480, 494, 490, 496, ], ); #[rustfmt::skip] const PST_QUEEN_MG_EG: ([Score; 32], [Score; 32]) = ( [ - 962, 968, 968, 992, - 983, 958, 945, 883, - 982, 1014, 947, 946, - 964, 930, 935, 927, - 963, 959, 955, 949, - 975, 983, 971, 968, - 978, 1003, 1000, 994, - 1030, 997, 1012, 1010, - ], - [ - 953, 944, 959, 948, - 941, 950, 970, 996, - 921, 908, 962, 965, - 932, 958, 961, 975, - 930, 938, 937, 959, - 923, 922, 934, 924, - 947, 906, 897, 924, - 915, 914, 919, 912, + 958, 968, 965, 987, + 983, 957, 946, 883, + 980, 1010, 947, 945, + 963, 930, 935, 927, + 960, 956, 952, 946, + 972, 980, 968, 966, + 977, 1001, 997, 991, + 1027, 994, 1009, 1008, + ], + [ + 951, 941, 957, 945, + 937, 948, 965, 993, + 920, 909, 961, 963, + 930, 958, 960, 975, + 929, 941, 938, 961, + 924, 924, 937, 925, + 947, 907, 901, 927, + 917, 916, 922, 915, ], ); #[rustfmt::skip] const PST_KING_MG_EG: ([Score; 32], [Score; 32]) = ( [ - 19, 13, 32, 12, - -9, 10, 44, -1, - 5, 78, 32, 20, - -17, 9, 27, 4, - -34, 0, -16, -25, - 3, 20, -29, -58, - 43, 27, -33, -64, - 6, 24, -56, -85, - ], - [ - -50, -13, -9, -6, - -23, 0, -5, -5, - -17, -4, -3, -9, - -15, -8, -9, -11, - -11, -5, -2, 1, - -5, 2, 14, 20, - 1, 14, 30, 34, - -2, 15, 40, 41, + 15, 8, 33, 5, + -13, 3, 35, -1, + 0, 69, 23, 17, + -13, 12, 18, -7, + -37, 3, -22, -29, + 3, 22, -26, -53, + 45, 32, -20, -50, + 8, 31, -43, -68, + ], + [ + -41, -12, -10, -8, + -20, 0, -6, -8, + -15, -6, -4, -11, + -17, -9, -9, -11, + -7, -5, -2, -3, + -1, 3, 12, 15, + 6, 15, 26, 29, + 5, 17, 39, 38, ], ); @@ -448,15 +488,32 @@ const fn human_readable_to_file_rank(piece_value: Score, pst: [Score; 32]) -> [S const fn convert_square_relative_to( mg_eg: ( - [Score; SQUARE_RELATIVE_TO_KING_LEN], - [Score; SQUARE_RELATIVE_TO_KING_LEN], + [Score; PIECE_RELATIVE_TO_KING_LEN], + [Score; PIECE_RELATIVE_TO_KING_LEN], ), -) -> [ScorePair; SQUARE_RELATIVE_TO_KING_LEN] { +) -> [ScorePair; PIECE_RELATIVE_TO_KING_LEN] { let mg = mg_eg.0; let eg = mg_eg.1; - let mut scores = [ScorePair(0, 0); SQUARE_RELATIVE_TO_KING_LEN]; + let mut scores = [ScorePair(0, 0); PIECE_RELATIVE_TO_KING_LEN]; let mut idx = 0; - while idx < SQUARE_RELATIVE_TO_KING_LEN { + while idx < PIECE_RELATIVE_TO_KING_LEN { + scores[idx] = ScorePair(mg[idx], eg[idx]); + idx += 1; + } + scores +} + +const fn convert_passed_pawn_relative_to( + mg_eg: ( + [Score; PASSED_PAWNS_RELATIVE_TO_KING_LEN], + [Score; PASSED_PAWNS_RELATIVE_TO_KING_LEN], + ), +) -> [ScorePair; PASSED_PAWNS_RELATIVE_TO_KING_LEN] { + let mg = mg_eg.0; + let eg = mg_eg.1; + let mut scores = [ScorePair(0, 0); PASSED_PAWNS_RELATIVE_TO_KING_LEN]; + let mut idx = 0; + while idx < PASSED_PAWNS_RELATIVE_TO_KING_LEN { scores[idx] = ScorePair(mg[idx], eg[idx]); idx += 1; } @@ -511,26 +568,31 @@ pub const MOBILITY_QUEEN: [ScorePair; 28] = { table }; -pub const PAWN_SQUARE_RELATIVE_TO_FRIENDLY_KING: [ScorePair; SQUARE_RELATIVE_TO_KING_LEN] = - convert_square_relative_to(PAWN_SQUARE_RELATIVE_TO_FRIENDLY_KING_MG_EG); -pub const PAWN_SQUARE_RELATIVE_TO_ENEMY_KING: [ScorePair; SQUARE_RELATIVE_TO_KING_LEN] = - convert_square_relative_to(PAWN_SQUARE_RELATIVE_TO_ENEMY_KING_MG_EG); -pub const KNIGHT_SQUARE_RELATIVE_TO_FRIENDLY_KING: [ScorePair; SQUARE_RELATIVE_TO_KING_LEN] = - convert_square_relative_to(KNIGHT_SQUARE_RELATIVE_TO_FRIENDLY_KING_MG_EG); -pub const KNIGHT_SQUARE_RELATIVE_TO_ENEMY_KING: [ScorePair; SQUARE_RELATIVE_TO_KING_LEN] = - convert_square_relative_to(KNIGHT_SQUARE_RELATIVE_TO_ENEMY_KING_MG_EG); -pub const BISHOP_SQUARE_RELATIVE_TO_FRIENDLY_KING: [ScorePair; SQUARE_RELATIVE_TO_KING_LEN] = - convert_square_relative_to(BISHOP_SQUARE_RELATIVE_TO_FRIENDLY_KING_MG_EG); -pub const BISHOP_SQUARE_RELATIVE_TO_ENEMY_KING: [ScorePair; SQUARE_RELATIVE_TO_KING_LEN] = - convert_square_relative_to(BISHOP_SQUARE_RELATIVE_TO_ENEMY_KING_MG_EG); -pub const ROOK_SQUARE_RELATIVE_TO_FRIENDLY_KING: [ScorePair; SQUARE_RELATIVE_TO_KING_LEN] = - convert_square_relative_to(ROOK_SQUARE_RELATIVE_TO_FRIENDLY_KING_MG_EG); -pub const ROOK_SQUARE_RELATIVE_TO_ENEMY_KING: [ScorePair; SQUARE_RELATIVE_TO_KING_LEN] = - convert_square_relative_to(ROOK_SQUARE_RELATIVE_TO_ENEMY_KING_MG_EG); -pub const QUEEN_SQUARE_RELATIVE_TO_FRIENDLY_KING: [ScorePair; SQUARE_RELATIVE_TO_KING_LEN] = - convert_square_relative_to(QUEEN_SQUARE_RELATIVE_TO_FRIENDLY_KING_MG_EG); -pub const QUEEN_SQUARE_RELATIVE_TO_ENEMY_KING: [ScorePair; SQUARE_RELATIVE_TO_KING_LEN] = - convert_square_relative_to(QUEEN_SQUARE_RELATIVE_TO_ENEMY_KING_MG_EG); +pub const PAWN_RELATIVE_TO_FRIENDLY_KING: [ScorePair; PIECE_RELATIVE_TO_KING_LEN] = + convert_square_relative_to(PAWN_RELATIVE_TO_FRIENDLY_KING_MG_EG); +pub const PAWN_RELATIVE_TO_ENEMY_KING: [ScorePair; PIECE_RELATIVE_TO_KING_LEN] = + convert_square_relative_to(PAWN_RELATIVE_TO_ENEMY_KING_MG_EG); +pub const KNIGHT_RELATIVE_TO_FRIENDLY_KING: [ScorePair; PIECE_RELATIVE_TO_KING_LEN] = + convert_square_relative_to(KNIGHT_RELATIVE_TO_FRIENDLY_KING_MG_EG); +pub const KNIGHT_RELATIVE_TO_ENEMY_KING: [ScorePair; PIECE_RELATIVE_TO_KING_LEN] = + convert_square_relative_to(KNIGHT_RELATIVE_TO_ENEMY_KING_MG_EG); +pub const BISHOP_RELATIVE_TO_FRIENDLY_KING: [ScorePair; PIECE_RELATIVE_TO_KING_LEN] = + convert_square_relative_to(BISHOP_RELATIVE_TO_FRIENDLY_KING_MG_EG); +pub const BISHOP_RELATIVE_TO_ENEMY_KING: [ScorePair; PIECE_RELATIVE_TO_KING_LEN] = + convert_square_relative_to(BISHOP_RELATIVE_TO_ENEMY_KING_MG_EG); +pub const ROOK_RELATIVE_TO_FRIENDLY_KING: [ScorePair; PIECE_RELATIVE_TO_KING_LEN] = + convert_square_relative_to(ROOK_RELATIVE_TO_FRIENDLY_KING_MG_EG); +pub const ROOK_RELATIVE_TO_ENEMY_KING: [ScorePair; PIECE_RELATIVE_TO_KING_LEN] = + convert_square_relative_to(ROOK_RELATIVE_TO_ENEMY_KING_MG_EG); +pub const QUEEN_RELATIVE_TO_FRIENDLY_KING: [ScorePair; PIECE_RELATIVE_TO_KING_LEN] = + convert_square_relative_to(QUEEN_RELATIVE_TO_FRIENDLY_KING_MG_EG); +pub const QUEEN_RELATIVE_TO_ENEMY_KING: [ScorePair; PIECE_RELATIVE_TO_KING_LEN] = + convert_square_relative_to(QUEEN_RELATIVE_TO_ENEMY_KING_MG_EG); + +pub const PASSED_PAWN_RELATIVE_TO_FRIENDLY_KING: [ScorePair; PASSED_PAWNS_RELATIVE_TO_KING_LEN] = + convert_passed_pawn_relative_to(PASSED_PAWN_RELATIVE_TO_FRIENDLY_KING_MG_EG); +pub const PASSED_PAWN_RELATIVE_TO_ENEMY_KING: [ScorePair; PASSED_PAWNS_RELATIVE_TO_KING_LEN] = + convert_passed_pawn_relative_to(PASSED_PAWN_RELATIVE_TO_ENEMY_KING_MG_EG); pub const PASSED_PAWN: PieceSquareTable = { let mg = human_readable_to_file_rank(0, PASSED_PAWN_MG_EG.0); diff --git a/eval/src/piece_table_refs.rs b/eval/src/piece_table_refs.rs index 7977451..ee057a0 100644 --- a/eval/src/piece_table_refs.rs +++ b/eval/src/piece_table_refs.rs @@ -5,8 +5,8 @@ use crate::{params, score_pair::ScorePair}; #[derive(Debug, Clone, Copy)] pub struct PieceTableRefs<'a> { pub pst: &'a [ScorePair], - pub square_relative_to_friendly_king: &'a [ScorePair], - pub square_relative_to_enemy_king: &'a [ScorePair], + pub piece_relative_to_friendly_king: &'a [ScorePair], + pub piece_relative_to_enemy_king: &'a [ScorePair], } pub const PIECE_TABLE_REFS: [PieceTableRefs; 6] = { @@ -20,8 +20,8 @@ pub const PIECE_TABLE_REFS: [PieceTableRefs; 6] = { ]; let mut piece_tables = [PieceTableRefs { pst: &[], - square_relative_to_friendly_king: &[], - square_relative_to_enemy_king: &[], + piece_relative_to_friendly_king: &[], + piece_relative_to_enemy_king: &[], }; 6]; let mut i = 0; while i < piece_types.len() { @@ -29,33 +29,33 @@ pub const PIECE_TABLE_REFS: [PieceTableRefs; 6] = { let tables = match pt { piece::Type::Pawn => PieceTableRefs { pst: ¶ms::PST_PAWN, - square_relative_to_friendly_king: ¶ms::PAWN_SQUARE_RELATIVE_TO_FRIENDLY_KING, - square_relative_to_enemy_king: ¶ms::PAWN_SQUARE_RELATIVE_TO_ENEMY_KING, + piece_relative_to_friendly_king: ¶ms::PAWN_RELATIVE_TO_FRIENDLY_KING, + piece_relative_to_enemy_king: ¶ms::PAWN_RELATIVE_TO_ENEMY_KING, }, piece::Type::Knight => PieceTableRefs { pst: ¶ms::PST_KNIGHT, - square_relative_to_friendly_king: ¶ms::KNIGHT_SQUARE_RELATIVE_TO_FRIENDLY_KING, - square_relative_to_enemy_king: ¶ms::KNIGHT_SQUARE_RELATIVE_TO_ENEMY_KING, + piece_relative_to_friendly_king: ¶ms::KNIGHT_RELATIVE_TO_FRIENDLY_KING, + piece_relative_to_enemy_king: ¶ms::KNIGHT_RELATIVE_TO_ENEMY_KING, }, piece::Type::Bishop => PieceTableRefs { pst: ¶ms::PST_BISHOP, - square_relative_to_friendly_king: ¶ms::BISHOP_SQUARE_RELATIVE_TO_FRIENDLY_KING, - square_relative_to_enemy_king: ¶ms::BISHOP_SQUARE_RELATIVE_TO_ENEMY_KING, + piece_relative_to_friendly_king: ¶ms::BISHOP_RELATIVE_TO_FRIENDLY_KING, + piece_relative_to_enemy_king: ¶ms::BISHOP_RELATIVE_TO_ENEMY_KING, }, piece::Type::Rook => PieceTableRefs { pst: ¶ms::PST_ROOK, - square_relative_to_friendly_king: ¶ms::ROOK_SQUARE_RELATIVE_TO_FRIENDLY_KING, - square_relative_to_enemy_king: ¶ms::ROOK_SQUARE_RELATIVE_TO_ENEMY_KING, + piece_relative_to_friendly_king: ¶ms::ROOK_RELATIVE_TO_FRIENDLY_KING, + piece_relative_to_enemy_king: ¶ms::ROOK_RELATIVE_TO_ENEMY_KING, }, piece::Type::Queen => PieceTableRefs { pst: ¶ms::PST_QUEEN, - square_relative_to_friendly_king: ¶ms::QUEEN_SQUARE_RELATIVE_TO_FRIENDLY_KING, - square_relative_to_enemy_king: ¶ms::QUEEN_SQUARE_RELATIVE_TO_ENEMY_KING, + piece_relative_to_friendly_king: ¶ms::QUEEN_RELATIVE_TO_FRIENDLY_KING, + piece_relative_to_enemy_king: ¶ms::QUEEN_RELATIVE_TO_ENEMY_KING, }, piece::Type::King => PieceTableRefs { pst: ¶ms::PST_KING, - square_relative_to_friendly_king: &[], - square_relative_to_enemy_king: &[], + piece_relative_to_friendly_king: &[], + piece_relative_to_enemy_king: &[], }, }; piece_tables[pt.idx()] = tables; diff --git a/search/tests/search.rs b/search/tests/search.rs index 1361242..4fb6b89 100644 --- a/search/tests/search.rs +++ b/search/tests/search.rs @@ -567,13 +567,13 @@ fn mate_in_x_various_depths(search_algo: impl Search + Send + 'static) { // Mate in 4 ( "7Q/6P1/3k4/8/8/P4PK1/1P6/8 b - - 0 119", - 8, + 9, ScoreVariant::Mate(Side::White, 4), ), // Mate in 5 ( "8/2p5/4k3/8/P2B4/r7/6rP/3K4 b - - 6 51", - 16, + 17, ScoreVariant::Mate(Side::Black, -5), ), // Mate in 2 diff --git a/tuner/src/eval_params.rs b/tuner/src/eval_params.rs index af92e4c..c93a26c 100644 --- a/tuner/src/eval_params.rs +++ b/tuner/src/eval_params.rs @@ -2,7 +2,8 @@ use std::fmt::Display; use eval::{ params::{ - BISHOP_MOB_LEN, KNIGHT_MOB_LEN, QUEEN_MOB_LEN, ROOK_MOB_LEN, SQUARE_RELATIVE_TO_KING_LEN, + BISHOP_MOB_LEN, KNIGHT_MOB_LEN, PASSED_PAWNS_RELATIVE_TO_KING_LEN, + PIECE_RELATIVE_TO_KING_LEN, QUEEN_MOB_LEN, ROOK_MOB_LEN, }, score_pair::ScorePair, Score, @@ -28,16 +29,18 @@ pub struct EvalParams { rook_mobility: [ScorePair; ROOK_MOB_LEN], queen_mobility: [ScorePair; QUEEN_MOB_LEN], bishop_pair: ScorePair, - pawn_square_relative_to_friendly_king: [ScorePair; SQUARE_RELATIVE_TO_KING_LEN], - pawn_square_relative_to_enemy_king: [ScorePair; SQUARE_RELATIVE_TO_KING_LEN], - knight_square_relative_to_friendly_king: [ScorePair; SQUARE_RELATIVE_TO_KING_LEN], - knight_square_relative_to_enemy_king: [ScorePair; SQUARE_RELATIVE_TO_KING_LEN], - bishop_square_relative_to_friendly_king: [ScorePair; SQUARE_RELATIVE_TO_KING_LEN], - bishop_square_relative_to_enemy_king: [ScorePair; SQUARE_RELATIVE_TO_KING_LEN], - rook_square_relative_to_friendly_king: [ScorePair; SQUARE_RELATIVE_TO_KING_LEN], - rook_square_relative_to_enemy_king: [ScorePair; SQUARE_RELATIVE_TO_KING_LEN], - queen_square_relative_to_friendly_king: [ScorePair; SQUARE_RELATIVE_TO_KING_LEN], - queen_square_relative_to_enemy_king: [ScorePair; SQUARE_RELATIVE_TO_KING_LEN], + pawn_relative_to_friendly_king: [ScorePair; PIECE_RELATIVE_TO_KING_LEN], + pawn_relative_to_enemy_king: [ScorePair; PIECE_RELATIVE_TO_KING_LEN], + knight_relative_to_friendly_king: [ScorePair; PIECE_RELATIVE_TO_KING_LEN], + knight_relative_to_enemy_king: [ScorePair; PIECE_RELATIVE_TO_KING_LEN], + bishop_relative_to_friendly_king: [ScorePair; PIECE_RELATIVE_TO_KING_LEN], + bishop_relative_to_enemy_king: [ScorePair; PIECE_RELATIVE_TO_KING_LEN], + rook_relative_to_friendly_king: [ScorePair; PIECE_RELATIVE_TO_KING_LEN], + rook_relative_to_enemy_king: [ScorePair; PIECE_RELATIVE_TO_KING_LEN], + queen_relative_to_friendly_king: [ScorePair; PIECE_RELATIVE_TO_KING_LEN], + queen_relative_to_enemy_king: [ScorePair; PIECE_RELATIVE_TO_KING_LEN], + passed_pawn_relative_to_friendly_king: [ScorePair; PASSED_PAWNS_RELATIVE_TO_KING_LEN], + passed_pawn_relative_to_enemy_king: [ScorePair; PASSED_PAWNS_RELATIVE_TO_KING_LEN], } impl Default for EvalParams { @@ -59,16 +62,20 @@ impl Default for EvalParams { rook_mobility: [ScorePair(0, 0); ROOK_MOB_LEN], queen_mobility: [ScorePair(0, 0); QUEEN_MOB_LEN], bishop_pair: ScorePair(0, 0), - pawn_square_relative_to_friendly_king: [ScorePair(0, 0); SQUARE_RELATIVE_TO_KING_LEN], - pawn_square_relative_to_enemy_king: [ScorePair(0, 0); SQUARE_RELATIVE_TO_KING_LEN], - knight_square_relative_to_friendly_king: [ScorePair(0, 0); SQUARE_RELATIVE_TO_KING_LEN], - knight_square_relative_to_enemy_king: [ScorePair(0, 0); SQUARE_RELATIVE_TO_KING_LEN], - bishop_square_relative_to_friendly_king: [ScorePair(0, 0); SQUARE_RELATIVE_TO_KING_LEN], - bishop_square_relative_to_enemy_king: [ScorePair(0, 0); SQUARE_RELATIVE_TO_KING_LEN], - rook_square_relative_to_friendly_king: [ScorePair(0, 0); SQUARE_RELATIVE_TO_KING_LEN], - rook_square_relative_to_enemy_king: [ScorePair(0, 0); SQUARE_RELATIVE_TO_KING_LEN], - queen_square_relative_to_friendly_king: [ScorePair(0, 0); SQUARE_RELATIVE_TO_KING_LEN], - queen_square_relative_to_enemy_king: [ScorePair(0, 0); SQUARE_RELATIVE_TO_KING_LEN], + pawn_relative_to_friendly_king: [ScorePair(0, 0); PIECE_RELATIVE_TO_KING_LEN], + pawn_relative_to_enemy_king: [ScorePair(0, 0); PIECE_RELATIVE_TO_KING_LEN], + knight_relative_to_friendly_king: [ScorePair(0, 0); PIECE_RELATIVE_TO_KING_LEN], + knight_relative_to_enemy_king: [ScorePair(0, 0); PIECE_RELATIVE_TO_KING_LEN], + bishop_relative_to_friendly_king: [ScorePair(0, 0); PIECE_RELATIVE_TO_KING_LEN], + bishop_relative_to_enemy_king: [ScorePair(0, 0); PIECE_RELATIVE_TO_KING_LEN], + rook_relative_to_friendly_king: [ScorePair(0, 0); PIECE_RELATIVE_TO_KING_LEN], + rook_relative_to_enemy_king: [ScorePair(0, 0); PIECE_RELATIVE_TO_KING_LEN], + queen_relative_to_friendly_king: [ScorePair(0, 0); PIECE_RELATIVE_TO_KING_LEN], + queen_relative_to_enemy_king: [ScorePair(0, 0); PIECE_RELATIVE_TO_KING_LEN], + passed_pawn_relative_to_friendly_king: [ScorePair(0, 0); + PASSED_PAWNS_RELATIVE_TO_KING_LEN], + passed_pawn_relative_to_enemy_king: [ScorePair(0, 0); + PASSED_PAWNS_RELATIVE_TO_KING_LEN], } } } @@ -94,43 +101,51 @@ impl From<&WeightVector> for EvalParams { Self::next_params(&mut eval_params.queen_mobility, &mut weight_iter); Self::next_param(&mut eval_params.bishop_pair, &mut weight_iter); Self::next_params( - &mut eval_params.pawn_square_relative_to_friendly_king, + &mut eval_params.pawn_relative_to_friendly_king, &mut weight_iter, ); Self::next_params( - &mut eval_params.pawn_square_relative_to_enemy_king, + &mut eval_params.pawn_relative_to_enemy_king, &mut weight_iter, ); Self::next_params( - &mut eval_params.knight_square_relative_to_friendly_king, + &mut eval_params.knight_relative_to_friendly_king, &mut weight_iter, ); Self::next_params( - &mut eval_params.knight_square_relative_to_enemy_king, + &mut eval_params.knight_relative_to_enemy_king, &mut weight_iter, ); Self::next_params( - &mut eval_params.bishop_square_relative_to_friendly_king, + &mut eval_params.bishop_relative_to_friendly_king, &mut weight_iter, ); Self::next_params( - &mut eval_params.bishop_square_relative_to_enemy_king, + &mut eval_params.bishop_relative_to_enemy_king, &mut weight_iter, ); Self::next_params( - &mut eval_params.rook_square_relative_to_friendly_king, + &mut eval_params.rook_relative_to_friendly_king, &mut weight_iter, ); Self::next_params( - &mut eval_params.rook_square_relative_to_enemy_king, + &mut eval_params.rook_relative_to_enemy_king, &mut weight_iter, ); Self::next_params( - &mut eval_params.queen_square_relative_to_friendly_king, + &mut eval_params.queen_relative_to_friendly_king, &mut weight_iter, ); Self::next_params( - &mut eval_params.queen_square_relative_to_enemy_king, + &mut eval_params.queen_relative_to_enemy_king, + &mut weight_iter, + ); + Self::next_params( + &mut eval_params.passed_pawn_relative_to_friendly_king, + &mut weight_iter, + ); + Self::next_params( + &mut eval_params.passed_pawn_relative_to_enemy_king, &mut weight_iter, ); eval_params @@ -144,6 +159,7 @@ impl Display for EvalParams { "pub const TEMPO: ScorePair = ScorePair({}, {});", self.tempo.0, self.tempo.1 )?; + writeln!(f)?; self.fmt_single_pst(f, "PASSED_PAWN_MG_EG", self.passed_pawn)?; writeln!( f, @@ -160,15 +176,30 @@ impl Display for EvalParams { "pub const DOUBLED_PAWN: ScorePair = ScorePair({}, {});", self.doubled_pawn.0, self.doubled_pawn.1 )?; - + writeln!(f)?; writeln!( f, "pub const BISHOP_PAIR: ScorePair = ScorePair({}, {});", self.bishop_pair.0, self.bishop_pair.1 )?; - + writeln!(f)?; self.fmt_mobilities(f)?; - self.fmt_squares_relative_to_king(f)?; + writeln!(f)?; + self.fmt_pieces_relative_to_king(f)?; + writeln!(f)?; + self.fmt_weights( + f, + "PASSED_PAWN_RELATIVE_TO_FRIENDLY_KING_MG_EG", + "PASSED_PAWNS_RELATIVE_TO_KING_LEN", + &self.passed_pawn_relative_to_friendly_king, + )?; + self.fmt_weights( + f, + "PASSED_PAWN_RELATIVE_TO_ENEMY_KING_MG_EG", + "PASSED_PAWNS_RELATIVE_TO_KING_LEN", + &self.passed_pawn_relative_to_enemy_king, + )?; + writeln!(f)?; self.fmt_pst(f)?; Ok(()) @@ -222,50 +253,50 @@ impl EvalParams { Ok(()) } - fn fmt_squares_relative_to_king(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt_pieces_relative_to_king(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { for (const_name, weights) in [ ( - "PAWN_SQUARE_RELATIVE_TO_FRIENDLY_KING_MG_EG", - &self.pawn_square_relative_to_friendly_king, + "PAWN_RELATIVE_TO_FRIENDLY_KING_MG_EG", + &self.pawn_relative_to_friendly_king, ), ( - "PAWN_SQUARE_RELATIVE_TO_ENEMY_KING_MG_EG", - &self.pawn_square_relative_to_enemy_king, + "PAWN_RELATIVE_TO_ENEMY_KING_MG_EG", + &self.pawn_relative_to_enemy_king, ), ( - "KNIGHT_SQUARE_RELATIVE_TO_FRIENDLY_KING_MG_EG", - &self.knight_square_relative_to_friendly_king, + "KNIGHT_RELATIVE_TO_FRIENDLY_KING_MG_EG", + &self.knight_relative_to_friendly_king, ), ( - "KNIGHT_SQUARE_RELATIVE_TO_ENEMY_KING_MG_EG", - &self.knight_square_relative_to_enemy_king, + "KNIGHT_RELATIVE_TO_ENEMY_KING_MG_EG", + &self.knight_relative_to_enemy_king, ), ( - "BISHOP_SQUARE_RELATIVE_TO_FRIENDLY_KING_MG_EG", - &self.bishop_square_relative_to_friendly_king, + "BISHOP_RELATIVE_TO_FRIENDLY_KING_MG_EG", + &self.bishop_relative_to_friendly_king, ), ( - "BISHOP_SQUARE_RELATIVE_TO_ENEMY_KING_MG_EG", - &self.bishop_square_relative_to_enemy_king, + "BISHOP_RELATIVE_TO_ENEMY_KING_MG_EG", + &self.bishop_relative_to_enemy_king, ), ( - "ROOK_SQUARE_RELATIVE_TO_FRIENDLY_KING_MG_EG", - &self.rook_square_relative_to_friendly_king, + "ROOK_RELATIVE_TO_FRIENDLY_KING_MG_EG", + &self.rook_relative_to_friendly_king, ), ( - "ROOK_SQUARE_RELATIVE_TO_ENEMY_KING_MG_EG", - &self.rook_square_relative_to_enemy_king, + "ROOK_RELATIVE_TO_ENEMY_KING_MG_EG", + &self.rook_relative_to_enemy_king, ), ( - "QUEEN_SQUARE_RELATIVE_TO_FRIENDLY_KING_MG_EG", - &self.queen_square_relative_to_friendly_king, + "QUEEN_RELATIVE_TO_FRIENDLY_KING_MG_EG", + &self.queen_relative_to_friendly_king, ), ( - "QUEEN_SQUARE_RELATIVE_TO_ENEMY_KING_MG_EG", - &self.queen_square_relative_to_enemy_king, + "QUEEN_RELATIVE_TO_ENEMY_KING_MG_EG", + &self.queen_relative_to_enemy_king, ), ] { - self.fmt_weights(f, const_name, "SQUARE_RELATIVE_TO_KING_LEN", weights)?; + self.fmt_weights(f, const_name, "PIECE_RELATIVE_TO_KING_LEN", weights)?; } Ok(()) } diff --git a/tuner/src/feature_evaluator.rs b/tuner/src/feature_evaluator.rs index b23ea3d..38d8fd5 100644 --- a/tuner/src/feature_evaluator.rs +++ b/tuner/src/feature_evaluator.rs @@ -1,6 +1,6 @@ use std::iter; -use eval::params::{self, MOB_LEN, SQUARE_RELATIVE_TO_KING_LEN}; +use eval::params::{self, MOB_LEN, PASSED_PAWNS_RELATIVE_TO_KING_LEN, PIECE_RELATIVE_TO_KING_LEN}; use nalgebra::SVector; use crate::eval_coeffs::EvalCoeffs; @@ -24,8 +24,10 @@ const NUM_BACKWARD_PAWN_FEATURES: usize = 1; const NUM_DOUBLED_PAWN_FEATURES: usize = 1; const NUM_MOBILITY_FEATURES: usize = MOB_LEN; const NUM_BISHOP_PAIR_FEATURES: usize = 1; -const NUM_SQUARE_RELATIVE_TO_KING_FEATURES: usize = - NUM_SIDES * (NUM_PIECE_TYPES - 1) * SQUARE_RELATIVE_TO_KING_LEN; +const NUM_PIECE_RELATIVE_TO_KING_FEATURES: usize = + NUM_SIDES * (NUM_PIECE_TYPES - 1) * PIECE_RELATIVE_TO_KING_LEN; +const NUM_PASSED_PAWN_RELATIVE_TO_KING_FEATURES: usize = + NUM_SIDES * PASSED_PAWNS_RELATIVE_TO_KING_LEN; pub const NUM_FEATURES: usize = NUM_PST_FEATURES + NUM_TEMPO_FEATURES + NUM_PASSED_PAWN_FEATURES @@ -34,7 +36,8 @@ pub const NUM_FEATURES: usize = NUM_PST_FEATURES + NUM_DOUBLED_PAWN_FEATURES + NUM_MOBILITY_FEATURES + NUM_BISHOP_PAIR_FEATURES - + NUM_SQUARE_RELATIVE_TO_KING_FEATURES; + + NUM_PIECE_RELATIVE_TO_KING_FEATURES + + NUM_PASSED_PAWN_RELATIVE_TO_KING_FEATURES; pub const START_IDX_PST: usize = 0; @@ -127,16 +130,18 @@ pub fn engine_weights() -> WeightVector { .chain(params::MOBILITY_ROOK.iter()) .chain(params::MOBILITY_QUEEN.iter()) .chain(iter::once(¶ms::BISHOP_PAIR)) - .chain(params::PAWN_SQUARE_RELATIVE_TO_FRIENDLY_KING.iter()) - .chain(params::PAWN_SQUARE_RELATIVE_TO_ENEMY_KING.iter()) - .chain(params::KNIGHT_SQUARE_RELATIVE_TO_FRIENDLY_KING.iter()) - .chain(params::KNIGHT_SQUARE_RELATIVE_TO_ENEMY_KING.iter()) - .chain(params::BISHOP_SQUARE_RELATIVE_TO_FRIENDLY_KING.iter()) - .chain(params::BISHOP_SQUARE_RELATIVE_TO_ENEMY_KING.iter()) - .chain(params::ROOK_SQUARE_RELATIVE_TO_FRIENDLY_KING.iter()) - .chain(params::ROOK_SQUARE_RELATIVE_TO_ENEMY_KING.iter()) - .chain(params::QUEEN_SQUARE_RELATIVE_TO_FRIENDLY_KING.iter()) - .chain(params::QUEEN_SQUARE_RELATIVE_TO_ENEMY_KING.iter()); + .chain(params::PAWN_RELATIVE_TO_FRIENDLY_KING.iter()) + .chain(params::PAWN_RELATIVE_TO_ENEMY_KING.iter()) + .chain(params::KNIGHT_RELATIVE_TO_FRIENDLY_KING.iter()) + .chain(params::KNIGHT_RELATIVE_TO_ENEMY_KING.iter()) + .chain(params::BISHOP_RELATIVE_TO_FRIENDLY_KING.iter()) + .chain(params::BISHOP_RELATIVE_TO_ENEMY_KING.iter()) + .chain(params::ROOK_RELATIVE_TO_FRIENDLY_KING.iter()) + .chain(params::ROOK_RELATIVE_TO_ENEMY_KING.iter()) + .chain(params::QUEEN_RELATIVE_TO_FRIENDLY_KING.iter()) + .chain(params::QUEEN_RELATIVE_TO_ENEMY_KING.iter()) + .chain(params::PASSED_PAWN_RELATIVE_TO_FRIENDLY_KING.iter()) + .chain(params::PASSED_PAWN_RELATIVE_TO_ENEMY_KING.iter()); let mut weights = WeightVector::from_element(0.0); for (idx, &weight) in weight_iter.enumerate() { // Middlegame