cleanup some extra stuff

This commit is contained in:
OMGeeky
2025-02-20 17:25:12 +01:00
parent 5a1167a778
commit bfec63b701

View File

@@ -376,9 +376,6 @@ impl Engine {
} }
fn perft_inline(&mut self, depth: i8, ply: usize) -> usize { fn perft_inline(&mut self, depth: i8, ply: usize) -> usize {
// println!("Perft called with depth: {}", depth);
// unsafe
{
//if (depth == 0) //if (depth == 0)
//{ //{
// return 1; // return 1;
@@ -414,8 +411,7 @@ impl Engine {
if self.WHITE_TO_PLAY { if self.WHITE_TO_PLAY {
let mut white_king_check_count: usize = 0; let mut white_king_check_count: usize = 0;
let white_king_position: usize = let white_king_position: usize = self.bitscan_forward_separate(self.PIECE_ARRAY[WK]);
self.bitscan_forward_separate(self.PIECE_ARRAY[WK]);
//pawns //pawns
temp_bitboard = temp_bitboard =
@@ -428,8 +424,7 @@ impl Engine {
} }
//knights //knights
temp_bitboard = temp_bitboard = self.PIECE_ARRAY[BN] & constants::KNIGHT_ATTACKS[white_king_position];
self.PIECE_ARRAY[BN] & constants::KNIGHT_ATTACKS[white_king_position];
if temp_bitboard != 0 { if temp_bitboard != 0 {
let knight_square: usize = self.bitscan_forward_separate(temp_bitboard); let knight_square: usize = self.bitscan_forward_separate(temp_bitboard);
@@ -552,9 +547,7 @@ impl Engine {
target_square = self.bitscan_forward_separate(temp_empty); target_square = self.bitscan_forward_separate(temp_empty);
temp_empty &= temp_empty - 1; temp_empty &= temp_empty - 1;
if (self.PIECE_ARRAY[BP] & constants::WHITE_PAWN_ATTACKS[target_square]) if (self.PIECE_ARRAY[BP] & constants::WHITE_PAWN_ATTACKS[target_square]) != 0 {
!= 0
{
continue; continue;
} }
if (self.PIECE_ARRAY[BN] & constants::KNIGHT_ATTACKS[target_square]) != 0 { if (self.PIECE_ARRAY[BN] & constants::KNIGHT_ATTACKS[target_square]) != 0 {
@@ -563,16 +556,16 @@ impl Engine {
if (self.PIECE_ARRAY[BK] & constants::KING_ATTACKS[target_square]) != 0 { if (self.PIECE_ARRAY[BK] & constants::KING_ATTACKS[target_square]) != 0 {
continue; continue;
} }
let bishop_attacks: u64 = self let bishop_attacks: u64 =
.get_bishop_attacks_fast(target_square, occupancies_without_white_king); self.get_bishop_attacks_fast(target_square, occupancies_without_white_king);
if (self.PIECE_ARRAY[BB] & bishop_attacks) != 0 { if (self.PIECE_ARRAY[BB] & bishop_attacks) != 0 {
continue; continue;
} }
if (self.PIECE_ARRAY[BQ] & bishop_attacks) != 0 { if (self.PIECE_ARRAY[BQ] & bishop_attacks) != 0 {
continue; continue;
} }
let rook_attacks: u64 = self let rook_attacks: u64 =
.get_rook_attacks_fast(target_square, occupancies_without_white_king); self.get_rook_attacks_fast(target_square, occupancies_without_white_king);
if (self.PIECE_ARRAY[BR] & rook_attacks) != 0 { if (self.PIECE_ARRAY[BR] & rook_attacks) != 0 {
continue; continue;
} }
@@ -593,9 +586,7 @@ impl Engine {
target_square = self.bitscan_forward_separate(temp_captures); target_square = self.bitscan_forward_separate(temp_captures);
temp_captures &= temp_captures - 1; temp_captures &= temp_captures - 1;
if (self.PIECE_ARRAY[BP] & constants::WHITE_PAWN_ATTACKS[target_square]) if (self.PIECE_ARRAY[BP] & constants::WHITE_PAWN_ATTACKS[target_square]) != 0 {
!= 0
{
continue; continue;
} }
if (self.PIECE_ARRAY[BN] & constants::KNIGHT_ATTACKS[target_square]) != 0 { if (self.PIECE_ARRAY[BN] & constants::KNIGHT_ATTACKS[target_square]) != 0 {
@@ -604,16 +595,16 @@ impl Engine {
if (self.PIECE_ARRAY[BK] & constants::KING_ATTACKS[target_square]) != 0 { if (self.PIECE_ARRAY[BK] & constants::KING_ATTACKS[target_square]) != 0 {
continue; continue;
} }
let bishop_attacks: u64 = self let bishop_attacks: u64 =
.get_bishop_attacks_fast(target_square, occupancies_without_white_king); self.get_bishop_attacks_fast(target_square, occupancies_without_white_king);
if (self.PIECE_ARRAY[BB] & bishop_attacks) != 0 { if (self.PIECE_ARRAY[BB] & bishop_attacks) != 0 {
continue; continue;
} }
if (self.PIECE_ARRAY[BQ] & bishop_attacks) != 0 { if (self.PIECE_ARRAY[BQ] & bishop_attacks) != 0 {
continue; continue;
} }
let rook_attacks: u64 = self let rook_attacks: u64 =
.get_rook_attacks_fast(target_square, occupancies_without_white_king); self.get_rook_attacks_fast(target_square, occupancies_without_white_king);
if (self.PIECE_ARRAY[BR] & rook_attacks) != 0 { if (self.PIECE_ARRAY[BR] & rook_attacks) != 0 {
continue; continue;
} }
@@ -640,9 +631,7 @@ impl Engine {
target_square = self.bitscan_forward_separate(temp_empty); target_square = self.bitscan_forward_separate(temp_empty);
temp_empty &= temp_empty - 1; temp_empty &= temp_empty - 1;
if (self.PIECE_ARRAY[BP] & constants::WHITE_PAWN_ATTACKS[target_square]) if (self.PIECE_ARRAY[BP] & constants::WHITE_PAWN_ATTACKS[target_square]) != 0 {
!= 0
{
continue; continue;
} }
if (self.PIECE_ARRAY[BN] & constants::KNIGHT_ATTACKS[target_square]) != 0 { if (self.PIECE_ARRAY[BN] & constants::KNIGHT_ATTACKS[target_square]) != 0 {
@@ -651,16 +640,16 @@ impl Engine {
if (self.PIECE_ARRAY[BK] & constants::KING_ATTACKS[target_square]) != 0 { if (self.PIECE_ARRAY[BK] & constants::KING_ATTACKS[target_square]) != 0 {
continue; continue;
} }
let bishop_attacks: u64 = self let bishop_attacks: u64 =
.get_bishop_attacks_fast(target_square, occupancies_without_white_king); self.get_bishop_attacks_fast(target_square, occupancies_without_white_king);
if (self.PIECE_ARRAY[BB] & bishop_attacks) != 0 { if (self.PIECE_ARRAY[BB] & bishop_attacks) != 0 {
continue; continue;
} }
if (self.PIECE_ARRAY[BQ] & bishop_attacks) != 0 { if (self.PIECE_ARRAY[BQ] & bishop_attacks) != 0 {
continue; continue;
} }
let rook_attacks: u64 = self let rook_attacks: u64 =
.get_rook_attacks_fast(target_square, occupancies_without_white_king); self.get_rook_attacks_fast(target_square, occupancies_without_white_king);
if (self.PIECE_ARRAY[BR] & rook_attacks) != 0 { if (self.PIECE_ARRAY[BR] & rook_attacks) != 0 {
continue; continue;
} }
@@ -681,9 +670,7 @@ impl Engine {
target_square = self.bitscan_forward_separate(temp_captures); target_square = self.bitscan_forward_separate(temp_captures);
temp_captures &= temp_captures - 1; temp_captures &= temp_captures - 1;
if (self.PIECE_ARRAY[BP] & constants::WHITE_PAWN_ATTACKS[target_square]) if (self.PIECE_ARRAY[BP] & constants::WHITE_PAWN_ATTACKS[target_square]) != 0 {
!= 0
{
continue; continue;
} }
if (self.PIECE_ARRAY[BN] & constants::KNIGHT_ATTACKS[target_square]) != 0 { if (self.PIECE_ARRAY[BN] & constants::KNIGHT_ATTACKS[target_square]) != 0 {
@@ -692,16 +679,16 @@ impl Engine {
if (self.PIECE_ARRAY[BK] & constants::KING_ATTACKS[target_square]) != 0 { if (self.PIECE_ARRAY[BK] & constants::KING_ATTACKS[target_square]) != 0 {
continue; continue;
} }
let bishop_attacks: u64 = self let bishop_attacks: u64 =
.get_bishop_attacks_fast(target_square, occupancies_without_white_king); self.get_bishop_attacks_fast(target_square, occupancies_without_white_king);
if (self.PIECE_ARRAY[BB] & bishop_attacks) != 0 { if (self.PIECE_ARRAY[BB] & bishop_attacks) != 0 {
continue; continue;
} }
if (self.PIECE_ARRAY[BQ] & bishop_attacks) != 0 { if (self.PIECE_ARRAY[BQ] & bishop_attacks) != 0 {
continue; continue;
} }
let rook_attacks: u64 = self let rook_attacks: u64 =
.get_rook_attacks_fast(target_square, occupancies_without_white_king); self.get_rook_attacks_fast(target_square, occupancies_without_white_king);
if (self.PIECE_ARRAY[BR] & rook_attacks) != 0 { if (self.PIECE_ARRAY[BR] & rook_attacks) != 0 {
continue; continue;
} }
@@ -717,26 +704,26 @@ impl Engine {
} }
if white_king_check_count == 0 { if white_king_check_count == 0 {
if self.CASTLE_RIGHTS[WKS_CASTLE_RIGHTS] && white_king_position == E1 && (WKS_EMPTY_BITBOARD & combined_occupancies) == 0 && (self.PIECE_ARRAY[WR] & constants::SQUARE_BBS[H1]) != 0 && !self.Is_Square_Attacked_By_Black_Global( if self.CASTLE_RIGHTS[WKS_CASTLE_RIGHTS]
F1, && white_king_position == E1
combined_occupancies, && (WKS_EMPTY_BITBOARD & combined_occupancies) == 0
) && !self.Is_Square_Attacked_By_Black_Global( && (self.PIECE_ARRAY[WR] & constants::SQUARE_BBS[H1]) != 0
G1, && !self.Is_Square_Attacked_By_Black_Global(F1, combined_occupancies)
combined_occupancies, && !self.Is_Square_Attacked_By_Black_Global(G1, combined_occupancies)
) { {
self.STARTING_SQUARES[ply][move_count] = E1; self.STARTING_SQUARES[ply][move_count] = E1;
self.TARGET_SQUARES[ply][move_count] = G1; self.TARGET_SQUARES[ply][move_count] = G1;
self.TAGS[ply][move_count] = TAG_WCASTLEKS; self.TAGS[ply][move_count] = TAG_WCASTLEKS;
self.PIECES[ply][move_count] = WK; self.PIECES[ply][move_count] = WK;
move_count += 1; move_count += 1;
} }
if self.CASTLE_RIGHTS[WQS_CASTLE_RIGHTS] && white_king_position == E1 && (WQS_EMPTY_BITBOARD & combined_occupancies) == 0 && (self.PIECE_ARRAY[WR] & constants::SQUARE_BBS[A1]) != 0 && !self.Is_Square_Attacked_By_Black_Global( if self.CASTLE_RIGHTS[WQS_CASTLE_RIGHTS]
C1, && white_king_position == E1
combined_occupancies, && (WQS_EMPTY_BITBOARD & combined_occupancies) == 0
) && !self.Is_Square_Attacked_By_Black_Global( && (self.PIECE_ARRAY[WR] & constants::SQUARE_BBS[A1]) != 0
D1, && !self.Is_Square_Attacked_By_Black_Global(C1, combined_occupancies)
combined_occupancies, && !self.Is_Square_Attacked_By_Black_Global(D1, combined_occupancies)
) { {
self.STARTING_SQUARES[ply][move_count] = E1; self.STARTING_SQUARES[ply][move_count] = E1;
self.TARGET_SQUARES[ply][move_count] = C1; self.TARGET_SQUARES[ply][move_count] = C1;
self.TAGS[ply][move_count] = TAG_WCASTLEQS; self.TAGS[ply][move_count] = TAG_WCASTLEQS;
@@ -809,8 +796,7 @@ impl Engine {
} }
} }
if (constants::SQUARE_BBS[starting_square - 8] & combined_occupancies) == 0 if (constants::SQUARE_BBS[starting_square - 8] & combined_occupancies) == 0 {
{
//if up one square is empty //if up one square is empty
if ((constants::SQUARE_BBS[starting_square - 8] & check_bitboard) if ((constants::SQUARE_BBS[starting_square - 8] & check_bitboard)
& temp_pin_bitboard) & temp_pin_bitboard)
@@ -916,10 +902,14 @@ impl Engine {
} }
} }
if (constants::SQUARE_BBS[starting_square] & RANK_5_BITBOARD) != 0 && self.EP != NO_SQUARE && (((constants::WHITE_PAWN_ATTACKS[starting_square] if (constants::SQUARE_BBS[starting_square] & RANK_5_BITBOARD) != 0
&& self.EP != NO_SQUARE
&& (((constants::WHITE_PAWN_ATTACKS[starting_square]
& constants::SQUARE_BBS[self.EP]) & constants::SQUARE_BBS[self.EP])
& check_bitboard) & check_bitboard)
& temp_pin_bitboard) != 0 { & temp_pin_bitboard)
!= 0
{
if (self.PIECE_ARRAY[WK] & RANK_5_BITBOARD) == 0 if (self.PIECE_ARRAY[WK] & RANK_5_BITBOARD) == 0
//if no king on rank 5 //if no king on rank 5
{ {
@@ -941,19 +931,17 @@ impl Engine {
//wk and br or bq on rank 5 //wk and br or bq on rank 5
{ {
let mut occupancy_without_ep_pawns: u64 = let mut occupancy_without_ep_pawns: u64 =
combined_occupancies combined_occupancies & (!constants::SQUARE_BBS[starting_square]);
& (!constants::SQUARE_BBS[starting_square]); occupancy_without_ep_pawns &= !constants::SQUARE_BBS[self.EP + 8];
occupancy_without_ep_pawns &=
!constants::SQUARE_BBS[self.EP + 8];
let rook_attacks_from_king: u64 = self let rook_attacks_from_king: u64 = self.get_rook_attacks_fast(
.get_rook_attacks_fast(
white_king_position, white_king_position,
occupancy_without_ep_pawns, occupancy_without_ep_pawns,
); );
if (rook_attacks_from_king & self.PIECE_ARRAY[BR]) == 0 && (rook_attacks_from_king & self.PIECE_ARRAY[BQ]) == 0 { if (rook_attacks_from_king & self.PIECE_ARRAY[BR]) == 0
self.STARTING_SQUARES[ply][move_count] = && (rook_attacks_from_king & self.PIECE_ARRAY[BQ]) == 0
starting_square; {
self.STARTING_SQUARES[ply][move_count] = starting_square;
self.TARGET_SQUARES[ply][move_count] = self.EP; self.TARGET_SQUARES[ply][move_count] = self.EP;
self.TAGS[ply][move_count] = TAG_WHITEEP; self.TAGS[ply][move_count] = TAG_WHITEEP;
self.PIECES[ply][move_count] = WP; self.PIECES[ply][move_count] = WP;
@@ -981,8 +969,8 @@ impl Engine {
let rook_attacks = let rook_attacks =
self.get_rook_attacks_fast(starting_square, combined_occupancies); self.get_rook_attacks_fast(starting_square, combined_occupancies);
temp_attack = ((rook_attacks & black_occupancies) & check_bitboard) temp_attack =
& temp_pin_bitboard; ((rook_attacks & black_occupancies) & check_bitboard) & temp_pin_bitboard;
while temp_attack != 0 { while temp_attack != 0 {
target_square = self.bitscan_forward_separate(temp_attack); target_square = self.bitscan_forward_separate(temp_attack);
temp_attack &= temp_attack - 1; temp_attack &= temp_attack - 1;
@@ -994,8 +982,8 @@ impl Engine {
move_count += 1; move_count += 1;
} }
temp_attack = ((rook_attacks & EMPTY_OCCUPANCIES) & check_bitboard) temp_attack =
& temp_pin_bitboard; ((rook_attacks & EMPTY_OCCUPANCIES) & check_bitboard) & temp_pin_bitboard;
while temp_attack != 0 { while temp_attack != 0 {
target_square = self.bitscan_forward_separate(temp_attack); target_square = self.bitscan_forward_separate(temp_attack);
temp_attack &= temp_attack - 1; temp_attack &= temp_attack - 1;
@@ -1026,8 +1014,8 @@ impl Engine {
let bishop_attacks: u64 = let bishop_attacks: u64 =
self.get_bishop_attacks_fast(starting_square, combined_occupancies); self.get_bishop_attacks_fast(starting_square, combined_occupancies);
temp_attack = ((bishop_attacks & black_occupancies) & check_bitboard) temp_attack =
& temp_pin_bitboard; ((bishop_attacks & black_occupancies) & check_bitboard) & temp_pin_bitboard;
while temp_attack != 0 { while temp_attack != 0 {
target_square = self.bitscan_forward_separate(temp_attack); target_square = self.bitscan_forward_separate(temp_attack);
temp_attack &= temp_attack - 1; temp_attack &= temp_attack - 1;
@@ -1039,8 +1027,8 @@ impl Engine {
move_count += 1; move_count += 1;
} }
temp_attack = ((bishop_attacks & EMPTY_OCCUPANCIES) & check_bitboard) temp_attack =
& temp_pin_bitboard; ((bishop_attacks & EMPTY_OCCUPANCIES) & check_bitboard) & temp_pin_bitboard;
while temp_attack != 0 { while temp_attack != 0 {
target_square = self.bitscan_forward_separate(temp_attack); target_square = self.bitscan_forward_separate(temp_attack);
temp_attack &= temp_attack - 1; temp_attack &= temp_attack - 1;
@@ -1073,8 +1061,8 @@ impl Engine {
queen_attacks |= queen_attacks |=
self.get_bishop_attacks_fast(starting_square, combined_occupancies); self.get_bishop_attacks_fast(starting_square, combined_occupancies);
temp_attack = ((queen_attacks & black_occupancies) & check_bitboard) temp_attack =
& temp_pin_bitboard; ((queen_attacks & black_occupancies) & check_bitboard) & temp_pin_bitboard;
while temp_attack != 0 { while temp_attack != 0 {
target_square = self.bitscan_forward_separate(temp_attack); target_square = self.bitscan_forward_separate(temp_attack);
@@ -1087,8 +1075,8 @@ impl Engine {
move_count += 1; move_count += 1;
} }
temp_attack = ((queen_attacks & EMPTY_OCCUPANCIES) & check_bitboard) temp_attack =
& temp_pin_bitboard; ((queen_attacks & EMPTY_OCCUPANCIES) & check_bitboard) & temp_pin_bitboard;
while temp_attack != 0 { while temp_attack != 0 {
target_square = self.bitscan_forward_separate(temp_attack); target_square = self.bitscan_forward_separate(temp_attack);
temp_attack &= temp_attack - 1; temp_attack &= temp_attack - 1;
@@ -1104,8 +1092,7 @@ impl Engine {
} else { } else {
//black move //black move
let mut black_king_check_count: u8 = 0; let mut black_king_check_count: u8 = 0;
let black_king_position: usize = let black_king_position: usize = self.bitscan_forward_separate(self.PIECE_ARRAY[BK]);
self.bitscan_forward_separate(self.PIECE_ARRAY[BK]);
//pawns //pawns
temp_bitboard = temp_bitboard =
self.PIECE_ARRAY[WP] & constants::BLACK_PAWN_ATTACKS[black_king_position]; self.PIECE_ARRAY[WP] & constants::BLACK_PAWN_ATTACKS[black_king_position];
@@ -1119,8 +1106,7 @@ impl Engine {
} }
//knights //knights
temp_bitboard = temp_bitboard = self.PIECE_ARRAY[WN] & constants::KNIGHT_ATTACKS[black_king_position];
self.PIECE_ARRAY[WN] & constants::KNIGHT_ATTACKS[black_king_position];
if temp_bitboard != 0 { if temp_bitboard != 0 {
let knight_square: usize = self.bitscan_forward_separate(temp_bitboard); let knight_square: usize = self.bitscan_forward_separate(temp_bitboard);
@@ -1186,8 +1172,7 @@ impl Engine {
} }
//rook //rook
let rook_attacks = let rook_attacks = self.get_rook_attacks_fast(black_king_position, white_occupancies);
self.get_rook_attacks_fast(black_king_position, white_occupancies);
temp_bitboard = self.PIECE_ARRAY[WR] & rook_attacks; temp_bitboard = self.PIECE_ARRAY[WR] & rook_attacks;
while temp_bitboard != 0 { while temp_bitboard != 0 {
let piece_square: usize = self.bitscan_forward_separate(temp_bitboard); let piece_square: usize = self.bitscan_forward_separate(temp_bitboard);
@@ -1243,8 +1228,7 @@ impl Engine {
} }
if black_king_check_count > 1 { if black_king_check_count > 1 {
let occupancy_without_black_king = let occupancy_without_black_king = combined_occupancies & (!self.PIECE_ARRAY[BK]);
combined_occupancies & (!self.PIECE_ARRAY[BK]);
temp_attack = constants::KING_ATTACKS[black_king_position] & white_occupancies; temp_attack = constants::KING_ATTACKS[black_king_position] & white_occupancies;
temp_attack = constants::KING_ATTACKS[black_king_position] & white_occupancies; temp_attack = constants::KING_ATTACKS[black_king_position] & white_occupancies;
@@ -1253,9 +1237,7 @@ impl Engine {
target_square = self.bitscan_forward_separate(temp_attack); target_square = self.bitscan_forward_separate(temp_attack);
temp_attack &= temp_attack - 1; temp_attack &= temp_attack - 1;
if (self.PIECE_ARRAY[WP] & constants::BLACK_PAWN_ATTACKS[target_square]) if (self.PIECE_ARRAY[WP] & constants::BLACK_PAWN_ATTACKS[target_square]) != 0 {
!= 0
{
continue; continue;
} }
if (self.PIECE_ARRAY[WN] & constants::KNIGHT_ATTACKS[target_square]) != 0 { if (self.PIECE_ARRAY[WN] & constants::KNIGHT_ATTACKS[target_square]) != 0 {
@@ -1264,8 +1246,8 @@ impl Engine {
if (self.PIECE_ARRAY[WK] & constants::KING_ATTACKS[target_square]) != 0 { if (self.PIECE_ARRAY[WK] & constants::KING_ATTACKS[target_square]) != 0 {
continue; continue;
} }
let bishop_attacks = self let bishop_attacks =
.get_bishop_attacks_fast(target_square, occupancy_without_black_king); self.get_bishop_attacks_fast(target_square, occupancy_without_black_king);
if (self.PIECE_ARRAY[WB] & bishop_attacks) != 0 { if (self.PIECE_ARRAY[WB] & bishop_attacks) != 0 {
continue; continue;
} }
@@ -1288,16 +1270,13 @@ impl Engine {
move_count += 1; move_count += 1;
} }
temp_attack = temp_attack = constants::KING_ATTACKS[black_king_position] & !combined_occupancies;
constants::KING_ATTACKS[black_king_position] & !combined_occupancies;
while temp_attack != 0 { while temp_attack != 0 {
target_square = self.bitscan_forward_separate(temp_attack); target_square = self.bitscan_forward_separate(temp_attack);
temp_attack &= temp_attack - 1; temp_attack &= temp_attack - 1;
if (self.PIECE_ARRAY[WP] & constants::WHITE_PAWN_ATTACKS[target_square]) if (self.PIECE_ARRAY[WP] & constants::WHITE_PAWN_ATTACKS[target_square]) != 0 {
!= 0
{
continue; continue;
} }
if (self.PIECE_ARRAY[WN] & constants::KNIGHT_ATTACKS[target_square]) != 0 { if (self.PIECE_ARRAY[WN] & constants::KNIGHT_ATTACKS[target_square]) != 0 {
@@ -1306,8 +1285,8 @@ impl Engine {
if (self.PIECE_ARRAY[WK] & constants::KING_ATTACKS[target_square]) != 0 { if (self.PIECE_ARRAY[WK] & constants::KING_ATTACKS[target_square]) != 0 {
continue; continue;
} }
let bishop_attacks = self let bishop_attacks =
.get_bishop_attacks_fast(target_square, occupancy_without_black_king); self.get_bishop_attacks_fast(target_square, occupancy_without_black_king);
if (self.PIECE_ARRAY[WB] & bishop_attacks) != 0 { if (self.PIECE_ARRAY[WB] & bishop_attacks) != 0 {
continue; continue;
} }
@@ -1392,9 +1371,14 @@ impl Engine {
} }
} }
if (constants::SQUARE_BBS[starting_square] & RANK_7_BITBOARD) != 0 && ((constants::SQUARE_BBS[starting_square + 16] & check_bitboard) if (constants::SQUARE_BBS[starting_square] & RANK_7_BITBOARD) != 0
& temp_pin_bitboard) != 0 && ((constants::SQUARE_BBS[starting_square + 16]) && ((constants::SQUARE_BBS[starting_square + 16] & check_bitboard)
& combined_occupancies) == 0 { & temp_pin_bitboard)
!= 0
&& ((constants::SQUARE_BBS[starting_square + 16])
& combined_occupancies)
== 0
{
self.STARTING_SQUARES[ply][move_count] = starting_square; self.STARTING_SQUARES[ply][move_count] = starting_square;
self.TARGET_SQUARES[ply][move_count] = starting_square + 16; self.TARGET_SQUARES[ply][move_count] = starting_square + 16;
self.TAGS[ply][move_count] = TAG_DOUBLE_PAWN_BLACK; self.TAGS[ply][move_count] = TAG_DOUBLE_PAWN_BLACK;
@@ -1447,10 +1431,14 @@ impl Engine {
} }
} }
if (constants::SQUARE_BBS[starting_square] & RANK_4_BITBOARD) != 0 && self.EP != NO_SQUARE && (((constants::BLACK_PAWN_ATTACKS[starting_square] if (constants::SQUARE_BBS[starting_square] & RANK_4_BITBOARD) != 0
&& self.EP != NO_SQUARE
&& (((constants::BLACK_PAWN_ATTACKS[starting_square]
& constants::SQUARE_BBS[self.EP]) & constants::SQUARE_BBS[self.EP])
& check_bitboard) & check_bitboard)
& temp_pin_bitboard) != 0 { & temp_pin_bitboard)
!= 0
{
if (self.PIECE_ARRAY[BK] & RANK_4_BITBOARD) == 0 if (self.PIECE_ARRAY[BK] & RANK_4_BITBOARD) == 0
//if no king on rank 5 //if no king on rank 5
{ {
@@ -1472,18 +1460,17 @@ impl Engine {
//wk and br or bq on rank 5 //wk and br or bq on rank 5
{ {
let mut occupancy_without_ep_pawns: u64 = let mut occupancy_without_ep_pawns: u64 =
combined_occupancies combined_occupancies & !constants::SQUARE_BBS[starting_square];
& !constants::SQUARE_BBS[starting_square]; occupancy_without_ep_pawns &= !constants::SQUARE_BBS[self.EP - 8];
occupancy_without_ep_pawns &=
!constants::SQUARE_BBS[self.EP - 8];
let rook_attacks_from_king = self.get_rook_attacks_fast( let rook_attacks_from_king = self.get_rook_attacks_fast(
black_king_position, black_king_position,
occupancy_without_ep_pawns, occupancy_without_ep_pawns,
); );
if (rook_attacks_from_king & self.PIECE_ARRAY[WR]) == 0 && (rook_attacks_from_king & self.PIECE_ARRAY[WQ]) == 0 { if (rook_attacks_from_king & self.PIECE_ARRAY[WR]) == 0
self.STARTING_SQUARES[ply][move_count] = && (rook_attacks_from_king & self.PIECE_ARRAY[WQ]) == 0
starting_square; {
self.STARTING_SQUARES[ply][move_count] = starting_square;
self.TARGET_SQUARES[ply][move_count] = self.EP; self.TARGET_SQUARES[ply][move_count] = self.EP;
self.TAGS[ply][move_count] = TAG_BLACKEP; self.TAGS[ply][move_count] = TAG_BLACKEP;
self.PIECES[ply][move_count] = BP; self.PIECES[ply][move_count] = BP;
@@ -1559,8 +1546,8 @@ impl Engine {
let bishop_attacks = let bishop_attacks =
self.get_bishop_attacks_fast(starting_square, combined_occupancies); self.get_bishop_attacks_fast(starting_square, combined_occupancies);
temp_attack = ((bishop_attacks & white_occupancies) & check_bitboard) temp_attack =
& temp_pin_bitboard; ((bishop_attacks & white_occupancies) & check_bitboard) & temp_pin_bitboard;
while temp_attack != 0 { while temp_attack != 0 {
target_square = self.bitscan_forward_separate(temp_attack); target_square = self.bitscan_forward_separate(temp_attack);
temp_attack &= temp_attack - 1; temp_attack &= temp_attack - 1;
@@ -1604,8 +1591,8 @@ impl Engine {
let rook_attacks = let rook_attacks =
self.get_rook_attacks_fast(starting_square, combined_occupancies); self.get_rook_attacks_fast(starting_square, combined_occupancies);
temp_attack = ((rook_attacks & white_occupancies) & check_bitboard) temp_attack =
& temp_pin_bitboard; ((rook_attacks & white_occupancies) & check_bitboard) & temp_pin_bitboard;
while temp_attack != 0 { while temp_attack != 0 {
target_square = self.bitscan_forward_separate(temp_attack); target_square = self.bitscan_forward_separate(temp_attack);
temp_attack &= temp_attack - 1; temp_attack &= temp_attack - 1;
@@ -1651,8 +1638,8 @@ impl Engine {
queen_attacks |= queen_attacks |=
self.get_bishop_attacks_fast(starting_square, combined_occupancies); self.get_bishop_attacks_fast(starting_square, combined_occupancies);
temp_attack = ((queen_attacks & white_occupancies) & check_bitboard) temp_attack =
& temp_pin_bitboard; ((queen_attacks & white_occupancies) & check_bitboard) & temp_pin_bitboard;
while temp_attack != 0 { while temp_attack != 0 {
target_square = self.bitscan_forward_separate(temp_attack); target_square = self.bitscan_forward_separate(temp_attack);
@@ -1684,9 +1671,7 @@ impl Engine {
target_square = self.bitscan_forward_separate(temp_attack); target_square = self.bitscan_forward_separate(temp_attack);
temp_attack &= temp_attack - 1; temp_attack &= temp_attack - 1;
if (self.PIECE_ARRAY[WP] & constants::BLACK_PAWN_ATTACKS[target_square]) if (self.PIECE_ARRAY[WP] & constants::BLACK_PAWN_ATTACKS[target_square]) != 0 {
!= 0
{
continue; continue;
} }
if (self.PIECE_ARRAY[WN] & constants::KNIGHT_ATTACKS[target_square]) != 0 { if (self.PIECE_ARRAY[WN] & constants::KNIGHT_ATTACKS[target_square]) != 0 {
@@ -1697,8 +1682,8 @@ impl Engine {
} }
let occupancy_without_black_king = let occupancy_without_black_king =
combined_occupancies & (!self.PIECE_ARRAY[BK]); combined_occupancies & (!self.PIECE_ARRAY[BK]);
let bishop_attacks = self let bishop_attacks =
.get_bishop_attacks_fast(target_square, occupancy_without_black_king); self.get_bishop_attacks_fast(target_square, occupancy_without_black_king);
if (self.PIECE_ARRAY[WB] & bishop_attacks) != 0 { if (self.PIECE_ARRAY[WB] & bishop_attacks) != 0 {
continue; continue;
} }
@@ -1727,9 +1712,7 @@ impl Engine {
target_square = self.bitscan_forward_separate(temp_attack); target_square = self.bitscan_forward_separate(temp_attack);
temp_attack &= temp_attack - 1; temp_attack &= temp_attack - 1;
if (self.PIECE_ARRAY[WP] & constants::BLACK_PAWN_ATTACKS[target_square]) if (self.PIECE_ARRAY[WP] & constants::BLACK_PAWN_ATTACKS[target_square]) != 0 {
!= 0
{
continue; continue;
} }
if (self.PIECE_ARRAY[WN] & constants::KNIGHT_ATTACKS[target_square]) != 0 { if (self.PIECE_ARRAY[WN] & constants::KNIGHT_ATTACKS[target_square]) != 0 {
@@ -1740,8 +1723,8 @@ impl Engine {
} }
let occupancy_without_black_king = let occupancy_without_black_king =
combined_occupancies & (!self.PIECE_ARRAY[BK]); combined_occupancies & (!self.PIECE_ARRAY[BK]);
let bishop_attacks = self let bishop_attacks =
.get_bishop_attacks_fast(target_square, occupancy_without_black_king); self.get_bishop_attacks_fast(target_square, occupancy_without_black_king);
if (self.PIECE_ARRAY[WB] & bishop_attacks) != 0 { if (self.PIECE_ARRAY[WB] & bishop_attacks) != 0 {
continue; continue;
} }
@@ -1765,26 +1748,26 @@ impl Engine {
} }
} }
if black_king_check_count == 0 { if black_king_check_count == 0 {
if self.CASTLE_RIGHTS[BKS_CASTLE_RIGHTS] && black_king_position == E8 && (BKS_EMPTY_BITBOARD & combined_occupancies) == 0 && (self.PIECE_ARRAY[BR] & constants::SQUARE_BBS[H8]) != 0 && !self.Is_Square_Attacked_By_White_Global( if self.CASTLE_RIGHTS[BKS_CASTLE_RIGHTS]
F8, && black_king_position == E8
combined_occupancies, && (BKS_EMPTY_BITBOARD & combined_occupancies) == 0
) && !self.Is_Square_Attacked_By_White_Global( && (self.PIECE_ARRAY[BR] & constants::SQUARE_BBS[H8]) != 0
G8, && !self.Is_Square_Attacked_By_White_Global(F8, combined_occupancies)
combined_occupancies, && !self.Is_Square_Attacked_By_White_Global(G8, combined_occupancies)
) { {
self.STARTING_SQUARES[ply][move_count] = E8; self.STARTING_SQUARES[ply][move_count] = E8;
self.TARGET_SQUARES[ply][move_count] = G8; self.TARGET_SQUARES[ply][move_count] = G8;
self.TAGS[ply][move_count] = TAG_BCASTLEKS; self.TAGS[ply][move_count] = TAG_BCASTLEKS;
self.PIECES[ply][move_count] = BK; self.PIECES[ply][move_count] = BK;
move_count += 1; move_count += 1;
} }
if self.CASTLE_RIGHTS[BQS_CASTLE_RIGHTS] && black_king_position == E8 && (BQS_EMPTY_BITBOARD & combined_occupancies) == 0 && (self.PIECE_ARRAY[BR] & constants::SQUARE_BBS[A8]) != 0 && !self.Is_Square_Attacked_By_White_Global( if self.CASTLE_RIGHTS[BQS_CASTLE_RIGHTS]
C8, && black_king_position == E8
combined_occupancies, && (BQS_EMPTY_BITBOARD & combined_occupancies) == 0
) && !self.Is_Square_Attacked_By_White_Global( && (self.PIECE_ARRAY[BR] & constants::SQUARE_BBS[A8]) != 0
D8, && !self.Is_Square_Attacked_By_White_Global(C8, combined_occupancies)
combined_occupancies, && !self.Is_Square_Attacked_By_White_Global(D8, combined_occupancies)
) { {
self.STARTING_SQUARES[ply][move_count] = E8; self.STARTING_SQUARES[ply][move_count] = E8;
self.TARGET_SQUARES[ply][move_count] = C8; self.TARGET_SQUARES[ply][move_count] = C8;
self.TAGS[ply][move_count] = TAG_BCASTLEQS; self.TAGS[ply][move_count] = TAG_BCASTLEQS;
@@ -1832,8 +1815,7 @@ impl Engine {
self.PIECE_ARRAY[piece] &= !constants::SQUARE_BBS[starting_square]; self.PIECE_ARRAY[piece] &= !constants::SQUARE_BBS[starting_square];
if piece <= WK { if piece <= WK {
for i in BP..BK + 1 { for i in BP..BK + 1 {
if (self.PIECE_ARRAY[i] & constants::SQUARE_BBS[target_square]) != 0 if (self.PIECE_ARRAY[i] & constants::SQUARE_BBS[target_square]) != 0 {
{
capture_index = i; capture_index = i;
break; break;
} }
@@ -1843,14 +1825,12 @@ impl Engine {
//is black //is black
for i in WP..BP { for i in WP..BP {
if (self.PIECE_ARRAY[i] & constants::SQUARE_BBS[target_square]) != 0 if (self.PIECE_ARRAY[i] & constants::SQUARE_BBS[target_square]) != 0 {
{
capture_index = i; capture_index = i;
break; break;
} }
} }
self.PIECE_ARRAY[capture_index] &= self.PIECE_ARRAY[capture_index] &= !constants::SQUARE_BBS[target_square];
!constants::SQUARE_BBS[target_square];
} }
self.EP = NO_SQUARE; self.EP = NO_SQUARE;
} }
@@ -2096,17 +2076,25 @@ impl Engine {
self.CASTLE_RIGHTS[BKS_CASTLE_RIGHTS] = false; self.CASTLE_RIGHTS[BKS_CASTLE_RIGHTS] = false;
self.CASTLE_RIGHTS[BQS_CASTLE_RIGHTS] = false; self.CASTLE_RIGHTS[BQS_CASTLE_RIGHTS] = false;
} else if piece == WR { } else if piece == WR {
if self.CASTLE_RIGHTS[WKS_CASTLE_RIGHTS] && (self.PIECE_ARRAY[WR] & constants::SQUARE_BBS[H1]) == 0 { if self.CASTLE_RIGHTS[WKS_CASTLE_RIGHTS]
&& (self.PIECE_ARRAY[WR] & constants::SQUARE_BBS[H1]) == 0
{
self.CASTLE_RIGHTS[WKS_CASTLE_RIGHTS] = false; self.CASTLE_RIGHTS[WKS_CASTLE_RIGHTS] = false;
} }
if self.CASTLE_RIGHTS[WQS_CASTLE_RIGHTS] && (self.PIECE_ARRAY[WR] & constants::SQUARE_BBS[A1]) == 0 { if self.CASTLE_RIGHTS[WQS_CASTLE_RIGHTS]
&& (self.PIECE_ARRAY[WR] & constants::SQUARE_BBS[A1]) == 0
{
self.CASTLE_RIGHTS[WQS_CASTLE_RIGHTS] = false; self.CASTLE_RIGHTS[WQS_CASTLE_RIGHTS] = false;
} }
} else if piece == BR { } else if piece == BR {
if self.CASTLE_RIGHTS[BKS_CASTLE_RIGHTS] && (self.PIECE_ARRAY[BR] & constants::SQUARE_BBS[H8]) == 0 { if self.CASTLE_RIGHTS[BKS_CASTLE_RIGHTS]
&& (self.PIECE_ARRAY[BR] & constants::SQUARE_BBS[H8]) == 0
{
self.CASTLE_RIGHTS[BKS_CASTLE_RIGHTS] = false; self.CASTLE_RIGHTS[BKS_CASTLE_RIGHTS] = false;
} }
if self.CASTLE_RIGHTS[BQS_CASTLE_RIGHTS] && (self.PIECE_ARRAY[BR] & constants::SQUARE_BBS[A8]) == 0 { if self.CASTLE_RIGHTS[BQS_CASTLE_RIGHTS]
&& (self.PIECE_ARRAY[BR] & constants::SQUARE_BBS[A8]) == 0
{
self.CASTLE_RIGHTS[BQS_CASTLE_RIGHTS] = false; self.CASTLE_RIGHTS[BQS_CASTLE_RIGHTS] = false;
} }
} }
@@ -2303,7 +2291,6 @@ impl Engine {
nodes nodes
} }
}
fn run_perft(&mut self, depth: i8) { fn run_perft(&mut self, depth: i8) {
let timestamp_start = Instant::now(); let timestamp_start = Instant::now();