From 91c53a2a18bb95888a13f590f9af82d6cdf61d49 Mon Sep 17 00:00:00 2001 From: jan Date: Wed, 15 Oct 2025 20:52:13 +0200 Subject: [PATCH 1/3] Feat: Started pawn optimizations. --- src/backend/movegen/move_gen_pawn_util.rs | 112 +++++++++------------- src/backend/state/board/bitboard.rs | 32 ++++++- 2 files changed, 75 insertions(+), 69 deletions(-) diff --git a/src/backend/movegen/move_gen_pawn_util.rs b/src/backend/movegen/move_gen_pawn_util.rs index 07c8f19..f97f9fd 100644 --- a/src/backend/movegen/move_gen_pawn_util.rs +++ b/src/backend/movegen/move_gen_pawn_util.rs @@ -1,95 +1,73 @@ -use crate::backend::compile_time::gen_caches::{ - PAWN_CAPTURE_MOVES, PAWN_DOUBLE_PUSH_MOVES, PAWN_QUIET_MOVES, -}; +use crate::backend::compile_time::gen_caches::PAWN_CAPTURE_MOVES; use crate::backend::movegen::moove::Moove; use crate::backend::movegen::move_gen::iterate_over_bitboard_for_non_slider; -use crate::backend::state::board::bb_manager::BBManager; use crate::backend::state::board::bitboard::BitBoard; use crate::backend::state::game::state::State; use crate::backend::state::piece::Piece::{Pawn, Queen}; use crate::backend::state::piece::{PROMOTABLE_PIECES, Side}; +const WHITE_PAWN_START_RANK_BB: BitBoard = BitBoard::new_from_rank(1); +const BLACK_PAWN_START_RANK_BB: BitBoard = BitBoard::new_from_rank(6); + pub fn gen_pawn_moves( moves: &mut Vec, - game_state: &State, + state: &State, friendly_pieces_bb: BitBoard, enemy_pieces_bb: BitBoard, active_color: Side, ) { - let mut pawn_moves = Vec::new(); - // Quiet pawn moves - iterate_over_bitboard_for_non_slider( - &mut pawn_moves, - PAWN_QUIET_MOVES[active_color as usize], - game_state - .bb_manager - .get_colored_piece_bb(Pawn, active_color), - friendly_pieces_bb | enemy_pieces_bb, - ); - - // Capture pawn moves - iterate_over_bitboard_for_non_slider( - &mut pawn_moves, - PAWN_CAPTURE_MOVES[active_color as usize], - game_state - .bb_manager - .get_colored_piece_bb(Pawn, active_color), - create_pawn_capture_mask(game_state, enemy_pieces_bb), - ); - promotion_logic(&mut pawn_moves); - moves.append(&mut pawn_moves); - - // Double pawn push moves - let mut pawn_moves = get_double_pawn_push_moves( - &game_state.bb_manager, - active_color, - friendly_pieces_bb | enemy_pieces_bb, - ); - moves.append(&mut pawn_moves); -} -pub fn get_double_pawn_push_moves( - bitboard_manager: &BBManager, - active_color: Side, - all_pieces_bb: BitBoard, -) -> Vec { - let mut moves: Vec = Vec::new(); + let occupancy_bb = friendly_pieces_bb | enemy_pieces_bb; + let pawn_bb = state.bb_manager.get_colored_piece_bb(Pawn, active_color); - let mut pawn_bitboard = bitboard_manager.get_colored_piece_bb(Pawn, active_color); - - let starting_bitboard = match active_color { - Side::White => BitBoard::new_from_rank(1), - Side::Black => BitBoard::new_from_rank(6), + // single push + let mut push_pawn_bb = match active_color { + Side::White => pawn_bb << 8, + Side::Black => pawn_bb >> 8, }; - - pawn_bitboard &= starting_bitboard; - - for square in pawn_bitboard { - let mut single_push_bb = PAWN_QUIET_MOVES[active_color as usize][square.square_to_index()]; - single_push_bb &= all_pieces_bb; - if !single_push_bb.is_empty() { - continue; + push_pawn_bb &= !occupancy_bb; + for square in push_pawn_bb { + let moove = Moove::new(square.back_by_one(active_color), square); + if square.is_on_promotion_rank() { + for piece_type in PROMOTABLE_PIECES { + let mut promotion_move = moove; + promotion_move.promotion_type = Some(piece_type); + moves.push(promotion_move); + } + } else { + moves.push(moove); } + } - let mut double_push_bb = - PAWN_DOUBLE_PUSH_MOVES[active_color as usize][square.square_to_index()]; - double_push_bb &= all_pieces_bb; - if !double_push_bb.is_empty() { - continue; + // double push + let double_push_pawn_bb = match active_color { + Side::White => { + (((pawn_bb & WHITE_PAWN_START_RANK_BB) << 8) & !occupancy_bb) << 8 & !occupancy_bb } - + Side::Black => { + (((pawn_bb & BLACK_PAWN_START_RANK_BB) >> 8) & !occupancy_bb) >> 8 & !occupancy_bb + } + }; + for square in double_push_pawn_bb { let moove = Moove::new( + square.back_by_one(active_color).back_by_one(active_color), square, - square - .forward_by_one(active_color) - .forward_by_one(active_color), ); moves.push(moove); } - moves + let mut pawn_moves = Vec::new(); + // Capture pawn moves + iterate_over_bitboard_for_non_slider( + &mut pawn_moves, + PAWN_CAPTURE_MOVES[active_color as usize], + state.bb_manager.get_colored_piece_bb(Pawn, active_color), + create_pawn_capture_mask(state, enemy_pieces_bb), + ); + promotion_logic(&mut pawn_moves); + moves.append(&mut pawn_moves); } -pub fn create_pawn_capture_mask(game_state: &State, enemy_pieces_bitboard: BitBoard) -> BitBoard { +fn create_pawn_capture_mask(game_state: &State, enemy_pieces_bitboard: BitBoard) -> BitBoard { // Capture pawn moves let mut pawn_capture_mask = enemy_pieces_bitboard; match game_state.irreversible_data.en_passant_square { @@ -102,7 +80,7 @@ pub fn create_pawn_capture_mask(game_state: &State, enemy_pieces_bitboard: BitBo pawn_capture_mask } -pub fn promotion_logic(moves: &mut Vec) { +fn promotion_logic(moves: &mut Vec) { if moves.is_empty() { return; } diff --git a/src/backend/state/board/bitboard.rs b/src/backend/state/board/bitboard.rs index fd2b869..8f5d792 100644 --- a/src/backend/state/board/bitboard.rs +++ b/src/backend/state/board/bitboard.rs @@ -1,7 +1,9 @@ use crate::backend::constants::FILES_AMOUNT; use crate::backend::state::square::Square; use std::fmt::{Display, Formatter}; -use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not}; +use std::ops::{ + BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not, Shl, ShlAssign, Shr, +}; /// A struct that represents a BitBoard. /// Each bit in the `u64` value represents a specific position on the board. @@ -39,7 +41,7 @@ impl BitBoard { bitboard } - pub fn new_from_rank(rank: i8) -> Self { + pub const fn new_from_rank(rank: i8) -> Self { let mut bitboard = BitBoard::new(); let mut file = 0; @@ -120,6 +122,32 @@ impl Iterator for BitBoard { } } +impl ShlAssign for BitBoard { + fn shl_assign(&mut self, rhs: i32) { + self.value <<= rhs; + } +} + +impl Shl for BitBoard { + type Output = Self; + + fn shl(self, rhs: i32) -> Self::Output { + BitBoard { + value: self.value << rhs, + } + } +} + +impl Shr for BitBoard { + type Output = Self; + + fn shr(self, rhs: i32) -> Self::Output { + BitBoard { + value: self.value >> rhs, + } + } +} + // Various bitwise operations on BitBoards. impl Not for BitBoard { type Output = Self; From 53ab6aa273f3e65fa64873812272400dfcfd6a41 Mon Sep 17 00:00:00 2001 From: jan Date: Fri, 17 Oct 2025 17:39:26 +0200 Subject: [PATCH 2/3] Feat: Pawn capture moves optimizations. --- src/backend/movegen/move_gen_pawn_util.rs | 191 +++++++++++++++------- src/backend/state/board/bitboard.rs | 21 ++- tests/integration_tests.rs | 8 + 3 files changed, 160 insertions(+), 60 deletions(-) diff --git a/src/backend/movegen/move_gen_pawn_util.rs b/src/backend/movegen/move_gen_pawn_util.rs index f97f9fd..72c604a 100644 --- a/src/backend/movegen/move_gen_pawn_util.rs +++ b/src/backend/movegen/move_gen_pawn_util.rs @@ -1,13 +1,19 @@ -use crate::backend::compile_time::gen_caches::PAWN_CAPTURE_MOVES; use crate::backend::movegen::moove::Moove; -use crate::backend::movegen::move_gen::iterate_over_bitboard_for_non_slider; use crate::backend::state::board::bitboard::BitBoard; use crate::backend::state::game::state::State; -use crate::backend::state::piece::Piece::{Pawn, Queen}; +use crate::backend::state::piece::Piece::Pawn; use crate::backend::state::piece::{PROMOTABLE_PIECES, Side}; +use crate::backend::state::square::Square; +const BLACK_PROMOTION_RANK_BB: BitBoard = BitBoard::new_from_rank(0); +const WHITE_PROMOTION_RANK_BB: BitBoard = BitBoard::new_from_rank(7); const WHITE_PAWN_START_RANK_BB: BitBoard = BitBoard::new_from_rank(1); const BLACK_PAWN_START_RANK_BB: BitBoard = BitBoard::new_from_rank(6); +const PROMOTION_RANKS_BB: BitBoard = BitBoard { + value: (BLACK_PROMOTION_RANK_BB.value | WHITE_PROMOTION_RANK_BB.value), +}; +const LEFT_SIDE_BB: BitBoard = BitBoard::new_from_file(0); +const RIGHT_SIDE_BB: BitBoard = BitBoard::new_from_file(7); pub fn gen_pawn_moves( moves: &mut Vec, @@ -19,27 +25,84 @@ pub fn gen_pawn_moves( let occupancy_bb = friendly_pieces_bb | enemy_pieces_bb; let pawn_bb = state.bb_manager.get_colored_piece_bb(Pawn, active_color); + let rank_offset = match active_color { + Side::White => -1, + Side::Black => 1, + }; + // single push + single_push(moves, active_color, occupancy_bb, pawn_bb, rank_offset); + + // double push + double_push(moves, active_color, occupancy_bb, pawn_bb, rank_offset); + + let mut possible_captures_bb = enemy_pieces_bb; + match state.irreversible_data.en_passant_square { + None => {} + Some(square) => { + possible_captures_bb.fill_square(square); + } + } + // left captures + let shift = match active_color { + Side::White => 7, + Side::Black => -9, + }; + one_dir_capture( + moves, + possible_captures_bb, + pawn_bb, + rank_offset, + shift, + LEFT_SIDE_BB, + 1, + ); + + // right captures + let shift = match active_color { + Side::White => 9, + Side::Black => -7, + }; + one_dir_capture( + moves, + possible_captures_bb, + pawn_bb, + rank_offset, + shift, + RIGHT_SIDE_BB, + -1, + ); +} + +fn single_push( + moves: &mut Vec, + active_color: Side, + occupancy_bb: BitBoard, + pawn_bb: BitBoard, + rank_offset: i8, +) { let mut push_pawn_bb = match active_color { Side::White => pawn_bb << 8, Side::Black => pawn_bb >> 8, }; + // cant go there if something is there push_pawn_bb &= !occupancy_bb; - for square in push_pawn_bb { - let moove = Moove::new(square.back_by_one(active_color), square); - if square.is_on_promotion_rank() { - for piece_type in PROMOTABLE_PIECES { - let mut promotion_move = moove; - promotion_move.promotion_type = Some(piece_type); - moves.push(promotion_move); - } - } else { - moves.push(moove); - } - } - // double push - let double_push_pawn_bb = match active_color { + let no_promotion_push_pawn_bb = push_pawn_bb & !PROMOTION_RANKS_BB; + pawn_bb_to_moves_no_promotion(moves, no_promotion_push_pawn_bb, 0, rank_offset); + + let promotion_push_pawn_bb = push_pawn_bb & PROMOTION_RANKS_BB; + pawn_bb_to_moves_promotion(moves, promotion_push_pawn_bb, 0, rank_offset); +} + +fn double_push( + moves: &mut Vec, + active_color: Side, + occupancy_bb: BitBoard, + pawn_bb: BitBoard, + rank_offset: i8, +) { + let double_push_bb = match active_color { Side::White => { (((pawn_bb & WHITE_PAWN_START_RANK_BB) << 8) & !occupancy_bb) << 8 & !occupancy_bb } @@ -47,55 +110,65 @@ pub fn gen_pawn_moves( (((pawn_bb & BLACK_PAWN_START_RANK_BB) >> 8) & !occupancy_bb) >> 8 & !occupancy_bb } }; - for square in double_push_pawn_bb { - let moove = Moove::new( - square.back_by_one(active_color).back_by_one(active_color), - square, - ); - moves.push(moove); + pawn_bb_to_moves_no_promotion(moves, double_push_bb, 0, 2 * rank_offset); +} + +fn one_dir_capture( + moves: &mut Vec, + enemy_pieces_bb: BitBoard, + mut pawn_bb: BitBoard, + rank_offset: i8, + shift: i32, + mask: BitBoard, + file_offset: i8, +) { + pawn_bb &= !mask; + + if shift.is_negative() { + pawn_bb >>= shift.unsigned_abs(); + } else { + pawn_bb <<= shift; } + let capture_bb = pawn_bb & enemy_pieces_bb; - let mut pawn_moves = Vec::new(); - // Capture pawn moves - iterate_over_bitboard_for_non_slider( - &mut pawn_moves, - PAWN_CAPTURE_MOVES[active_color as usize], - state.bb_manager.get_colored_piece_bb(Pawn, active_color), - create_pawn_capture_mask(state, enemy_pieces_bb), - ); - promotion_logic(&mut pawn_moves); - moves.append(&mut pawn_moves); + let capture_no_promotion = capture_bb & !PROMOTION_RANKS_BB; + pawn_bb_to_moves_no_promotion(moves, capture_no_promotion, file_offset, rank_offset); + + let captures_promotion = capture_bb & PROMOTION_RANKS_BB; + pawn_bb_to_moves_promotion(moves, captures_promotion, file_offset, rank_offset); } -fn create_pawn_capture_mask(game_state: &State, enemy_pieces_bitboard: BitBoard) -> BitBoard { - // Capture pawn moves - let mut pawn_capture_mask = enemy_pieces_bitboard; - match game_state.irreversible_data.en_passant_square { - None => {} - Some(ep_square) => { - pawn_capture_mask.fill_square(ep_square); - } +fn pawn_bb_to_moves_no_promotion( + moves: &mut Vec, + pawn_bb: BitBoard, + file_offset: i8, + rank_offset: i8, +) { + for square in pawn_bb { + let from_square = Square { + file: square.file + file_offset, + rank: square.rank + rank_offset, + }; + let moove = Moove::new(from_square, square); + moves.push(moove); } - pawn_capture_mask = !pawn_capture_mask; - pawn_capture_mask } -fn promotion_logic(moves: &mut Vec) { - if moves.is_empty() { - return; - } - for index in (0..moves.len()).rev() { - let moove = moves[index]; - if moove.to.is_on_promotion_rank() { - for piece_type in PROMOTABLE_PIECES { - if piece_type == Queen { - moves[index].promotion_type = Some(Queen); - continue; - } - let mut moove = moove; - moove.promotion_type = Some(piece_type); - moves.push(moove); - } +fn pawn_bb_to_moves_promotion( + moves: &mut Vec, + pawn_bb: BitBoard, + file_offset: i8, + rank_offset: i8, +) { + for square in pawn_bb { + let from_square = Square { + file: square.file + file_offset, + rank: square.rank + rank_offset, + }; + for piece_type in PROMOTABLE_PIECES { + let mut moove = Moove::new(from_square, square); + moove.promotion_type = Some(piece_type); + moves.push(moove); } } } diff --git a/src/backend/state/board/bitboard.rs b/src/backend/state/board/bitboard.rs index 8f5d792..223163d 100644 --- a/src/backend/state/board/bitboard.rs +++ b/src/backend/state/board/bitboard.rs @@ -1,8 +1,9 @@ -use crate::backend::constants::FILES_AMOUNT; +use crate::backend::constants::{FILES_AMOUNT, RANKS_AMOUNT}; use crate::backend::state::square::Square; use std::fmt::{Display, Formatter}; use std::ops::{ BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not, Shl, ShlAssign, Shr, + ShrAssign, }; /// A struct that represents a BitBoard. @@ -53,6 +54,18 @@ impl BitBoard { bitboard } + pub const fn new_from_file(file: i8) -> Self { + let mut bitboard = BitBoard::new(); + + let mut rank = 0; + while rank < RANKS_AMOUNT { + bitboard.fill_square(Square::new(file, rank as i8)); + rank += 1; + } + + bitboard + } + /// Checks if the value of the current instance is empty or zero. /// /// # Returns @@ -138,6 +151,12 @@ impl Shl for BitBoard { } } +impl ShrAssign for BitBoard { + fn shr_assign(&mut self, rhs: u32) { + self.value >>= rhs; + } +} + impl Shr for BitBoard { type Output = Self; diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 78bc95c..61f00c3 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -194,3 +194,11 @@ fn test_perft_17() { let nodes = perft(&state, 4); assert_eq!(nodes, 112371); } + +#[test] +fn test_perft_18() { + let state = State::new_from_fen("4k3/8/8/p7/1P6/8/8/4K3 b - - 0 1"); + + let nodes = perft(&state, 1); + assert_eq!(nodes, 7); +} From 5dd2f70b0df4905a1d39bcb93b685190b89aa73c Mon Sep 17 00:00:00 2001 From: jan Date: Sun, 19 Oct 2025 18:36:40 +0200 Subject: [PATCH 3/3] Refactor: Removed old pawn code. --- src/backend/compile_time/gen_caches.rs | 23 +++----------------- src/backend/compile_time/generated/caches.rs | 6 ----- src/main.rs | 8 +++---- 3 files changed, 7 insertions(+), 30 deletions(-) diff --git a/src/backend/compile_time/gen_caches.rs b/src/backend/compile_time/gen_caches.rs index fbcdb58..b290612 100644 --- a/src/backend/compile_time/gen_caches.rs +++ b/src/backend/compile_time/gen_caches.rs @@ -3,9 +3,8 @@ use crate::backend::compile_time::gen_caches_non_sliders::{ }; use crate::backend::compile_time::gen_caches_sliders::{PEXT_TABLE_SIZE, gen_cache_sliders}; use crate::backend::compile_time::generated::caches::{ - CACHE_BISHOP_PEXT_INDEX, CACHE_BISHOP_PEXT_MASK, CACHE_CAPTURE_PAWN, CACHE_DOUBLE_PUSH_PAWN, - CACHE_KING, CACHE_KNIGHT, CACHE_PEXT_TABLE, CACHE_QUIET_PAWN, CACHE_ROOK_PEXT_INDEX, - CACHE_ROOK_PEXT_MASK, + CACHE_BISHOP_PEXT_INDEX, CACHE_BISHOP_PEXT_MASK, CACHE_CAPTURE_PAWN, CACHE_KING, CACHE_KNIGHT, + CACHE_PEXT_TABLE, CACHE_ROOK_PEXT_INDEX, CACHE_ROOK_PEXT_MASK, }; use crate::backend::constants::{SIDES, SQUARES_AMOUNT}; use crate::backend::state::board::bitboard::BitBoard; @@ -35,13 +34,9 @@ use std::fs; pub const KING_MOVES: [BitBoard; SQUARES_AMOUNT] = read_bb_cache(&CACHE_KING); pub const KNIGHT_MOVES: [BitBoard; SQUARES_AMOUNT] = read_bb_cache(&CACHE_KNIGHT); -// Various pawn caches: -pub const PAWN_QUIET_MOVES: [[BitBoard; SQUARES_AMOUNT]; SIDES] = - read_2d_bb_cache(CACHE_QUIET_PAWN); +// Due for removal, only exists until check_decider gets reworked. pub const PAWN_CAPTURE_MOVES: [[BitBoard; SQUARES_AMOUNT]; SIDES] = read_2d_bb_cache(CACHE_CAPTURE_PAWN); -pub const PAWN_DOUBLE_PUSH_MOVES: [[BitBoard; SQUARES_AMOUNT]; SIDES] = - read_2d_bb_cache(CACHE_DOUBLE_PUSH_PAWN); // Various slider caches: pub const ROOK_PEXT_MASK: [BitBoard; SQUARES_AMOUNT] = read_bb_cache(&CACHE_ROOK_PEXT_MASK); @@ -95,12 +90,8 @@ pub fn write_caches() { let knight_moves = calculate_potential_moves_cache(Piece::Knight); let knight_moves = knight_moves.map(|b| b.value); - let quiet_pawn_moves = generate_pawn_moves(PawnMoveType::Quiet); - let quiet_pawn_moves = quiet_pawn_moves.map(|a| a.map(|b| b.value)); let capture_pawn_moves = generate_pawn_moves(PawnMoveType::Capture); let capture_pawn_moves = capture_pawn_moves.map(|a| a.map(|b| b.value)); - let double_push_pawn_moves = generate_pawn_moves(PawnMoveType::DoublePush); - let double_push_pawn_moves = double_push_pawn_moves.map(|a| a.map(|b| b.value)); let pext_data = gen_cache_sliders(); let rook_pext_mask = pext_data.rook_pext_mask; @@ -115,18 +106,10 @@ pub fn write_caches() { let cache_strings = [ format!("pub const CACHE_KING: [u64; 64] = {:?};", king_moves), format!("pub const CACHE_KNIGHT: [u64; 64] = {:?};", knight_moves), - format!( - "pub const CACHE_QUIET_PAWN: [[u64; 64]; 2] = {:?};", - quiet_pawn_moves - ), format!( "pub const CACHE_CAPTURE_PAWN: [[u64; 64]; 2] = {:?};", capture_pawn_moves ), - format!( - "pub const CACHE_DOUBLE_PUSH_PAWN: [[u64; 64]; 2] = {:?};", - double_push_pawn_moves - ), format!( "pub const CACHE_ROOK_PEXT_MASK: [u64; 64] = {:?};", rook_pext_mask diff --git a/src/backend/compile_time/generated/caches.rs b/src/backend/compile_time/generated/caches.rs index 93710dc..54a1c8f 100644 --- a/src/backend/compile_time/generated/caches.rs +++ b/src/backend/compile_time/generated/caches.rs @@ -4,15 +4,9 @@ pub const CACHE_KING: [u64; 64] = [770, 1797, 3594, 7188, 14376, 28752, 57504, 4 #[rustfmt::skip] pub const CACHE_KNIGHT: [u64; 64] = [132096, 329728, 659712, 1319424, 2638848, 5277696, 10489856, 4202496, 33816580, 84410376, 168886289, 337772578, 675545156, 1351090312, 2685403152, 1075839008, 8657044482, 21609056261, 43234889994, 86469779988, 172939559976, 345879119952, 687463207072, 275414786112, 2216203387392, 5531918402816, 11068131838464, 22136263676928, 44272527353856, 88545054707712, 175990581010432, 70506185244672, 567348067172352, 1416171111120896, 2833441750646784, 5666883501293568, 11333767002587136, 22667534005174272, 45053588738670592, 18049583422636032, 145241105196122112, 362539804446949376, 725361088165576704, 1450722176331153408, 2901444352662306816, 5802888705324613632, 11533718717099671552, 4620693356194824192, 288234782788157440, 576469569871282176, 1224997833292120064, 2449995666584240128, 4899991333168480256, 9799982666336960512, 1152939783987658752, 2305878468463689728, 1128098930098176, 2257297371824128, 4796069720358912, 9592139440717824, 19184278881435648, 38368557762871296, 4679521487814656, 9077567998918656]; -#[rustfmt::skip] -pub const CACHE_QUIET_PAWN: [[u64; 64]; 2] = [[256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 34359738368, 68719476736, 137438953472, 274877906944, 549755813888, 1099511627776, 2199023255552, 4398046511104, 8796093022208, 17592186044416, 35184372088832, 70368744177664, 140737488355328, 281474976710656, 562949953421312, 1125899906842624, 2251799813685248, 4503599627370496, 9007199254740992, 18014398509481984, 36028797018963968, 72057594037927936, 144115188075855872, 288230376151711744, 576460752303423488, 1152921504606846976, 2305843009213693952, 4611686018427387904, 9223372036854775808, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 34359738368, 68719476736, 137438953472, 274877906944, 549755813888, 1099511627776, 2199023255552, 4398046511104, 8796093022208, 17592186044416, 35184372088832, 70368744177664, 140737488355328, 281474976710656, 562949953421312, 1125899906842624, 2251799813685248, 4503599627370496, 9007199254740992, 18014398509481984, 36028797018963968]]; - #[rustfmt::skip] pub const CACHE_CAPTURE_PAWN: [[u64; 64]; 2] = [[512, 1280, 2560, 5120, 10240, 20480, 40960, 16384, 131072, 327680, 655360, 1310720, 2621440, 5242880, 10485760, 4194304, 33554432, 83886080, 167772160, 335544320, 671088640, 1342177280, 2684354560, 1073741824, 8589934592, 21474836480, 42949672960, 85899345920, 171798691840, 343597383680, 687194767360, 274877906944, 2199023255552, 5497558138880, 10995116277760, 21990232555520, 43980465111040, 87960930222080, 175921860444160, 70368744177664, 562949953421312, 1407374883553280, 2814749767106560, 5629499534213120, 11258999068426240, 22517998136852480, 45035996273704960, 18014398509481984, 144115188075855872, 360287970189639680, 720575940379279360, 1441151880758558720, 2882303761517117440, 5764607523034234880, 11529215046068469760, 4611686018427387904, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 2, 5, 10, 20, 40, 80, 160, 64, 512, 1280, 2560, 5120, 10240, 20480, 40960, 16384, 131072, 327680, 655360, 1310720, 2621440, 5242880, 10485760, 4194304, 33554432, 83886080, 167772160, 335544320, 671088640, 1342177280, 2684354560, 1073741824, 8589934592, 21474836480, 42949672960, 85899345920, 171798691840, 343597383680, 687194767360, 274877906944, 2199023255552, 5497558138880, 10995116277760, 21990232555520, 43980465111040, 87960930222080, 175921860444160, 70368744177664, 562949953421312, 1407374883553280, 2814749767106560, 5629499534213120, 11258999068426240, 22517998136852480, 45035996273704960, 18014398509481984]]; -#[rustfmt::skip] -pub const CACHE_DOUBLE_PUSH_PAWN: [[u64; 64]; 2] = [[0, 0, 0, 0, 0, 0, 0, 0, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4294967296, 8589934592, 17179869184, 34359738368, 68719476736, 137438953472, 274877906944, 549755813888, 0, 0, 0, 0, 0, 0, 0, 0]]; - #[rustfmt::skip] pub const CACHE_ROOK_PEXT_MASK: [u64; 64] = [282578800148862, 565157600297596, 1130315200595066, 2260630401190006, 4521260802379886, 9042521604759646, 18085043209519166, 36170086419038334, 282578800180736, 565157600328704, 1130315200625152, 2260630401218048, 4521260802403840, 9042521604775424, 18085043209518592, 36170086419037696, 282578808340736, 565157608292864, 1130315208328192, 2260630408398848, 4521260808540160, 9042521608822784, 18085043209388032, 36170086418907136, 282580897300736, 565159647117824, 1130317180306432, 2260632246683648, 4521262379438080, 9042522644946944, 18085043175964672, 36170086385483776, 283115671060736, 565681586307584, 1130822006735872, 2261102847592448, 4521664529305600, 9042787892731904, 18085034619584512, 36170077829103616, 420017753620736, 699298018886144, 1260057572672512, 2381576680245248, 4624614895390720, 9110691325681664, 18082844186263552, 36167887395782656, 35466950888980736, 34905104758997504, 34344362452452352, 33222877839362048, 30979908613181440, 26493970160820224, 17522093256097792, 35607136465616896, 9079539427579068672, 8935706818303361536, 8792156787827803136, 8505056726876686336, 7930856604974452736, 6782456361169985536, 4485655873561051136, 9115426935197958144]; diff --git a/src/main.rs b/src/main.rs index 295a553..25309bf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,17 +1,17 @@ +use crate::backend::compile_time::gen_caches::write_caches; use crate::backend::movegen::check_decider::is_in_check; use crate::backend::movegen::moove::Moove; use crate::backend::movegen::move_gen::get_pseudo_legal_moves; use crate::backend::perft::perft; use crate::backend::state::game::state::State; -use std::env; use std::env::Args; mod backend; fn main() { - // write_caches(); - let args = env::args(); - run_perftree_debug(args); + write_caches(); + // let args = env::args(); + // run_perftree_debug(args); } // --------------------------------------------- //