From b06fd03362ba688c631abcc011242a2449f49a2f Mon Sep 17 00:00:00 2001 From: Coding with Tom <146443103+hcsalmon1@users.noreply.github.com> Date: Mon, 20 Jan 2025 17:22:59 +0000 Subject: [PATCH] Update main.zig removed unnecessary if statements and made move_list 50 --- Zig/main.zig | 2033 +++++++++++++++++++++----------------------------- 1 file changed, 870 insertions(+), 1163 deletions(-) diff --git a/Zig/main.zig b/Zig/main.zig index 86bba97..443e5ed 100644 --- a/Zig/main.zig +++ b/Zig/main.zig @@ -1102,19 +1102,19 @@ fn PrMoveNoNL(starting_square:usize, target_square:usize) void { //starting } } -fn PerftInlineGlobalOcc(depth:i8, ply:u8) usize { +fn perftInline(depth:i8, ply:u8) usize { //if (depth == 0) //{ // return 1; //} - var move_list:[250][4]usize = undefined; + var move_list:[50][4]usize = undefined; var move_count:usize = 0; //Move generating variables - const WHITE_OCCUPANCIES_LOCAL:u64 = bitboard_array_global[0] | bitboard_array_global[1] | bitboard_array_global[2] | bitboard_array_global[3] | bitboard_array_global[4] | bitboard_array_global[5]; - const BLACK_OCCUPANCIES_LOCAL:u64 = bitboard_array_global[6] | bitboard_array_global[7] | bitboard_array_global[8] | bitboard_array_global[9] | bitboard_array_global[10] | bitboard_array_global[11]; + const WHITE_OCCUPANCIES_LOCAL:u64 = board.bitboard_array_global[0] | board.bitboard_array_global[1] | board.bitboard_array_global[2] | board.bitboard_array_global[3] | board.bitboard_array_global[4] | board.bitboard_array_global[5]; + const BLACK_OCCUPANCIES_LOCAL:u64 = board.bitboard_array_global[6] | board.bitboard_array_global[7] | board.bitboard_array_global[8] | board.bitboard_array_global[9] | board.bitboard_array_global[10] | board.bitboard_array_global[11]; const COMBINED_OCCUPANCIES_LOCAL:u64 = WHITE_OCCUPANCIES_LOCAL | BLACK_OCCUPANCIES_LOCAL; const EMPTY_OCCUPANCIES:u64 = ~COMBINED_OCCUPANCIES_LOCAL; var temp_bitboard:u64 = undefined; @@ -1123,69 +1123,61 @@ fn PerftInlineGlobalOcc(depth:i8, ply:u8) usize { var temp_attack:u64 = undefined; var temp_empty:u64 = undefined; var temp_captures:u64 = undefined; - var starting_square:usize = NO_SQUARE; - var target_square:usize = NO_SQUARE; + var starting_square:usize = gen_const.NO_SQUARE; + var target_square:usize = gen_const.NO_SQUARE; var pinArray:[8][2]usize = [8][2]usize { - [_]usize{ NO_SQUARE, NO_SQUARE }, - [_]usize{ NO_SQUARE, NO_SQUARE }, - [_]usize{ NO_SQUARE, NO_SQUARE }, - [_]usize{ NO_SQUARE, NO_SQUARE }, - [_]usize{ NO_SQUARE, NO_SQUARE }, - [_]usize{ NO_SQUARE, NO_SQUARE }, - [_]usize{ NO_SQUARE, NO_SQUARE }, - [_]usize{ NO_SQUARE, NO_SQUARE}, + .{ gen_const.NO_SQUARE, gen_const.NO_SQUARE }, + .{ gen_const.NO_SQUARE, gen_const.NO_SQUARE }, + .{ gen_const.NO_SQUARE, gen_const.NO_SQUARE }, + .{ gen_const.NO_SQUARE, gen_const.NO_SQUARE }, + .{ gen_const.NO_SQUARE, gen_const.NO_SQUARE }, + .{ gen_const.NO_SQUARE, gen_const.NO_SQUARE }, + .{ gen_const.NO_SQUARE, gen_const.NO_SQUARE }, + .{ gen_const.NO_SQUARE, gen_const.NO_SQUARE}, }; var pinNumber:usize = 0; - if (is_white_global == true) - { + if (board.is_white_global == true) { var whiteKingCheckCount:usize = 0; - const whiteKingPosition:usize = (DEBRUIJN64[MAGIC *% (bitboard_array_global[WK] ^ (bitboard_array_global[WK] - 1)) >> 58]); + const whiteKingPosition:usize = gen_const.DEBRUIJN64[gen_const.MAGIC *% (board.bitboard_array_global[gen_const.WK] ^ (board.bitboard_array_global[gen_const.WK] - 1)) >> 58]; //pawns - temp_bitboard = bitboard_array_global[BP] & WHITE_PAWN_ATTACKS[whiteKingPosition]; + temp_bitboard = board.bitboard_array_global[gen_const.BP] & move_constants.WHITE_PAWN_ATTACKS[whiteKingPosition]; if (temp_bitboard != 0) { - const pawn_square:usize = @intCast(DEBRUIJN64[MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]); - if (check_bitboard == 0) { - check_bitboard = SQUARE_BBS[pawn_square]; - } + const pawn_square:usize = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]; + check_bitboard = move_constants.SQUARE_BBS[pawn_square]; whiteKingCheckCount+=1; } //knights - temp_bitboard = bitboard_array_global[BN] & KNIGHT_ATTACKS[whiteKingPosition]; + temp_bitboard = board.bitboard_array_global[gen_const.BN] & move_constants.KNIGHT_ATTACKS[whiteKingPosition]; if (temp_bitboard != 0) { - const knight_square = (DEBRUIJN64[MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]); - if (knight_square != -1) { - if (check_bitboard == 0) { - check_bitboard = SQUARE_BBS[knight_square]; - } - } + const knight_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]; + check_bitboard = move_constants.SQUARE_BBS[knight_square]; + whiteKingCheckCount+=1; } //bishops - const bishopAttacksChecks = GetBishopAttacksFast(whiteKingPosition, BLACK_OCCUPANCIES_LOCAL); - temp_bitboard = bitboard_array_global[BB] & bishopAttacksChecks; + const bishopAttacksChecks = gen_moves.getBishopAttacksFast(whiteKingPosition, BLACK_OCCUPANCIES_LOCAL); + temp_bitboard = board.bitboard_array_global[gen_const.BB] & bishopAttacksChecks; while (temp_bitboard != 0) { - const piece_square = (DEBRUIJN64[MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]); + const piece_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]; temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[whiteKingPosition][piece_square] & WHITE_OCCUPANCIES_LOCAL; if (temp_pin_bitboard == 0) { - if (check_bitboard == 0) { - check_bitboard = constants.INBETWEEN_BITBOARDS[whiteKingPosition][piece_square]; - } + check_bitboard = constants.INBETWEEN_BITBOARDS[whiteKingPosition][piece_square]; whiteKingCheckCount+=1; } else { - const pinned_square = (DEBRUIJN64[MAGIC *% (temp_pin_bitboard ^ (temp_pin_bitboard - 1)) >> 58]); + const pinned_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_pin_bitboard ^ (temp_pin_bitboard - 1)) >> 58]; temp_pin_bitboard &= temp_pin_bitboard - 1; if (temp_pin_bitboard == 0) { - pinArray[pinNumber][PINNED_SQUARE_INDEX] = pinned_square; - pinArray[pinNumber][PINNING_PIECE_INDEX] = piece_square; + pinArray[pinNumber][gen_const.PINNED_SQUARE_INDEX] = pinned_square; + pinArray[pinNumber][gen_const.PINNING_PIECE_INDEX] = piece_square; pinNumber+=1; } } @@ -1193,24 +1185,22 @@ fn PerftInlineGlobalOcc(depth:i8, ply:u8) usize { } //queen - temp_bitboard = bitboard_array_global[BQ] & bishopAttacksChecks; + temp_bitboard = board.bitboard_array_global[gen_const.BQ] & bishopAttacksChecks; while (temp_bitboard != 0) { - const piece_square = (DEBRUIJN64[MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]); + const piece_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]; temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[whiteKingPosition][piece_square] & WHITE_OCCUPANCIES_LOCAL; if (temp_pin_bitboard == 0) { - if (check_bitboard == 0) { - check_bitboard = constants.INBETWEEN_BITBOARDS[whiteKingPosition][piece_square]; - } + check_bitboard = constants.INBETWEEN_BITBOARDS[whiteKingPosition][piece_square]; whiteKingCheckCount+=1; } else { - const pinned_square = (DEBRUIJN64[MAGIC *% (temp_pin_bitboard ^ (temp_pin_bitboard - 1)) >> 58]); + const pinned_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_pin_bitboard ^ (temp_pin_bitboard - 1)) >> 58]; temp_pin_bitboard &= temp_pin_bitboard - 1; if (temp_pin_bitboard == 0) { - pinArray[pinNumber][PINNED_SQUARE_INDEX] = pinned_square; - pinArray[pinNumber][PINNING_PIECE_INDEX] = piece_square; + pinArray[pinNumber][gen_const.PINNED_SQUARE_INDEX] = pinned_square; + pinArray[pinNumber][gen_const.PINNING_PIECE_INDEX] = piece_square; pinNumber+=1; } } @@ -1218,25 +1208,23 @@ fn PerftInlineGlobalOcc(depth:i8, ply:u8) usize { } //rook - const rook_attacks = GetRookAttacksFast(whiteKingPosition, BLACK_OCCUPANCIES_LOCAL); - temp_bitboard = bitboard_array_global[BR] & rook_attacks; + const rook_attacks = gen_moves.getRookAttacksFast(whiteKingPosition, BLACK_OCCUPANCIES_LOCAL); + temp_bitboard = board.bitboard_array_global[gen_const.BR] & rook_attacks; while (temp_bitboard != 0) { - const piece_square = (DEBRUIJN64[MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]); + const piece_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]; temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[whiteKingPosition][piece_square] & WHITE_OCCUPANCIES_LOCAL; if (temp_pin_bitboard == 0) { - if (check_bitboard == 0) { - check_bitboard = constants.INBETWEEN_BITBOARDS[whiteKingPosition][piece_square]; - } + check_bitboard = constants.INBETWEEN_BITBOARDS[whiteKingPosition][piece_square]; whiteKingCheckCount+=1; } else { - const pinned_square = (DEBRUIJN64[MAGIC *% (temp_pin_bitboard ^ (temp_pin_bitboard - 1)) >> 58]); + const pinned_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_pin_bitboard ^ (temp_pin_bitboard - 1)) >> 58]; temp_pin_bitboard &= temp_pin_bitboard - 1; if (temp_pin_bitboard == 0) { - pinArray[pinNumber][PINNED_SQUARE_INDEX] = pinned_square; - pinArray[pinNumber][PINNING_PIECE_INDEX] = piece_square; + pinArray[pinNumber][gen_const.PINNED_SQUARE_INDEX] = pinned_square; + pinArray[pinNumber][gen_const.PINNING_PIECE_INDEX] = piece_square; pinNumber+=1; } } @@ -1244,249 +1232,195 @@ fn PerftInlineGlobalOcc(depth:i8, ply:u8) usize { } //queen - temp_bitboard = bitboard_array_global[BQ] & rook_attacks; + temp_bitboard = board.bitboard_array_global[gen_const.BQ] & rook_attacks; while (temp_bitboard != 0) { - const piece_square = (DEBRUIJN64[MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]); - if (piece_square == -1) - { - break; - } + const piece_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]; temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[whiteKingPosition][piece_square] & WHITE_OCCUPANCIES_LOCAL; - if (temp_pin_bitboard == 0) - { - if (check_bitboard == 0) - { - check_bitboard = constants.INBETWEEN_BITBOARDS[whiteKingPosition][piece_square]; - } + if (temp_pin_bitboard == 0) { + check_bitboard = constants.INBETWEEN_BITBOARDS[whiteKingPosition][piece_square]; whiteKingCheckCount+=1; - } - else - { - const pinned_square = (DEBRUIJN64[MAGIC *% (temp_pin_bitboard ^ (temp_pin_bitboard - 1)) >> 58]); + } else { + const pinned_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_pin_bitboard ^ (temp_pin_bitboard - 1)) >> 58]; temp_pin_bitboard &= temp_pin_bitboard - 1; - if (temp_pin_bitboard == 0) - { - pinArray[pinNumber][PINNED_SQUARE_INDEX] = pinned_square; - pinArray[pinNumber][PINNING_PIECE_INDEX] = piece_square; + if (temp_pin_bitboard == 0) { + pinArray[pinNumber][gen_const.PINNED_SQUARE_INDEX] = pinned_square; + pinArray[pinNumber][gen_const.PINNING_PIECE_INDEX] = piece_square; pinNumber+=1; } } temp_bitboard &= temp_bitboard - 1; } - - if (whiteKingCheckCount > 1) - { - const occupanciesWithoutWhiteKing = COMBINED_OCCUPANCIES_LOCAL & (~bitboard_array_global[WK]); - temp_attack = KING_ATTACKS[whiteKingPosition]; + + if (whiteKingCheckCount > 1) { + const occupanciesWithoutWhiteKing = COMBINED_OCCUPANCIES_LOCAL & (~board.bitboard_array_global[gen_const.WK]); + temp_attack = move_constants.KING_ATTACKS[whiteKingPosition]; temp_empty = temp_attack & EMPTY_OCCUPANCIES; - while (temp_empty != 0) - { - target_square = (DEBRUIJN64[MAGIC *% (temp_empty ^ (temp_empty - 1)) >> 58]); + while (temp_empty != 0) { + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_empty ^ (temp_empty - 1)) >> 58]; temp_empty &= temp_empty - 1; - if ((bitboard_array_global[BP] & WHITE_PAWN_ATTACKS[target_square]) != 0) - { + if ((board.bitboard_array_global[gen_const.BP] & move_constants.WHITE_PAWN_ATTACKS[target_square]) != 0) { continue; } - if ((bitboard_array_global[BN] & KNIGHT_ATTACKS[target_square]) != 0) - { + if ((board.bitboard_array_global[gen_const.BN] & move_constants.KNIGHT_ATTACKS[target_square]) != 0) { continue; } - if ((bitboard_array_global[BK] & KING_ATTACKS[target_square]) != 0) - { + if ((board.bitboard_array_global[gen_const.BK] & move_constants.KING_ATTACKS[target_square]) != 0) { continue; } - const bishopAttacks = GetBishopAttacksFast(target_square, occupanciesWithoutWhiteKing); - if ((bitboard_array_global[BB] & bishopAttacks) != 0) - { + const bishopAttacks = gen_moves.getBishopAttacksFast(target_square, occupanciesWithoutWhiteKing); + if ((board.bitboard_array_global[gen_const.BB] & bishopAttacks) != 0) { continue; } - if ((bitboard_array_global[BQ] & bishopAttacks) != 0) - { + if ((board.bitboard_array_global[gen_const.BQ] & bishopAttacks) != 0) { continue; } - const rookAttacks = GetRookAttacksFast(target_square, occupanciesWithoutWhiteKing); - if ((bitboard_array_global[BR] & rookAttacks) != 0) - { + const rookAttacks = gen_moves.getRookAttacksFast(target_square, occupanciesWithoutWhiteKing); + if ((board.bitboard_array_global[gen_const.BR] & rookAttacks) != 0) { continue; } - if ((bitboard_array_global[BQ] & rookAttacks) != 0) - { + if ((board.bitboard_array_global[gen_const.BQ] & rookAttacks) != 0) { continue; } - move_list[move_count][MOVE_STARTING] = whiteKingPosition; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_NONE; - move_list[move_count][MOVE_PIECE] = WK; + move_list[move_count][gen_const.MOVE_STARTING] = whiteKingPosition; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_NONE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WK; move_count+=1; } //captures temp_captures = temp_attack & BLACK_OCCUPANCIES_LOCAL; - while (temp_captures != 0) - { - target_square = (DEBRUIJN64[MAGIC *% (temp_captures ^ (temp_captures - 1)) >> 58]); + while (temp_captures != 0) { + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_captures ^ (temp_captures - 1)) >> 58]; temp_captures &= temp_captures - 1; - if ((bitboard_array_global[BP] & WHITE_PAWN_ATTACKS[target_square]) != 0) - { + if ((board.bitboard_array_global[gen_const.BP] & move_constants.WHITE_PAWN_ATTACKS[target_square]) != 0) { continue; } - if ((bitboard_array_global[BN] & KNIGHT_ATTACKS[target_square]) != 0) - { + if ((board.bitboard_array_global[gen_const.BN] & move_constants.KNIGHT_ATTACKS[target_square]) != 0) { continue; } - if ((bitboard_array_global[BK] & KING_ATTACKS[target_square]) != 0) - { + if ((board.bitboard_array_global[gen_const.BK] & move_constants.KING_ATTACKS[target_square]) != 0) { continue; } - const bishopAttacks = GetBishopAttacksFast(target_square, occupanciesWithoutWhiteKing); - if ((bitboard_array_global[BB] & bishopAttacks) != 0) - { + const bishopAttacks = gen_moves.getBishopAttacksFast(target_square, occupanciesWithoutWhiteKing); + if ((board.bitboard_array_global[gen_const.BB] & bishopAttacks) != 0) { continue; } - if ((bitboard_array_global[BQ] & bishopAttacks) != 0) - { + if ((board.bitboard_array_global[gen_const.BQ] & bishopAttacks) != 0) { continue; } - const rookAttacks = GetRookAttacksFast(target_square, occupanciesWithoutWhiteKing); - if ((bitboard_array_global[BR] & rookAttacks) != 0) - { + const rookAttacks = gen_moves.getRookAttacksFast(target_square, occupanciesWithoutWhiteKing); + if ((board.bitboard_array_global[gen_const.BR] & rookAttacks) != 0) { continue; } - if ((bitboard_array_global[BQ] & rookAttacks) != 0) - { + if ((board.bitboard_array_global[gen_const.BQ] & rookAttacks) != 0) { continue; } - move_list[move_count][MOVE_STARTING] = whiteKingPosition; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_CAPTURE; - move_list[move_count][MOVE_PIECE] = WK; + move_list[move_count][gen_const.MOVE_STARTING] = whiteKingPosition; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_CAPTURE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WK; move_count+=1; } - } - else - { + } else { - if (whiteKingCheckCount == 0) - { - check_bitboard = MAX_ULONG; + if (whiteKingCheckCount == 0) { + check_bitboard = gen_const.MAX_ULONG; } - const occupanciesWithoutWhiteKing = COMBINED_OCCUPANCIES_LOCAL & (~bitboard_array_global[WK]); - temp_attack = KING_ATTACKS[whiteKingPosition]; + const occupanciesWithoutWhiteKing = COMBINED_OCCUPANCIES_LOCAL & (~board.bitboard_array_global[gen_const.WK]); + temp_attack = move_constants.KING_ATTACKS[whiteKingPosition]; temp_empty = temp_attack & EMPTY_OCCUPANCIES; - while (temp_empty != 0) - { - target_square = (DEBRUIJN64[MAGIC *% (temp_empty ^ (temp_empty - 1)) >> 58]); + while (temp_empty != 0) { + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_empty ^ (temp_empty - 1)) >> 58]; temp_empty &= temp_empty - 1; - if ((bitboard_array_global[BP] & WHITE_PAWN_ATTACKS[target_square]) != 0) - { + if ((board.bitboard_array_global[gen_const.BP] & move_constants.WHITE_PAWN_ATTACKS[target_square]) != 0) { continue; } - if ((bitboard_array_global[BN] & KNIGHT_ATTACKS[target_square]) != 0) - { + if ((board.bitboard_array_global[gen_const.BN] & move_constants.KNIGHT_ATTACKS[target_square]) != 0) { continue; } - if ((bitboard_array_global[BK] & KING_ATTACKS[target_square]) != 0) - { + if ((board.bitboard_array_global[gen_const.BK] & move_constants.KING_ATTACKS[target_square]) != 0) { continue; } - const bishopAttacks = GetBishopAttacksFast(target_square, occupanciesWithoutWhiteKing); - if ((bitboard_array_global[BB] & bishopAttacks) != 0) - { + const bishopAttacks = gen_moves.getBishopAttacksFast(target_square, occupanciesWithoutWhiteKing); + if ((board.bitboard_array_global[gen_const.BB] & bishopAttacks) != 0) { continue; } - if ((bitboard_array_global[BQ] & bishopAttacks) != 0) - { + if ((board.bitboard_array_global[gen_const.BQ] & bishopAttacks) != 0) { continue; } - const rookAttacks = GetRookAttacksFast(target_square, occupanciesWithoutWhiteKing); - if ((bitboard_array_global[BR] & rookAttacks) != 0) - { + const rookAttacks = gen_moves.getRookAttacksFast(target_square, occupanciesWithoutWhiteKing); + if ((board.bitboard_array_global[gen_const.BR] & rookAttacks) != 0) { continue; } - if ((bitboard_array_global[BQ] & rookAttacks) != 0) - { + if ((board.bitboard_array_global[gen_const.BQ] & rookAttacks) != 0) { continue; } - move_list[move_count][MOVE_STARTING] = whiteKingPosition; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_NONE; - move_list[move_count][MOVE_PIECE] = WK; + move_list[move_count][gen_const.MOVE_STARTING] = whiteKingPosition; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_NONE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WK; move_count+=1; } //captures temp_captures = temp_attack & BLACK_OCCUPANCIES_LOCAL; - while (temp_captures != 0) - { - target_square = (DEBRUIJN64[MAGIC *% (temp_captures ^ (temp_captures - 1)) >> 58]); + while (temp_captures != 0) { + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_captures ^ (temp_captures - 1)) >> 58]; temp_captures &= temp_captures - 1; - if ((bitboard_array_global[BP] & WHITE_PAWN_ATTACKS[target_square]) != 0) - { + if ((board.bitboard_array_global[gen_const.BP] & move_constants.WHITE_PAWN_ATTACKS[target_square]) != 0) { continue; } - if ((bitboard_array_global[BN] & KNIGHT_ATTACKS[target_square]) != 0) - { + if ((board.bitboard_array_global[gen_const.BN] & move_constants.KNIGHT_ATTACKS[target_square]) != 0) { continue; } - if ((bitboard_array_global[BK] & KING_ATTACKS[target_square]) != 0) - { + if ((board.bitboard_array_global[gen_const.BK] & move_constants.KING_ATTACKS[target_square]) != 0) { continue; } - const bishopAttacks = GetBishopAttacksFast(target_square, occupanciesWithoutWhiteKing); - if ((bitboard_array_global[BB] & bishopAttacks) != 0) - { + const bishopAttacks = gen_moves.getBishopAttacksFast(target_square, occupanciesWithoutWhiteKing); + if ((board.bitboard_array_global[gen_const.BB] & bishopAttacks) != 0) { continue; } - if ((bitboard_array_global[BQ] & bishopAttacks) != 0) - { + if ((board.bitboard_array_global[gen_const.BQ] & bishopAttacks) != 0) { continue; } - const rookAttacks = GetRookAttacksFast(target_square, occupanciesWithoutWhiteKing); - if ((bitboard_array_global[BR] & rookAttacks) != 0) - { + const rookAttacks = gen_moves.getRookAttacksFast(target_square, occupanciesWithoutWhiteKing); + if ((board.bitboard_array_global[gen_const.BR] & rookAttacks) != 0) { continue; } - if ((bitboard_array_global[BQ] & rookAttacks) != 0) - { + if ((board.bitboard_array_global[gen_const.BQ] & rookAttacks) != 0) { continue; } - move_list[move_count][MOVE_STARTING] = whiteKingPosition; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_CAPTURE; - move_list[move_count][MOVE_PIECE] = WK; + move_list[move_count][gen_const.MOVE_STARTING] = whiteKingPosition; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_CAPTURE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WK; move_count+=1; } - if (whiteKingCheckCount == 0) - { - if (castle_rights_global[WKS_CASTLE_RIGHTS] == true) - { - if (whiteKingPosition == E1) //king on e1 - { - if ((WKS_EMPTY_BITBOARD & COMBINED_OCCUPANCIES_LOCAL) == 0) //f1 and g1 empty - { - if ((bitboard_array_global[WR] & SQUARE_BBS[H1]) != 0) //rook on h1 - { - if (Is_Square_Attacked_By_Black_Global(F1, COMBINED_OCCUPANCIES_LOCAL) == false) - { - if (Is_Square_Attacked_By_Black_Global(G1, COMBINED_OCCUPANCIES_LOCAL) == false) - { - move_list[move_count][MOVE_STARTING] = E1; - move_list[move_count][MOVE_TARGET] = G1; - move_list[move_count][MOVE_TAG] = TAG_WCASTLEKS; - move_list[move_count][MOVE_PIECE] = WK; + if (whiteKingCheckCount == 0) { + if (board.castle_rights_global[gen_const.WKS_CASTLE_RIGHTS] == true) { + if (whiteKingPosition == gen_const.E1) { //king on e1 + if ((gen_const.WKS_EMPTY_BITBOARD & COMBINED_OCCUPANCIES_LOCAL) == 0) { //f1 and g1 empty + if ((board.bitboard_array_global[gen_const.WR] & move_constants.SQUARE_BBS[gen_const.H1]) != 0) { //rook on h1 + if (board.isSquareAttackedByBlack(gen_const.F1, COMBINED_OCCUPANCIES_LOCAL) == false) { + if (board.isSquareAttackedByBlack(gen_const.G1, COMBINED_OCCUPANCIES_LOCAL) == false) { + move_list[move_count][gen_const.MOVE_STARTING] = gen_const.E1; + move_list[move_count][gen_const.MOVE_TARGET] = gen_const.G1; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_WCASTLEKS; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WK; move_count+=1; } } @@ -1494,22 +1428,16 @@ fn PerftInlineGlobalOcc(depth:i8, ply:u8) usize { } } } - if (castle_rights_global[WQS_CASTLE_RIGHTS] == true) - { - if (whiteKingPosition == E1) //king on e1 - { - if ((WQS_EMPTY_BITBOARD & COMBINED_OCCUPANCIES_LOCAL) == 0) //f1 and g1 empty - { - if ((bitboard_array_global[WR] & SQUARE_BBS[A1]) != 0) //rook on h1 - { - if (Is_Square_Attacked_By_Black_Global(C1, COMBINED_OCCUPANCIES_LOCAL) == false) - { - if (Is_Square_Attacked_By_Black_Global(D1, COMBINED_OCCUPANCIES_LOCAL) == false) - { - move_list[move_count][MOVE_STARTING] = E1; - move_list[move_count][MOVE_TARGET] = C1; - move_list[move_count][MOVE_TAG] = TAG_WCASTLEQS; - move_list[move_count][MOVE_PIECE] = WK; + if (board.castle_rights_global[gen_const.WQS_CASTLE_RIGHTS] == true) { + if (whiteKingPosition == gen_const.E1) { //king on e1 + if ((gen_const.WQS_EMPTY_BITBOARD & COMBINED_OCCUPANCIES_LOCAL) == 0) { //f1 and g1 empty + if ((board.bitboard_array_global[gen_const.WR] & move_constants.SQUARE_BBS[gen_const.A1]) != 0) { //rook on h1 + if (board.isSquareAttackedByBlack(gen_const.C1, COMBINED_OCCUPANCIES_LOCAL) == false) { + if (board.isSquareAttackedByBlack(gen_const.D1, COMBINED_OCCUPANCIES_LOCAL) == false) { + move_list[move_count][gen_const.MOVE_STARTING] = gen_const.E1; + move_list[move_count][gen_const.MOVE_TARGET] = gen_const.C1; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_WCASTLEQS; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WK; move_count+=1; } } @@ -1519,194 +1447,179 @@ fn PerftInlineGlobalOcc(depth:i8, ply:u8) usize { } } - temp_bitboard = bitboard_array_global[WN]; + temp_bitboard = board.bitboard_array_global[gen_const.WN]; - while (temp_bitboard != 0) - { - starting_square = (DEBRUIJN64[MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]); + while (temp_bitboard != 0) { + starting_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]; temp_bitboard &= temp_bitboard - 1; //removes the knight from that square to not infinitely loop - temp_pin_bitboard = MAX_ULONG; + temp_pin_bitboard = gen_const.MAX_ULONG; if (pinNumber != 0) { for (0..pinNumber) |i| { - if (pinArray[i][PINNED_SQUARE_INDEX] == starting_square) - { - temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[whiteKingPosition][pinArray[i][PINNING_PIECE_INDEX]]; + if (pinArray[i][gen_const.PINNED_SQUARE_INDEX] == starting_square) { + temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[whiteKingPosition][pinArray[i][gen_const.PINNING_PIECE_INDEX]]; } } } - temp_attack = ((KNIGHT_ATTACKS[starting_square] & BLACK_OCCUPANCIES_LOCAL) & check_bitboard) & temp_pin_bitboard; //gets knight captures + temp_attack = ((move_constants.KNIGHT_ATTACKS[starting_square] & BLACK_OCCUPANCIES_LOCAL) & check_bitboard) & temp_pin_bitboard; //gets knight captures while (temp_attack != 0) { - target_square = (DEBRUIJN64[MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]); + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]; temp_attack &= temp_attack - 1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_CAPTURE; - move_list[move_count][MOVE_PIECE] = WN; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_CAPTURE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WN; move_count+=1; } - temp_attack = ((KNIGHT_ATTACKS[starting_square] & EMPTY_OCCUPANCIES) & check_bitboard) & temp_pin_bitboard; + temp_attack = ((move_constants.KNIGHT_ATTACKS[starting_square] & EMPTY_OCCUPANCIES) & check_bitboard) & temp_pin_bitboard; while (temp_attack != 0) { - target_square = (DEBRUIJN64[MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]); + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]; temp_attack &= temp_attack - 1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_NONE; - move_list[move_count][MOVE_PIECE] = WN; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_NONE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WN; move_count+=1; } } - temp_bitboard = bitboard_array_global[WP]; + temp_bitboard = board.bitboard_array_global[gen_const.WP]; - while (temp_bitboard != 0) - { - starting_square = (DEBRUIJN64[MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]); + while (temp_bitboard != 0) { + starting_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]; temp_bitboard &= temp_bitboard - 1; - temp_pin_bitboard = MAX_ULONG; + temp_pin_bitboard = gen_const.MAX_ULONG; if (pinNumber != 0) { for (0..pinNumber) |i| { - if (pinArray[i][PINNED_SQUARE_INDEX] == starting_square) { - temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[whiteKingPosition][pinArray[i][PINNING_PIECE_INDEX]]; + if (pinArray[i][gen_const.PINNED_SQUARE_INDEX] == starting_square) { + temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[whiteKingPosition][pinArray[i][gen_const.PINNING_PIECE_INDEX]]; } } } - if ((SQUARE_BBS[starting_square - 8] & COMBINED_OCCUPANCIES_LOCAL) == 0) { //if up one square is empty - if (((SQUARE_BBS[starting_square - 8] & check_bitboard) & temp_pin_bitboard) != 0) { - if ((SQUARE_BBS[starting_square] & RANK_7_BITBOARD) != 0) { //if promotion - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = starting_square - 8; - move_list[move_count][MOVE_TAG] = TAG_WQueenPromotion; - move_list[move_count][MOVE_PIECE] = WP; + if ((move_constants.SQUARE_BBS[starting_square - 8] & COMBINED_OCCUPANCIES_LOCAL) == 0) { //if up one square is empty + if (((move_constants.SQUARE_BBS[starting_square - 8] & check_bitboard) & temp_pin_bitboard) != 0) { + if ((move_constants.SQUARE_BBS[starting_square] & gen_const.RANK_7_BITBOARD) != 0) { //if promotion + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = starting_square - 8; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_W_Q_PROMOTION; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WP; move_count+=1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = starting_square - 8; - move_list[move_count][MOVE_TAG] = TAG_WRookPromotion; - move_list[move_count][MOVE_PIECE] = WP; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = starting_square - 8; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_W_R_PROMOTION; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WP; move_count+=1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = starting_square - 8; - move_list[move_count][MOVE_TAG] = TAG_WBishopPromotion; - move_list[move_count][MOVE_PIECE] = WP; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = starting_square - 8; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_W_B_PROMOTION; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WP; move_count+=1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = starting_square - 8; - move_list[move_count][MOVE_TAG] = TAG_WKnightPromotion; - move_list[move_count][MOVE_PIECE] = WP; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = starting_square - 8; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_W_N_PROMOTION; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WP; move_count+=1; } else { - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = starting_square - 8; - move_list[move_count][MOVE_TAG] = TAG_NONE; - move_list[move_count][MOVE_PIECE] = WP; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = starting_square - 8; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_NONE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WP; move_count+=1; } } - if ((SQUARE_BBS[starting_square] & RANK_2_BITBOARD) != 0) { //if on rank 2 - if (((SQUARE_BBS[starting_square - 16] & check_bitboard) & temp_pin_bitboard) != 0) { //if not pinned or - if (((SQUARE_BBS[starting_square - 16]) & COMBINED_OCCUPANCIES_LOCAL) == 0) { //if up two squares and one square are empty - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = starting_square - 16; - move_list[move_count][MOVE_TAG] = TAG_DoublePawnWhite; - move_list[move_count][MOVE_PIECE] = WP; + if ((move_constants.SQUARE_BBS[starting_square] & gen_const.RANK_2_BITBOARD) != 0) { //if on rank 2 + if (((move_constants.SQUARE_BBS[starting_square - 16] & check_bitboard) & temp_pin_bitboard) != 0) { //if not pinned or + if (((move_constants.SQUARE_BBS[starting_square - 16]) & COMBINED_OCCUPANCIES_LOCAL) == 0) { //if up two squares and one square are empty + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = starting_square - 16; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_W_DOUBLE_PAWN; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WP; move_count+=1; } } } } - temp_attack = ((WHITE_PAWN_ATTACKS[starting_square] & BLACK_OCCUPANCIES_LOCAL) & check_bitboard) & temp_pin_bitboard; //if black piece diagonal to pawn + temp_attack = ((move_constants.WHITE_PAWN_ATTACKS[starting_square] & BLACK_OCCUPANCIES_LOCAL) & check_bitboard) & temp_pin_bitboard; //if black piece diagonal to pawn - while (temp_attack != 0) - { - target_square = (DEBRUIJN64[MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]); + while (temp_attack != 0) { + + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]; temp_attack &= temp_attack - 1; - if ((SQUARE_BBS[starting_square] & RANK_7_BITBOARD) != 0) //if promotion - { - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_WCaptureQueenPromotion; - move_list[move_count][MOVE_PIECE] = WP; + if ((move_constants.SQUARE_BBS[starting_square] & gen_const.RANK_7_BITBOARD) != 0) { //if promotion + + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_W_Q_PROMOTION_CAP; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WP; move_count+=1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_WCaptureRookPromotion; - move_list[move_count][MOVE_PIECE] = WP; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_W_R_PROMOTION_CAP; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WP; move_count+=1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_WCaptureBishopPromotion; - move_list[move_count][MOVE_PIECE] = WP; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_W_B_PROMOTION_CAP; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WP; move_count+=1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_WCaptureKnightPromotion; - move_list[move_count][MOVE_PIECE] = WP; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_W_N_PROMOTION_CAP; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WP; move_count+=1; - } - else - { - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_CAPTURE; - move_list[move_count][MOVE_PIECE] = WP; + } else { + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_CAPTURE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WP; move_count+=1; } } - if ((SQUARE_BBS[starting_square] & RANK_5_BITBOARD) != 0) //check rank for ep - { - if (ep_global != NO_SQUARE) - { - if ((((WHITE_PAWN_ATTACKS[starting_square] & SQUARE_BBS[ep_global]) & check_bitboard) & temp_pin_bitboard) != 0) - { - if ((bitboard_array_global[WK] & RANK_5_BITBOARD) == 0) //if no king on rank 5 - { - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = ep_global; - move_list[move_count][MOVE_TAG] = TAG_WHITEEP; - move_list[move_count][MOVE_PIECE] = WP; + if ((move_constants.SQUARE_BBS[starting_square] & gen_const.RANK_5_BITBOARD) != 0) { //check rank for ep + if (board.ep_global != gen_const.NO_SQUARE) { + if ((((move_constants.WHITE_PAWN_ATTACKS[starting_square] & move_constants.SQUARE_BBS[board.ep_global]) & check_bitboard) & temp_pin_bitboard) != 0) { + if ((board.bitboard_array_global[gen_const.WK] & gen_const.RANK_5_BITBOARD) == 0) { //if no king on rank 5 + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = board.ep_global; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_WHITE_EP; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WP; move_count+=1; - } - else if ((bitboard_array_global[BR] & RANK_5_BITBOARD) == 0 and (bitboard_array_global[BQ] & RANK_5_BITBOARD) == 0) // if no b rook or queen on rank 5 - { - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = ep_global; - move_list[move_count][MOVE_TAG] = TAG_WHITEEP; - move_list[move_count][MOVE_PIECE] = WP; + } else if ((board.bitboard_array_global[gen_const.BR] & gen_const.RANK_5_BITBOARD) == 0 and (board.bitboard_array_global[gen_const.BQ] & gen_const.RANK_5_BITBOARD) == 0) { // if no b rook or queen on rank 5 + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = board.ep_global; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_WHITE_EP; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WP; move_count+=1; - } - else //wk and br or bq on rank 5 - { - var occupancyWithoutEPPawns:u64 = COMBINED_OCCUPANCIES_LOCAL & ~SQUARE_BBS[starting_square]; - occupancyWithoutEPPawns &= ~SQUARE_BBS[ep_global + 8]; + } else { //wk and br or bq on rank 5 + var occupancyWithoutEPPawns:u64 = COMBINED_OCCUPANCIES_LOCAL & ~move_constants.SQUARE_BBS[starting_square]; + occupancyWithoutEPPawns &= ~move_constants.SQUARE_BBS[board.ep_global + 8]; - const rookAttacksFromKing = GetRookAttacksFast(whiteKingPosition, occupancyWithoutEPPawns); + const rookAttacksFromKing = gen_moves.getRookAttacksFast(whiteKingPosition, occupancyWithoutEPPawns); - if ((rookAttacksFromKing & bitboard_array_global[BR]) == 0) - { - if ((rookAttacksFromKing & bitboard_array_global[BQ]) == 0) - { - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = ep_global; - move_list[move_count][MOVE_TAG] = TAG_WHITEEP; - move_list[move_count][MOVE_PIECE] = WP; + if ((rookAttacksFromKing & board.bitboard_array_global[gen_const.BR]) == 0) { + if ((rookAttacksFromKing & board.bitboard_array_global[gen_const.BQ]) == 0) { + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = board.ep_global; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_WHITE_EP; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WP; move_count+=1; } } @@ -1716,198 +1629,168 @@ fn PerftInlineGlobalOcc(depth:i8, ply:u8) usize { } } - temp_bitboard = bitboard_array_global[WR]; - while (temp_bitboard != 0) - { - starting_square = (DEBRUIJN64[MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]); + temp_bitboard = board.bitboard_array_global[gen_const.WR]; + while (temp_bitboard != 0) { + starting_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]; temp_bitboard &= temp_bitboard - 1; - temp_pin_bitboard = MAX_ULONG; - if (pinNumber != 0) - { - for (0..pinNumber) |i| - { - if (pinArray[i][PINNED_SQUARE_INDEX] == starting_square) - { - temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[whiteKingPosition][pinArray[i][PINNING_PIECE_INDEX]]; + temp_pin_bitboard = gen_const.MAX_ULONG; + if (pinNumber != 0) { + for (0..pinNumber) |i| { + if (pinArray[i][gen_const.PINNED_SQUARE_INDEX] == starting_square) { + temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[whiteKingPosition][pinArray[i][gen_const.PINNING_PIECE_INDEX]]; } } } - const rookAttacks = GetRookAttacksFast(starting_square, COMBINED_OCCUPANCIES_LOCAL); + const rookAttacks = gen_moves.getRookAttacksFast(starting_square, COMBINED_OCCUPANCIES_LOCAL); temp_attack = ((rookAttacks & BLACK_OCCUPANCIES_LOCAL) & check_bitboard) & temp_pin_bitboard; - while (temp_attack != 0) - { - target_square = (DEBRUIJN64[MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]); + while (temp_attack != 0) { + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]; temp_attack &= temp_attack - 1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_CAPTURE; - move_list[move_count][MOVE_PIECE] = WR; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_CAPTURE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WR; move_count+=1; } temp_attack = ((rookAttacks & EMPTY_OCCUPANCIES) & check_bitboard) & temp_pin_bitboard; - while (temp_attack != 0) - { - target_square = (DEBRUIJN64[MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]); + while (temp_attack != 0) { + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]; temp_attack &= temp_attack - 1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_NONE; - move_list[move_count][MOVE_PIECE] = WR; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_NONE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WR; move_count+=1; } } - temp_bitboard = bitboard_array_global[WB]; - while (temp_bitboard != 0) - { - starting_square = (DEBRUIJN64[MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]); + temp_bitboard = board.bitboard_array_global[gen_const.WB]; + while (temp_bitboard != 0) { + starting_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]; temp_bitboard &= temp_bitboard - 1; - temp_pin_bitboard = MAX_ULONG; + temp_pin_bitboard = gen_const.MAX_ULONG; if (pinNumber != 0) { for (0..pinNumber) |i| { - if (pinArray[i][PINNED_SQUARE_INDEX] == starting_square) { - temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[whiteKingPosition][pinArray[i][PINNING_PIECE_INDEX]]; + if (pinArray[i][gen_const.PINNED_SQUARE_INDEX] == starting_square) { + temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[whiteKingPosition][pinArray[i][gen_const.PINNING_PIECE_INDEX]]; } } } - const bishopAttacks = GetBishopAttacksFast(starting_square, COMBINED_OCCUPANCIES_LOCAL); + const bishopAttacks = gen_moves.getBishopAttacksFast(starting_square, COMBINED_OCCUPANCIES_LOCAL); temp_attack = ((bishopAttacks & BLACK_OCCUPANCIES_LOCAL) & check_bitboard) & temp_pin_bitboard; - while (temp_attack != 0) - { - target_square = (DEBRUIJN64[MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]); + while (temp_attack != 0) { + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]; temp_attack &= temp_attack - 1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_CAPTURE; - move_list[move_count][MOVE_PIECE] = WB; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_CAPTURE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WB; move_count+=1; } temp_attack = ((bishopAttacks & EMPTY_OCCUPANCIES) & check_bitboard) & temp_pin_bitboard; - while (temp_attack != 0) - { - target_square = (DEBRUIJN64[MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]); + while (temp_attack != 0) { + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]; temp_attack &= temp_attack - 1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_NONE; - move_list[move_count][MOVE_PIECE] = WB; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_NONE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WB; move_count+=1; } } - temp_bitboard = bitboard_array_global[WQ]; + temp_bitboard = board.bitboard_array_global[gen_const.WQ]; while (temp_bitboard != 0) { - starting_square = (DEBRUIJN64[MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]); + starting_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]; temp_bitboard &= temp_bitboard - 1; - temp_pin_bitboard = MAX_ULONG; + temp_pin_bitboard = gen_const.MAX_ULONG; if (pinNumber != 0) { for (0..pinNumber) |i| { - if (pinArray[i][PINNED_SQUARE_INDEX] == starting_square) { - temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[whiteKingPosition][pinArray[i][PINNING_PIECE_INDEX]]; + if (pinArray[i][gen_const.PINNED_SQUARE_INDEX] == starting_square) { + temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[whiteKingPosition][pinArray[i][gen_const.PINNING_PIECE_INDEX]]; } } } - var queenAttacks:u64 = GetRookAttacksFast(starting_square, COMBINED_OCCUPANCIES_LOCAL); - queenAttacks |= GetBishopAttacksFast(starting_square, COMBINED_OCCUPANCIES_LOCAL); + var queenAttacks:u64 = gen_moves.getRookAttacksFast(starting_square, COMBINED_OCCUPANCIES_LOCAL); + queenAttacks |= gen_moves.getBishopAttacksFast(starting_square, COMBINED_OCCUPANCIES_LOCAL); temp_attack = ((queenAttacks & BLACK_OCCUPANCIES_LOCAL) & check_bitboard) & temp_pin_bitboard; - while (temp_attack != 0) - { - target_square = (DEBRUIJN64[MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]); + while (temp_attack != 0) { + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]; temp_attack &= temp_attack - 1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_CAPTURE; - move_list[move_count][MOVE_PIECE] = WQ; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_CAPTURE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WQ; move_count+=1; } temp_attack = ((queenAttacks & EMPTY_OCCUPANCIES) & check_bitboard) & temp_pin_bitboard; - while (temp_attack != 0) - { - target_square = (DEBRUIJN64[MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]); + while (temp_attack != 0) { + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]; temp_attack &= temp_attack - 1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_NONE; - move_list[move_count][MOVE_PIECE] = WQ; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_NONE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.WQ; move_count+=1; } } } } else { //black move var blackKingCheckCount:usize = 0; - const blackKingPosition:usize = (DEBRUIJN64[MAGIC *% (bitboard_array_global[BK] ^ (bitboard_array_global[BK] - 1)) >> 58]); + const blackKingPosition:usize = gen_const.DEBRUIJN64[gen_const.MAGIC *% (board.bitboard_array_global[gen_const.BK] ^ (board.bitboard_array_global[gen_const.BK] - 1)) >> 58]; //pawns - temp_bitboard = bitboard_array_global[WP] & BLACK_PAWN_ATTACKS[blackKingPosition]; - if (temp_bitboard != 0) - { - const pawn_square = (DEBRUIJN64[MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]); - if (check_bitboard == 0) - { - check_bitboard = SQUARE_BBS[pawn_square]; - } - + temp_bitboard = board.bitboard_array_global[gen_const.WP] & move_constants.BLACK_PAWN_ATTACKS[blackKingPosition]; + if (temp_bitboard != 0) { + const pawn_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]; + check_bitboard = move_constants.SQUARE_BBS[pawn_square]; blackKingCheckCount+=1; } //knights - temp_bitboard = bitboard_array_global[WN] & KNIGHT_ATTACKS[blackKingPosition]; - if (temp_bitboard != 0) - { - const knight_square:usize = (DEBRUIJN64[MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]); - - if (check_bitboard == 0) - { - check_bitboard = SQUARE_BBS[knight_square]; - } - + temp_bitboard = board.bitboard_array_global[gen_const.WN] & move_constants.KNIGHT_ATTACKS[blackKingPosition]; + if (temp_bitboard != 0) { + const knight_square:usize = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]; + check_bitboard = move_constants.SQUARE_BBS[knight_square]; blackKingCheckCount+=1; } //bishops - const bishopAttacksChecks = GetBishopAttacksFast(blackKingPosition, WHITE_OCCUPANCIES_LOCAL); - temp_bitboard = bitboard_array_global[WB] & bishopAttacksChecks; - while (temp_bitboard != 0) - { - const piece_square = (DEBRUIJN64[MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]); + const bishopAttacksChecks = gen_moves.getBishopAttacksFast(blackKingPosition, WHITE_OCCUPANCIES_LOCAL); + temp_bitboard = board.bitboard_array_global[gen_const.WB] & bishopAttacksChecks; + while (temp_bitboard != 0) { + const piece_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]; temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[blackKingPosition][piece_square] & BLACK_OCCUPANCIES_LOCAL; - if (temp_pin_bitboard == 0) - { - if (check_bitboard == 0) - { - check_bitboard = constants.INBETWEEN_BITBOARDS[blackKingPosition][piece_square]; - } + if (temp_pin_bitboard == 0) { + check_bitboard = constants.INBETWEEN_BITBOARDS[blackKingPosition][piece_square]; blackKingCheckCount+=1; - } - else - { - const pinned_square = (DEBRUIJN64[MAGIC *% (temp_pin_bitboard ^ (temp_pin_bitboard - 1)) >> 58]); + } else { + const pinned_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_pin_bitboard ^ (temp_pin_bitboard - 1)) >> 58]; temp_pin_bitboard &= temp_pin_bitboard - 1; - if (temp_pin_bitboard == 0) - { - pinArray[pinNumber][PINNED_SQUARE_INDEX] = pinned_square; - pinArray[pinNumber][PINNING_PIECE_INDEX] = piece_square; + if (temp_pin_bitboard == 0) { + pinArray[pinNumber][gen_const.PINNED_SQUARE_INDEX] = pinned_square; + pinArray[pinNumber][gen_const.PINNING_PIECE_INDEX] = piece_square; pinNumber+=1; } } @@ -1915,29 +1798,21 @@ fn PerftInlineGlobalOcc(depth:i8, ply:u8) usize { } //queen - temp_bitboard = bitboard_array_global[WQ] & bishopAttacksChecks; - while (temp_bitboard != 0) - { - const piece_square = (DEBRUIJN64[MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]); + temp_bitboard = board.bitboard_array_global[gen_const.WQ] & bishopAttacksChecks; + while (temp_bitboard != 0) { + const piece_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]; temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[blackKingPosition][piece_square] & BLACK_OCCUPANCIES_LOCAL; - if (temp_pin_bitboard == 0) - { - if (check_bitboard == 0) - { - check_bitboard = constants.INBETWEEN_BITBOARDS[blackKingPosition][piece_square]; - } + if (temp_pin_bitboard == 0) { + check_bitboard = constants.INBETWEEN_BITBOARDS[blackKingPosition][piece_square]; blackKingCheckCount+=1; - } - else - { - const pinned_square = (DEBRUIJN64[MAGIC *% (temp_pin_bitboard ^ (temp_pin_bitboard - 1)) >> 58]); + } else { + const pinned_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_pin_bitboard ^ (temp_pin_bitboard - 1)) >> 58]; temp_pin_bitboard &= temp_pin_bitboard - 1; - if (temp_pin_bitboard == 0) - { - pinArray[pinNumber][PINNED_SQUARE_INDEX] = pinned_square; - pinArray[pinNumber][PINNING_PIECE_INDEX] = piece_square; + if (temp_pin_bitboard == 0) { + pinArray[pinNumber][gen_const.PINNED_SQUARE_INDEX] = pinned_square; + pinArray[pinNumber][gen_const.PINNING_PIECE_INDEX] = piece_square; pinNumber+=1; } } @@ -1945,34 +1820,23 @@ fn PerftInlineGlobalOcc(depth:i8, ply:u8) usize { } //rook - const rook_attacks = GetRookAttacksFast(blackKingPosition, WHITE_OCCUPANCIES_LOCAL); - temp_bitboard = bitboard_array_global[WR] & rook_attacks; - while (temp_bitboard != 0) - { - const piece_square = (DEBRUIJN64[MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]); - if (piece_square == -1) - { - break; - } + const rook_attacks = gen_moves.getRookAttacksFast(blackKingPosition, WHITE_OCCUPANCIES_LOCAL); + temp_bitboard = board.bitboard_array_global[gen_const.WR] & rook_attacks; + while (temp_bitboard != 0) { + const piece_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]; temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[blackKingPosition][piece_square] & BLACK_OCCUPANCIES_LOCAL; - if (temp_pin_bitboard == 0) - { - if (check_bitboard == 0) - { - check_bitboard = constants.INBETWEEN_BITBOARDS[blackKingPosition][piece_square]; - } + if (temp_pin_bitboard == 0) { + check_bitboard = constants.INBETWEEN_BITBOARDS[blackKingPosition][piece_square]; blackKingCheckCount+=1; - } - else - { - const pinned_square = (DEBRUIJN64[MAGIC *% (temp_pin_bitboard ^ (temp_pin_bitboard - 1)) >> 58]); + } else { + const pinned_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_pin_bitboard ^ (temp_pin_bitboard - 1)) >> 58]; temp_pin_bitboard &= temp_pin_bitboard - 1; if (temp_pin_bitboard == 0) { - pinArray[pinNumber][PINNED_SQUARE_INDEX] = pinned_square; - pinArray[pinNumber][PINNING_PIECE_INDEX] = piece_square; + pinArray[pinNumber][gen_const.PINNED_SQUARE_INDEX] = pinned_square; + pinArray[pinNumber][gen_const.PINNING_PIECE_INDEX] = piece_square; pinNumber+=1; } } @@ -1980,33 +1844,22 @@ fn PerftInlineGlobalOcc(depth:i8, ply:u8) usize { } //queen - temp_bitboard = bitboard_array_global[WQ] & rook_attacks; - while (temp_bitboard != 0) - { - const piece_square = (DEBRUIJN64[MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]); - if (piece_square == -1) - { - break; - } + temp_bitboard = board.bitboard_array_global[gen_const.WQ] & rook_attacks; + while (temp_bitboard != 0) { + const piece_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]; temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[blackKingPosition][piece_square] & BLACK_OCCUPANCIES_LOCAL; - if (temp_pin_bitboard == 0) - { - if (check_bitboard == 0) - { - check_bitboard = constants.INBETWEEN_BITBOARDS[blackKingPosition][piece_square]; - } + if (temp_pin_bitboard == 0) { + check_bitboard = constants.INBETWEEN_BITBOARDS[blackKingPosition][piece_square]; blackKingCheckCount+=1; - } - else - { - const pinned_square = (DEBRUIJN64[MAGIC *% (temp_pin_bitboard ^ (temp_pin_bitboard - 1)) >> 58]); + } else { + const pinned_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_pin_bitboard ^ (temp_pin_bitboard - 1)) >> 58]; temp_pin_bitboard &= temp_pin_bitboard - 1; if (temp_pin_bitboard == 0) { - pinArray[pinNumber][PINNED_SQUARE_INDEX] = pinned_square; - pinArray[pinNumber][PINNING_PIECE_INDEX] = piece_square; + pinArray[pinNumber][gen_const.PINNED_SQUARE_INDEX] = pinned_square; + pinArray[pinNumber][gen_const.PINNING_PIECE_INDEX] = piece_square; pinNumber+=1; } } @@ -2014,265 +1867,215 @@ fn PerftInlineGlobalOcc(depth:i8, ply:u8) usize { } - if (blackKingCheckCount > 1) - { - const occupancyWithoutBlackKing = COMBINED_OCCUPANCIES_LOCAL & (~bitboard_array_global[BK]); - if (blackKingPosition == -1) - { - return 0; - } - temp_attack = KING_ATTACKS[blackKingPosition] & WHITE_OCCUPANCIES_LOCAL; + if (blackKingCheckCount > 1) { + const occupancyWithoutBlackKing = COMBINED_OCCUPANCIES_LOCAL & (~board.bitboard_array_global[gen_const.BK]); + temp_attack = move_constants.KING_ATTACKS[blackKingPosition] & WHITE_OCCUPANCIES_LOCAL; - while (temp_attack != 0) - { - target_square = (DEBRUIJN64[MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]); + while (temp_attack != 0) { + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]; temp_attack &= temp_attack - 1; - if ((bitboard_array_global[WP] & BLACK_PAWN_ATTACKS[target_square]) != 0) - { + if ((board.bitboard_array_global[gen_const.WP] & move_constants.BLACK_PAWN_ATTACKS[target_square]) != 0) { + continue; + } + if ((board.bitboard_array_global[gen_const.WN] & move_constants.KNIGHT_ATTACKS[target_square]) != 0) { continue; } - if ((bitboard_array_global[WN] & KNIGHT_ATTACKS[target_square]) != 0) - { + if ((board.bitboard_array_global[gen_const.WK] & move_constants.KING_ATTACKS[target_square]) != 0) { continue; } - if ((bitboard_array_global[WK] & KING_ATTACKS[target_square]) != 0) - { + const bishopAttacks = gen_moves.getBishopAttacksFast(target_square, occupancyWithoutBlackKing); + if ((board.bitboard_array_global[gen_const.WB] & bishopAttacks) != 0) { continue; } - const bishopAttacks = GetBishopAttacksFast(target_square, occupancyWithoutBlackKing); - if ((bitboard_array_global[WB] & bishopAttacks) != 0) - { + if ((board.bitboard_array_global[gen_const.WQ] & bishopAttacks) != 0) { continue; } - if ((bitboard_array_global[WQ] & bishopAttacks) != 0) - { + const rookAttacks = gen_moves.getRookAttacksFast(target_square, occupancyWithoutBlackKing); + if ((board.bitboard_array_global[gen_const.WR] & rookAttacks) != 0) { continue; } - const rookAttacks = GetRookAttacksFast(target_square, occupancyWithoutBlackKing); - if ((bitboard_array_global[WR] & rookAttacks) != 0) - { - continue; - } - if ((bitboard_array_global[WQ] & rookAttacks) != 0) - { + if ((board.bitboard_array_global[gen_const.WQ] & rookAttacks) != 0) { continue; } - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_CAPTURE; - move_list[move_count][MOVE_PIECE] = BK; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_CAPTURE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BK; move_count+=1; } - temp_attack = KING_ATTACKS[blackKingPosition] & ~COMBINED_OCCUPANCIES_LOCAL; + temp_attack = move_constants.KING_ATTACKS[blackKingPosition] & ~COMBINED_OCCUPANCIES_LOCAL; - while (temp_attack != 0) - { - target_square = (DEBRUIJN64[MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]); + while (temp_attack != 0) { + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]; temp_attack &= temp_attack - 1; - if ((bitboard_array_global[WP] & WHITE_PAWN_ATTACKS[target_square]) != 0) - { + if ((board.bitboard_array_global[gen_const.WP] & move_constants.WHITE_PAWN_ATTACKS[target_square]) != 0) { continue; } - if ((bitboard_array_global[WN] & KNIGHT_ATTACKS[target_square]) != 0) - { + if ((board.bitboard_array_global[gen_const.WN] & move_constants.KNIGHT_ATTACKS[target_square]) != 0) { continue; } - if ((bitboard_array_global[WK] & KING_ATTACKS[target_square]) != 0) - { + if ((board.bitboard_array_global[gen_const.WK] & move_constants.KING_ATTACKS[target_square]) != 0) { continue; } - const bishopAttacks = GetBishopAttacksFast(target_square, occupancyWithoutBlackKing); - if ((bitboard_array_global[WB] & bishopAttacks) != 0) - { + const bishopAttacks = gen_moves.getBishopAttacksFast(target_square, occupancyWithoutBlackKing); + if ((board.bitboard_array_global[gen_const.WB] & bishopAttacks) != 0) { continue; } - if ((bitboard_array_global[WQ] & bishopAttacks) != 0) - { + if ((board.bitboard_array_global[gen_const.WQ] & bishopAttacks) != 0) { continue; } - const rookAttacks = GetRookAttacksFast(target_square, occupancyWithoutBlackKing); - if ((bitboard_array_global[WR] & rookAttacks) != 0) - { + const rookAttacks = gen_moves.getRookAttacksFast(target_square, occupancyWithoutBlackKing); + if ((board.bitboard_array_global[gen_const.WR] & rookAttacks) != 0) { continue; } - if ((bitboard_array_global[WQ] & rookAttacks) != 0) - { + if ((board.bitboard_array_global[gen_const.WQ] & rookAttacks) != 0) { continue; } - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_NONE; - move_list[move_count][MOVE_PIECE] = BK; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_NONE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BK; move_count+=1; } - } - else - { - if (blackKingCheckCount == 0) - { - check_bitboard = MAX_ULONG; + } else { + if (blackKingCheckCount == 0) { + check_bitboard = gen_const.MAX_ULONG; } - temp_bitboard = bitboard_array_global[BP]; + temp_bitboard = board.bitboard_array_global[gen_const.BP]; - while (temp_bitboard != 0) - { - starting_square = (DEBRUIJN64[MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]); + while (temp_bitboard != 0) { + starting_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]; temp_bitboard &= temp_bitboard - 1; - temp_pin_bitboard = MAX_ULONG; - if (pinNumber != 0) - { - for (0..pinNumber) |i| - { - if (pinArray[i][PINNED_SQUARE_INDEX] == starting_square) - { - temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[blackKingPosition][pinArray[i][PINNING_PIECE_INDEX]]; + temp_pin_bitboard = gen_const.MAX_ULONG; + if (pinNumber != 0) { + for (0..pinNumber) |i| { + if (pinArray[i][gen_const.PINNED_SQUARE_INDEX] == starting_square) { + temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[blackKingPosition][pinArray[i][gen_const.PINNING_PIECE_INDEX]]; } } } - if ((SQUARE_BBS[starting_square + 8] & COMBINED_OCCUPANCIES_LOCAL) == 0) //if up one square is empty - { - if (((SQUARE_BBS[starting_square + 8] & check_bitboard) & temp_pin_bitboard) != 0) - { - if ((SQUARE_BBS[starting_square] & RANK_2_BITBOARD) != 0) //if promotion - { - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = starting_square + 8; - move_list[move_count][MOVE_TAG] = TAG_BBishopPromotion; - move_list[move_count][MOVE_PIECE] = BP; + if ((move_constants.SQUARE_BBS[starting_square + 8] & COMBINED_OCCUPANCIES_LOCAL) == 0) { //if up one square is empty + if (((move_constants.SQUARE_BBS[starting_square + 8] & check_bitboard) & temp_pin_bitboard) != 0) { + if ((move_constants.SQUARE_BBS[starting_square] & gen_const.RANK_2_BITBOARD) != 0) { //if promotion + + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = starting_square + 8; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_B_B_PROMOTION; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BP; move_count+=1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = starting_square + 8; - move_list[move_count][MOVE_TAG] = TAG_BKnightPromotion; - move_list[move_count][MOVE_PIECE] = BP; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = starting_square + 8; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_B_N_PROMOTION; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BP; move_count+=1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = starting_square + 8; - move_list[move_count][MOVE_TAG] = TAG_BRookPromotion; - move_list[move_count][MOVE_PIECE] = BP; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = starting_square + 8; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_B_R_PROMOTION; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BP; move_count+=1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = starting_square + 8; - move_list[move_count][MOVE_TAG] = TAG_BQueenPromotion; - move_list[move_count][MOVE_PIECE] = BP; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = starting_square + 8; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_B_Q_PROMOTION; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BP; move_count+=1; - } - else - { - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = starting_square + 8; - move_list[move_count][MOVE_TAG] = TAG_NONE; - move_list[move_count][MOVE_PIECE] = BP; + } else { + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = starting_square + 8; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_NONE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BP; move_count+=1; } } - if ((SQUARE_BBS[starting_square] & RANK_7_BITBOARD) != 0) //if on rank 2 - { - if (((SQUARE_BBS[starting_square + 16] & check_bitboard) & temp_pin_bitboard) != 0) - { - if (((SQUARE_BBS[starting_square + 16]) & COMBINED_OCCUPANCIES_LOCAL) == 0) //if up two squares and one square are empty - { - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = starting_square + 16; - move_list[move_count][MOVE_TAG] = TAG_DoublePawnBlack; - move_list[move_count][MOVE_PIECE] = BP; + if ((move_constants.SQUARE_BBS[starting_square] & gen_const.RANK_7_BITBOARD) != 0) { //if on rank 2 + if (((move_constants.SQUARE_BBS[starting_square + 16] & check_bitboard) & temp_pin_bitboard) != 0) { + if (((move_constants.SQUARE_BBS[starting_square + 16]) & COMBINED_OCCUPANCIES_LOCAL) == 0) { //if up two squares and one square are empty + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = starting_square + 16; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_B_DOUBLE_PAWN; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BP; move_count+=1; } } } } - temp_attack = ((BLACK_PAWN_ATTACKS[starting_square] & WHITE_OCCUPANCIES_LOCAL) & check_bitboard) & temp_pin_bitboard; //if black piece diagonal to pawn + temp_attack = ((move_constants.BLACK_PAWN_ATTACKS[starting_square] & WHITE_OCCUPANCIES_LOCAL) & check_bitboard) & temp_pin_bitboard; //if black piece diagonal to pawn - while (temp_attack != 0) - { - target_square = (DEBRUIJN64[MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]); //find the bit + while (temp_attack != 0) { + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]; //find the bit temp_attack &= temp_attack - 1; - if ((SQUARE_BBS[starting_square] & RANK_2_BITBOARD) != 0) //if promotion - { - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_BCaptureQueenPromotion; - move_list[move_count][MOVE_PIECE] = BP; + if ((move_constants.SQUARE_BBS[starting_square] & gen_const.RANK_2_BITBOARD) != 0) { //if promotion + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_B_Q_PROMOTION_CAP; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BP; move_count+=1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_BCaptureRookPromotion; - move_list[move_count][MOVE_PIECE] = BP; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_B_R_PROMOTION_CAP; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BP; move_count+=1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_BCaptureKnightPromotion; - move_list[move_count][MOVE_PIECE] = BP; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_B_N_PROMOTION_CAP; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BP; move_count+=1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_BCaptureBishopPromotion; - move_list[move_count][MOVE_PIECE] = BP; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_B_B_PROMOTION_CAP; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BP; move_count+=1; - } - else - { - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_CAPTURE; - move_list[move_count][MOVE_PIECE] = BP; + } else { + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_CAPTURE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BP; move_count+=1; } } - if ((SQUARE_BBS[starting_square] & RANK_4_BITBOARD) != 0) //check rank for ep - { - if (ep_global != NO_SQUARE) - { - if ((((BLACK_PAWN_ATTACKS[starting_square] & SQUARE_BBS[ep_global]) & check_bitboard) & temp_pin_bitboard) != 0) - { - if ((bitboard_array_global[BK] & RANK_4_BITBOARD) == 0) //if no king on rank 5 - { - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = ep_global; - move_list[move_count][MOVE_TAG] = TAG_BLACKEP; - move_list[move_count][MOVE_PIECE] = BP; + if ((move_constants.SQUARE_BBS[starting_square] & gen_const.RANK_4_BITBOARD) != 0) { //check rank for ep + if (board.ep_global != gen_const.NO_SQUARE) { + if ((((move_constants.BLACK_PAWN_ATTACKS[starting_square] & move_constants.SQUARE_BBS[board.ep_global]) & check_bitboard) & temp_pin_bitboard) != 0) { + if ((board.bitboard_array_global[gen_const.BK] & gen_const.RANK_4_BITBOARD) == 0) { //if no king on rank 5 + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = board.ep_global; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_BLACK_EP; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BP; move_count+=1; - } - else if ((bitboard_array_global[WR] & RANK_4_BITBOARD) == 0 and (bitboard_array_global[WQ] & RANK_4_BITBOARD) == 0) // if no b rook or queen on rank 5 - { - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = ep_global; - move_list[move_count][MOVE_TAG] = TAG_BLACKEP; - move_list[move_count][MOVE_PIECE] = BP; + } else if ((board.bitboard_array_global[gen_const.WR] & gen_const.RANK_4_BITBOARD) == 0 and (board.bitboard_array_global[gen_const.WQ] & gen_const.RANK_4_BITBOARD) == 0) { // if no b rook or queen on rank 5 move_list[move_count][MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = board.ep_global; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_BLACK_EP; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BP; move_count+=1; - } - else //wk and br or bq on rank 5 - { - var occupancyWithoutEPPawns = COMBINED_OCCUPANCIES_LOCAL & ~SQUARE_BBS[starting_square]; - occupancyWithoutEPPawns &= ~SQUARE_BBS[ep_global - 8]; + } else { //wk and br or bq on rank 5 + var occupancyWithoutEPPawns = COMBINED_OCCUPANCIES_LOCAL & ~move_constants.SQUARE_BBS[starting_square]; + occupancyWithoutEPPawns &= ~move_constants.SQUARE_BBS[board.ep_global - 8]; - const rookAttacksFromKing = GetRookAttacksFast(blackKingPosition, occupancyWithoutEPPawns); + const rookAttacksFromKing = gen_moves.getRookAttacksFast(blackKingPosition, occupancyWithoutEPPawns); - if ((rookAttacksFromKing & bitboard_array_global[WR]) == 0) - { - if ((rookAttacksFromKing & bitboard_array_global[WQ]) == 0) - { - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = ep_global; - move_list[move_count][MOVE_TAG] = TAG_BLACKEP; - move_list[move_count][MOVE_PIECE] = BP; + if ((rookAttacksFromKing & board.bitboard_array_global[gen_const.WR]) == 0) { + if ((rookAttacksFromKing & board.bitboard_array_global[gen_const.WQ]) == 0) { + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = board.ep_global; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_BLACK_EP; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BP; move_count+=1; } } @@ -2282,305 +2085,258 @@ fn PerftInlineGlobalOcc(depth:i8, ply:u8) usize { } } - temp_bitboard = bitboard_array_global[BN]; + temp_bitboard = board.bitboard_array_global[gen_const.BN]; - while (temp_bitboard != 0) - { - starting_square = (DEBRUIJN64[MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]); //looks for the startingSquare + while (temp_bitboard != 0) { + starting_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]; //looks for the startingSquare temp_bitboard &= temp_bitboard - 1; //removes the knight from that square to not infinitely loop - temp_pin_bitboard = MAX_ULONG; - if (pinNumber != 0) - { - for (0..pinNumber) |i| - { - if (pinArray[i][PINNED_SQUARE_INDEX] == starting_square) - { - temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[blackKingPosition][pinArray[i][PINNING_PIECE_INDEX]]; + temp_pin_bitboard = gen_const.MAX_ULONG; + if (pinNumber != 0) { + for (0..pinNumber) |i| { + if (pinArray[i][gen_const.PINNED_SQUARE_INDEX] == starting_square) { + temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[blackKingPosition][pinArray[i][gen_const.PINNING_PIECE_INDEX]]; } } } - temp_attack = ((KNIGHT_ATTACKS[starting_square] & WHITE_OCCUPANCIES_LOCAL) & check_bitboard) & temp_pin_bitboard; //gets knight captures - while (temp_attack != 0) - { - target_square = (DEBRUIJN64[MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]); + temp_attack = ((move_constants.KNIGHT_ATTACKS[starting_square] & WHITE_OCCUPANCIES_LOCAL) & check_bitboard) & temp_pin_bitboard; //gets knight captures + while (temp_attack != 0) { + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]; temp_attack &= temp_attack - 1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_CAPTURE; - move_list[move_count][MOVE_PIECE] = BN; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_CAPTURE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BN; move_count+=1; } - temp_attack = ((KNIGHT_ATTACKS[starting_square] & (~COMBINED_OCCUPANCIES_LOCAL)) & check_bitboard) & temp_pin_bitboard; + temp_attack = ((move_constants.KNIGHT_ATTACKS[starting_square] & (~COMBINED_OCCUPANCIES_LOCAL)) & check_bitboard) & temp_pin_bitboard; - while (temp_attack != 0) - { - target_square = (DEBRUIJN64[MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]); + while (temp_attack != 0) { + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]; temp_attack &= temp_attack - 1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_NONE; - move_list[move_count][MOVE_PIECE] = BN; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_NONE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BN; move_count+=1; } } - temp_bitboard = bitboard_array_global[BB]; - while (temp_bitboard != 0) - { - starting_square = (DEBRUIJN64[MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]); + temp_bitboard = board.bitboard_array_global[gen_const.BB]; + while (temp_bitboard != 0) { + starting_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]; temp_bitboard &= temp_bitboard - 1; - temp_pin_bitboard = MAX_ULONG; - if (pinNumber != 0) - { - for (0..pinNumber) |i| - { - if (pinArray[i][PINNED_SQUARE_INDEX] == starting_square) - { - temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[blackKingPosition][pinArray[i][PINNING_PIECE_INDEX]]; + temp_pin_bitboard = gen_const.MAX_ULONG; + if (pinNumber != 0) { + for (0..pinNumber) |i| { + if (pinArray[i][gen_const.PINNED_SQUARE_INDEX] == starting_square) { + temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[blackKingPosition][pinArray[i][gen_const.PINNING_PIECE_INDEX]]; } } } - const bishopAttacks = GetBishopAttacksFast(starting_square, COMBINED_OCCUPANCIES_LOCAL); + const bishopAttacks = gen_moves.getBishopAttacksFast(starting_square, COMBINED_OCCUPANCIES_LOCAL); temp_attack = ((bishopAttacks & WHITE_OCCUPANCIES_LOCAL) & check_bitboard) & temp_pin_bitboard; - while (temp_attack != 0) - { - target_square = (DEBRUIJN64[MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]); + while (temp_attack != 0) { + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]; temp_attack &= temp_attack - 1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_CAPTURE; - move_list[move_count][MOVE_PIECE] = BB; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_CAPTURE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BB; move_count+=1; } temp_attack = ((bishopAttacks & (~COMBINED_OCCUPANCIES_LOCAL)) & check_bitboard) & temp_pin_bitboard; - while (temp_attack != 0) - { - target_square = (DEBRUIJN64[MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]); + while (temp_attack != 0) { + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]; temp_attack &= temp_attack - 1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_NONE; - move_list[move_count][MOVE_PIECE] = BB; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_NONE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BB; move_count+=1; } } - temp_bitboard = bitboard_array_global[BR]; - while (temp_bitboard != 0) - { - starting_square = (DEBRUIJN64[MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]); + temp_bitboard = board.bitboard_array_global[gen_const.BR]; + while (temp_bitboard != 0) { + starting_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]; temp_bitboard &= temp_bitboard - 1; - temp_pin_bitboard = MAX_ULONG; - if (pinNumber != 0) - { - for (0..pinNumber) |i| - { - if (pinArray[i][PINNED_SQUARE_INDEX] == starting_square) - { - temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[blackKingPosition][pinArray[i][PINNING_PIECE_INDEX]]; + temp_pin_bitboard = gen_const.MAX_ULONG; + if (pinNumber != 0) { + for (0..pinNumber) |i| { + if (pinArray[i][gen_const.PINNED_SQUARE_INDEX] == starting_square) { + temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[blackKingPosition][pinArray[i][gen_const.PINNING_PIECE_INDEX]]; } } } - const rookAttacks = GetRookAttacksFast(starting_square, COMBINED_OCCUPANCIES_LOCAL); + const rookAttacks = gen_moves.getRookAttacksFast(starting_square, COMBINED_OCCUPANCIES_LOCAL); temp_attack = ((rookAttacks & WHITE_OCCUPANCIES_LOCAL) & check_bitboard) & temp_pin_bitboard; - while (temp_attack != 0) - { - target_square = (DEBRUIJN64[MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]); + while (temp_attack != 0) { + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]; temp_attack &= temp_attack - 1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_CAPTURE; - move_list[move_count][MOVE_PIECE] = BR; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_CAPTURE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BR; move_count+=1; } temp_attack = ((rookAttacks & (~COMBINED_OCCUPANCIES_LOCAL)) & check_bitboard) & temp_pin_bitboard; - while (temp_attack != 0) - { - target_square = (DEBRUIJN64[MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]); + while (temp_attack != 0) { + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]; temp_attack &= temp_attack - 1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_NONE; - move_list[move_count][MOVE_PIECE] = BR; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_NONE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BR; move_count+=1; } } - temp_bitboard = bitboard_array_global[BQ]; - while (temp_bitboard != 0) - { - starting_square = (DEBRUIJN64[MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]); + temp_bitboard = board.bitboard_array_global[gen_const.BQ]; + while (temp_bitboard != 0) { + starting_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_bitboard ^ (temp_bitboard - 1)) >> 58]; temp_bitboard &= temp_bitboard - 1; - temp_pin_bitboard = MAX_ULONG; - if (pinNumber != 0) - { - for (0..pinNumber) |i| - { - if (pinArray[i][PINNED_SQUARE_INDEX] == starting_square) - { - temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[blackKingPosition][pinArray[i][PINNING_PIECE_INDEX]]; + temp_pin_bitboard = gen_const.MAX_ULONG; + if (pinNumber != 0) { + for (0..pinNumber) |i| { + if (pinArray[i][gen_const.PINNED_SQUARE_INDEX] == starting_square) { + temp_pin_bitboard = constants.INBETWEEN_BITBOARDS[blackKingPosition][pinArray[i][gen_const.PINNING_PIECE_INDEX]]; } } } - var queenAttacks:u64 = GetRookAttacksFast(starting_square, COMBINED_OCCUPANCIES_LOCAL); - queenAttacks |= GetBishopAttacksFast(starting_square, COMBINED_OCCUPANCIES_LOCAL); + var queenAttacks:u64 = gen_moves.getRookAttacksFast(starting_square, COMBINED_OCCUPANCIES_LOCAL); + queenAttacks |= gen_moves.getBishopAttacksFast(starting_square, COMBINED_OCCUPANCIES_LOCAL); temp_attack = ((queenAttacks & WHITE_OCCUPANCIES_LOCAL) & check_bitboard) & temp_pin_bitboard; - while (temp_attack != 0) - { - target_square = (DEBRUIJN64[MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]); + while (temp_attack != 0) { + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]; temp_attack &= temp_attack - 1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_CAPTURE; - move_list[move_count][MOVE_PIECE] = BQ; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_CAPTURE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BQ; move_count+=1; } temp_attack = ((queenAttacks & (~COMBINED_OCCUPANCIES_LOCAL)) & check_bitboard) & temp_pin_bitboard; - while (temp_attack != 0) - { - target_square = (DEBRUIJN64[MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]); + while (temp_attack != 0) { + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]; temp_attack &= temp_attack - 1; - move_list[move_count][MOVE_STARTING] = starting_square; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_NONE; - move_list[move_count][MOVE_PIECE] = BQ; + move_list[move_count][gen_const.MOVE_STARTING] = starting_square; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_NONE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BQ; move_count+=1; } } - temp_attack = KING_ATTACKS[blackKingPosition] & WHITE_OCCUPANCIES_LOCAL; //gets knight captures - while (temp_attack != 0) - { - target_square = (DEBRUIJN64[MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]); + temp_attack = move_constants.KING_ATTACKS[blackKingPosition] & WHITE_OCCUPANCIES_LOCAL; //gets knight captures + while (temp_attack != 0) { + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]; temp_attack &= temp_attack - 1; - if ((bitboard_array_global[WP] & BLACK_PAWN_ATTACKS[target_square]) != 0) - { + if ((board.bitboard_array_global[gen_const.WP] & move_constants.BLACK_PAWN_ATTACKS[target_square]) != 0) { continue; } - if ((bitboard_array_global[WN] & KNIGHT_ATTACKS[target_square]) != 0) - { + if ((board.bitboard_array_global[gen_const.WN] & move_constants.KNIGHT_ATTACKS[target_square]) != 0) { continue; } - if ((bitboard_array_global[WK] & KING_ATTACKS[target_square]) != 0) - { + if ((board.bitboard_array_global[gen_const.WK] & move_constants.KING_ATTACKS[target_square]) != 0) { continue; } - const occupancyWithoutBlackKing = COMBINED_OCCUPANCIES_LOCAL & (~bitboard_array_global[BK]); - const bishopAttacks = GetBishopAttacksFast(target_square, occupancyWithoutBlackKing); - if ((bitboard_array_global[WB] & bishopAttacks) != 0) - { + const occupancyWithoutBlackKing = COMBINED_OCCUPANCIES_LOCAL & (~board.bitboard_array_global[gen_const.BK]); + const bishopAttacks = gen_moves.getBishopAttacksFast(target_square, occupancyWithoutBlackKing); + if ((board.bitboard_array_global[gen_const.WB] & bishopAttacks) != 0) { continue; } - if ((bitboard_array_global[WQ] & bishopAttacks) != 0) - { + if ((board.bitboard_array_global[gen_const.WQ] & bishopAttacks) != 0) { continue; } - const rookAttacks = GetRookAttacksFast(target_square, occupancyWithoutBlackKing); - if ((bitboard_array_global[WR] & rookAttacks) != 0) - { + const rookAttacks = gen_moves.getRookAttacksFast(target_square, occupancyWithoutBlackKing); + if ((board.bitboard_array_global[gen_const.WR] & rookAttacks) != 0) { continue; } - if ((bitboard_array_global[WQ] & rookAttacks) != 0) - { + if ((board.bitboard_array_global[gen_const.WQ] & rookAttacks) != 0) { continue; } - move_list[move_count][MOVE_STARTING] = blackKingPosition; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_CAPTURE; - move_list[move_count][MOVE_PIECE] = BK; + move_list[move_count][gen_const.MOVE_STARTING] = blackKingPosition; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_CAPTURE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BK; move_count+=1; } - temp_attack = KING_ATTACKS[blackKingPosition] & (~COMBINED_OCCUPANCIES_LOCAL); //get knight moves to emtpy squares + temp_attack = move_constants.KING_ATTACKS[blackKingPosition] & (~COMBINED_OCCUPANCIES_LOCAL); //get knight moves to emtpy squares - while (temp_attack != 0) - { - target_square = (DEBRUIJN64[MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]); + while (temp_attack != 0) { + target_square = gen_const.DEBRUIJN64[gen_const.MAGIC *% (temp_attack ^ (temp_attack - 1)) >> 58]; temp_attack &= temp_attack - 1; - if ((bitboard_array_global[WP] & BLACK_PAWN_ATTACKS[target_square]) != 0) - { + if ((board.bitboard_array_global[gen_const.WP] & move_constants.BLACK_PAWN_ATTACKS[target_square]) != 0) { continue; } - if ((bitboard_array_global[WN] & KNIGHT_ATTACKS[target_square]) != 0) - { + if ((board.bitboard_array_global[gen_const.WN] & move_constants.KNIGHT_ATTACKS[target_square]) != 0) { continue; } - if ((bitboard_array_global[WK] & KING_ATTACKS[target_square]) != 0) - { + if ((board.bitboard_array_global[gen_const.WK] & move_constants.KING_ATTACKS[target_square]) != 0) { continue; } - const occupancyWithoutBlackKing = COMBINED_OCCUPANCIES_LOCAL & (~bitboard_array_global[BK]); - const bishopAttacks = GetBishopAttacksFast(target_square, occupancyWithoutBlackKing); - if ((bitboard_array_global[WB] & bishopAttacks) != 0) - { + const occupancyWithoutBlackKing = COMBINED_OCCUPANCIES_LOCAL & (~board.bitboard_array_global[gen_const.BK]); + const bishopAttacks = gen_moves.getBishopAttacksFast(target_square, occupancyWithoutBlackKing); + if ((board.bitboard_array_global[gen_const.WB] & bishopAttacks) != 0) { continue; } - if ((bitboard_array_global[WQ] & bishopAttacks) != 0) - { + if ((board.bitboard_array_global[gen_const.WQ] & bishopAttacks) != 0) { continue; } - const rookAttacks = GetRookAttacksFast(target_square, occupancyWithoutBlackKing); - if ((bitboard_array_global[WR] & rookAttacks) != 0) - { + const rookAttacks = gen_moves.getRookAttacksFast(target_square, occupancyWithoutBlackKing); + if ((board.bitboard_array_global[gen_const.WR] & rookAttacks) != 0) { continue; } - if ((bitboard_array_global[WQ] & rookAttacks) != 0) - { + if ((board.bitboard_array_global[gen_const.WQ] & rookAttacks) != 0) { continue; } - move_list[move_count][MOVE_STARTING] = blackKingPosition; - move_list[move_count][MOVE_TARGET] = target_square; - move_list[move_count][MOVE_TAG] = TAG_NONE; - move_list[move_count][MOVE_PIECE] = BK; + move_list[move_count][gen_const.MOVE_STARTING] = blackKingPosition; + move_list[move_count][gen_const.MOVE_TARGET] = target_square; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_NONE; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BK; move_count+=1; } } - if (blackKingCheckCount == 0) - { - if (castle_rights_global[BKS_CASTLE_RIGHTS] == true) - { - if (blackKingPosition == E8) //king on e1 - { - if ((BKS_EMPTY_BITBOARD & COMBINED_OCCUPANCIES_LOCAL) == 0) //f1 and g1 empty - { - if ((bitboard_array_global[BR] & SQUARE_BBS[H8]) != 0) //rook on h1 - { - if (Is_Square_Attacked_By_White_Global(F8, COMBINED_OCCUPANCIES_LOCAL) == false) - { - if (Is_Square_Attacked_By_White_Global(G8, COMBINED_OCCUPANCIES_LOCAL) == false) - { - move_list[move_count][MOVE_STARTING] = E8; - move_list[move_count][MOVE_TARGET] = G8; - move_list[move_count][MOVE_TAG] = TAG_BCASTLEKS; - move_list[move_count][MOVE_PIECE] = BK; + if (blackKingCheckCount == 0) { + if (board.castle_rights_global[gen_const.BKS_CASTLE_RIGHTS] == true) { + if (blackKingPosition == gen_const.E8) { + if ((gen_const.BKS_EMPTY_BITBOARD & COMBINED_OCCUPANCIES_LOCAL) == 0) { + if ((board.bitboard_array_global[gen_const.BR] & move_constants.SQUARE_BBS[gen_const.H8]) != 0) { + if (board.isSquareAttackedByWhiteGlobal(gen_const.F8, COMBINED_OCCUPANCIES_LOCAL) == false) { + if (board.isSquareAttackedByWhiteGlobal(gen_const.G8, COMBINED_OCCUPANCIES_LOCAL) == false) { + move_list[move_count][gen_const.MOVE_STARTING] = gen_const.E8; + move_list[move_count][gen_const.MOVE_TARGET] = gen_const.G8; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_BCASTLEKS; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BK; move_count+=1; } } @@ -2588,22 +2344,16 @@ fn PerftInlineGlobalOcc(depth:i8, ply:u8) usize { } } } - if (castle_rights_global[BQS_CASTLE_RIGHTS] == true) - { - if (blackKingPosition == E8) //king on e1 - { - if ((BQS_EMPTY_BITBOARD & COMBINED_OCCUPANCIES_LOCAL) == 0) //f1 and g1 empty - { - if ((bitboard_array_global[BR] & SQUARE_BBS[A8]) != 0) //rook on h1 - { - if (Is_Square_Attacked_By_White_Global(C8, COMBINED_OCCUPANCIES_LOCAL) == false) - { - if (Is_Square_Attacked_By_White_Global(D8, COMBINED_OCCUPANCIES_LOCAL) == false) - { - move_list[move_count][MOVE_STARTING] = E8; - move_list[move_count][MOVE_TARGET] = C8; - move_list[move_count][MOVE_TAG] = TAG_BCASTLEQS; - move_list[move_count][MOVE_PIECE] = BK; + if (board.castle_rights_global[gen_const.BQS_CASTLE_RIGHTS] == true) { + if (blackKingPosition == gen_const.E8) { + if ((gen_const.BQS_EMPTY_BITBOARD & COMBINED_OCCUPANCIES_LOCAL) == 0) { + if ((board.bitboard_array_global[gen_const.BR] & move_constants.SQUARE_BBS[gen_const.A8]) != 0) { + if (board.isSquareAttackedByWhiteGlobal(gen_const.C8, COMBINED_OCCUPANCIES_LOCAL) == false) { + if (board.isSquareAttackedByWhiteGlobal(gen_const.D8, COMBINED_OCCUPANCIES_LOCAL) == false) { + move_list[move_count][gen_const.MOVE_STARTING] = gen_const.E8; + move_list[move_count][gen_const.MOVE_TARGET] = gen_const.C8; + move_list[move_count][gen_const.MOVE_TAG] = gen_const.TAG_BCASTLEQS; + move_list[move_count][gen_const.MOVE_PIECE] = gen_const.BK; move_count+=1; } } @@ -2614,518 +2364,475 @@ fn PerftInlineGlobalOcc(depth:i8, ply:u8) usize { } } - if (depth == 1) - { + if (depth == 1) { return move_count; } var nodes:usize = 0; var priorNodes:usize = undefined; - const copyEp = ep_global; + const copyEp = board.ep_global; const copy_castle :[4]bool = [4]bool { - castle_rights_global[0], - castle_rights_global[1], - castle_rights_global[2], - castle_rights_global[3], + board.castle_rights_global[0], + board.castle_rights_global[1], + board.castle_rights_global[2], + board.castle_rights_global[3], }; for (0..move_count) |move_index| { - const startingSquare = move_list[move_index][MOVE_STARTING]; - const targetSquare = move_list[move_index][MOVE_TARGET]; - const piece = move_list[move_index][MOVE_PIECE]; - const tag = move_list[move_index][MOVE_TAG]; + const startingSquare = move_list[move_index][gen_const.MOVE_STARTING]; + const targetSquare = move_list[move_index][gen_const.MOVE_TARGET]; + const piece = move_list[move_index][gen_const.MOVE_PIECE]; + const tag = move_list[move_index][gen_const.MOVE_TAG]; - var captureIndex:usize = NO_SQUARE; + var captureIndex:usize = gen_const.NO_SQUARE; - if (is_white_global == true) { - is_white_global = false; + if (board.is_white_global == true) { + board.is_white_global = false; } else { - is_white_global = true; + board.is_white_global = true; } - switch (tag) - { + switch (tag) { 0, 26 => { //none - bitboard_array_global[piece] |= SQUARE_BBS[targetSquare]; - bitboard_array_global[piece] &= ~SQUARE_BBS[startingSquare]; - ep_global = NO_SQUARE; + board.bitboard_array_global[piece] |= move_constants.SQUARE_BBS[targetSquare]; + board.bitboard_array_global[piece] &= ~move_constants.SQUARE_BBS[startingSquare]; + board.ep_global = gen_const.NO_SQUARE; }, 1, 27 => { //check cap - bitboard_array_global[piece] |= SQUARE_BBS[targetSquare]; - bitboard_array_global[piece] &= ~SQUARE_BBS[startingSquare]; - if (piece >= WP and piece <= WK) - { - for (6..12) |i| - { - if ((bitboard_array_global[i] & SQUARE_BBS[targetSquare]) != 0) - { + board.bitboard_array_global[piece] |= move_constants.SQUARE_BBS[targetSquare]; + board.bitboard_array_global[piece] &= ~move_constants.SQUARE_BBS[startingSquare]; + if (piece >= gen_const.WP and piece <= gen_const.WK) { + for (6..12) |i| { + if ((board.bitboard_array_global[i] & move_constants.SQUARE_BBS[targetSquare]) != 0) { captureIndex = i; break; } } - bitboard_array_global[captureIndex] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[captureIndex] &= ~move_constants.SQUARE_BBS[targetSquare]; - } - else //is black - { - for (WHITE_START_INDEX..BP) |i| - { - if ((bitboard_array_global[i] & SQUARE_BBS[targetSquare]) != 0) - { + } else { //is black + for (gen_const.WP..gen_const.BP) |i| { + if ((board.bitboard_array_global[i] & move_constants.SQUARE_BBS[targetSquare]) != 0) { captureIndex = i; break; } } - bitboard_array_global[captureIndex] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[captureIndex] &= ~move_constants.SQUARE_BBS[targetSquare]; } - ep_global = NO_SQUARE; + board.ep_global = gen_const.NO_SQUARE; }, 2 => { //white ep //move piece - bitboard_array_global[WP] |= SQUARE_BBS[targetSquare]; - bitboard_array_global[WP] &= ~SQUARE_BBS[startingSquare]; + board.bitboard_array_global[gen_const.WP] |= move_constants.SQUARE_BBS[targetSquare]; + board.bitboard_array_global[gen_const.WP] &= ~move_constants.SQUARE_BBS[startingSquare]; //remove - bitboard_array_global[BP] &= ~SQUARE_BBS[targetSquare + 8]; - ep_global = NO_SQUARE; + board.bitboard_array_global[gen_const.BP] &= ~move_constants.SQUARE_BBS[targetSquare + 8]; + board.ep_global = gen_const.NO_SQUARE; }, 3 => { //black ep //move piece - bitboard_array_global[BP] |= SQUARE_BBS[targetSquare]; - bitboard_array_global[BP] &= ~SQUARE_BBS[startingSquare]; + board.bitboard_array_global[gen_const.BP] |= move_constants.SQUARE_BBS[targetSquare]; + board.bitboard_array_global[gen_const.BP] &= ~move_constants.SQUARE_BBS[startingSquare]; //remove white pawn square up - bitboard_array_global[WP] &= ~SQUARE_BBS[targetSquare - 8]; - ep_global = NO_SQUARE; + board.bitboard_array_global[gen_const.WP] &= ~move_constants.SQUARE_BBS[targetSquare - 8]; + board.ep_global = gen_const.NO_SQUARE; }, 4 => { //WKS //white king - bitboard_array_global[WK] |= SQUARE_BBS[G1]; - bitboard_array_global[WK] &= ~SQUARE_BBS[E1]; + board.bitboard_array_global[gen_const.WK] |= move_constants.SQUARE_BBS[gen_const.G1]; + board.bitboard_array_global[gen_const.WK] &= ~move_constants.SQUARE_BBS[gen_const.E1]; //white rook - bitboard_array_global[WR] |= SQUARE_BBS[F1]; - bitboard_array_global[WR] &= ~SQUARE_BBS[H1]; - castle_rights_global[WKS_CASTLE_RIGHTS] = false; - castle_rights_global[WQS_CASTLE_RIGHTS] = false; - ep_global = NO_SQUARE; + board.bitboard_array_global[gen_const.WR] |= move_constants.SQUARE_BBS[gen_const.F1]; + board.bitboard_array_global[gen_const.WR] &= ~move_constants.SQUARE_BBS[gen_const.H1]; + board.castle_rights_global[gen_const.WKS_CASTLE_RIGHTS] = false; + board.castle_rights_global[gen_const.WQS_CASTLE_RIGHTS] = false; + board.ep_global = gen_const.NO_SQUARE; }, 5 => { //WQS //white king - bitboard_array_global[WK] |= SQUARE_BBS[C1]; - bitboard_array_global[WK] &= ~SQUARE_BBS[E1]; + board.bitboard_array_global[gen_const.WK] |= move_constants.SQUARE_BBS[gen_const.C1]; + board.bitboard_array_global[gen_const.WK] &= ~move_constants.SQUARE_BBS[gen_const.E1]; //white rook - bitboard_array_global[WR] |= SQUARE_BBS[D1]; - bitboard_array_global[WR] &= ~SQUARE_BBS[A1]; - castle_rights_global[WKS_CASTLE_RIGHTS] = false; - castle_rights_global[WQS_CASTLE_RIGHTS] = false; - ep_global = NO_SQUARE; + board.bitboard_array_global[gen_const.WR] |= move_constants.SQUARE_BBS[gen_const.D1]; + board.bitboard_array_global[gen_const.WR] &= ~move_constants.SQUARE_BBS[gen_const.A1]; + board.castle_rights_global[gen_const.WKS_CASTLE_RIGHTS] = false; + board.castle_rights_global[gen_const.WQS_CASTLE_RIGHTS] = false; + board.ep_global = gen_const.NO_SQUARE; }, 6 => { //BKS //white king - bitboard_array_global[BK] |= SQUARE_BBS[G8]; - bitboard_array_global[BK] &= ~SQUARE_BBS[E8]; + board.bitboard_array_global[gen_const.BK] |= move_constants.SQUARE_BBS[gen_const.G8]; + board.bitboard_array_global[gen_const.BK] &= ~move_constants.SQUARE_BBS[gen_const.E8]; //white rook - bitboard_array_global[BR] |= SQUARE_BBS[F8]; - bitboard_array_global[BR] &= ~SQUARE_BBS[H8]; + board.bitboard_array_global[gen_const.BR] |= move_constants.SQUARE_BBS[gen_const.F8]; + board.bitboard_array_global[gen_const.BR] &= ~move_constants.SQUARE_BBS[gen_const.H8]; - castle_rights_global[BKS_CASTLE_RIGHTS] = false; - castle_rights_global[BQS_CASTLE_RIGHTS] = false; - ep_global = NO_SQUARE; + board.castle_rights_global[gen_const.BKS_CASTLE_RIGHTS] = false; + board.castle_rights_global[gen_const.BQS_CASTLE_RIGHTS] = false; + board.ep_global = gen_const.NO_SQUARE; }, 7 => { //BQS //white king - bitboard_array_global[BK] |= SQUARE_BBS[C8]; - bitboard_array_global[BK] &= ~SQUARE_BBS[E8]; + board.bitboard_array_global[gen_const.BK] |= move_constants.SQUARE_BBS[gen_const.C8]; + board.bitboard_array_global[gen_const.BK] &= ~move_constants.SQUARE_BBS[gen_const.E8]; //white rook - bitboard_array_global[BR] |= SQUARE_BBS[D8]; - bitboard_array_global[BR] &= ~SQUARE_BBS[A8]; - castle_rights_global[BKS_CASTLE_RIGHTS] = false; - castle_rights_global[BQS_CASTLE_RIGHTS] = false; - ep_global = NO_SQUARE; + board.bitboard_array_global[gen_const.BR] |= move_constants.SQUARE_BBS[gen_const.D8]; + board.bitboard_array_global[gen_const.BR] &= ~move_constants.SQUARE_BBS[gen_const.A8]; + board.castle_rights_global[gen_const.BKS_CASTLE_RIGHTS] = false; + board.castle_rights_global[gen_const.BQS_CASTLE_RIGHTS] = false; + board.ep_global = gen_const.NO_SQUARE; }, 8 => { //BNPr - bitboard_array_global[BN] |= SQUARE_BBS[targetSquare]; - bitboard_array_global[piece] &= ~SQUARE_BBS[startingSquare]; - ep_global = NO_SQUARE; + board.bitboard_array_global[gen_const.BN] |= move_constants.SQUARE_BBS[targetSquare]; + board.bitboard_array_global[piece] &= ~move_constants.SQUARE_BBS[startingSquare]; + board.ep_global = gen_const.NO_SQUARE; }, 9 => { //BBPr - bitboard_array_global[BB] |= SQUARE_BBS[targetSquare]; - bitboard_array_global[piece] &= ~SQUARE_BBS[startingSquare]; - ep_global = NO_SQUARE; + board.bitboard_array_global[gen_const.BB] |= move_constants.SQUARE_BBS[targetSquare]; + board.bitboard_array_global[piece] &= ~move_constants.SQUARE_BBS[startingSquare]; + board.ep_global = gen_const.NO_SQUARE; }, 10 => { //BQPr - bitboard_array_global[BQ] |= SQUARE_BBS[targetSquare]; - bitboard_array_global[piece] &= ~SQUARE_BBS[startingSquare]; - ep_global = NO_SQUARE; + board.bitboard_array_global[gen_const.BQ] |= move_constants.SQUARE_BBS[targetSquare]; + board.bitboard_array_global[piece] &= ~move_constants.SQUARE_BBS[startingSquare]; + board.ep_global = gen_const.NO_SQUARE; }, 11 => { //BRPr - bitboard_array_global[BR] |= SQUARE_BBS[targetSquare]; - bitboard_array_global[piece] &= ~SQUARE_BBS[startingSquare]; - ep_global = NO_SQUARE; + board.bitboard_array_global[gen_const.BR] |= move_constants.SQUARE_BBS[targetSquare]; + board.bitboard_array_global[piece] &= ~move_constants.SQUARE_BBS[startingSquare]; + board.ep_global = gen_const.NO_SQUARE; }, 12 => { //WNPr - bitboard_array_global[WN] |= SQUARE_BBS[targetSquare]; - bitboard_array_global[piece] &= ~SQUARE_BBS[startingSquare]; - ep_global = NO_SQUARE; + board.bitboard_array_global[gen_const.WN] |= move_constants.SQUARE_BBS[targetSquare]; + board.bitboard_array_global[piece] &= ~move_constants.SQUARE_BBS[startingSquare]; + board.ep_global = gen_const.NO_SQUARE; }, 13 => { //WBPr - bitboard_array_global[WB] |= SQUARE_BBS[targetSquare]; - bitboard_array_global[piece] &= ~SQUARE_BBS[startingSquare]; - ep_global = NO_SQUARE; + board.bitboard_array_global[gen_const.WB] |= move_constants.SQUARE_BBS[targetSquare]; + board.bitboard_array_global[piece] &= ~move_constants.SQUARE_BBS[startingSquare]; + board.ep_global = gen_const.NO_SQUARE; }, 14 => { //WQPr - bitboard_array_global[WQ] |= SQUARE_BBS[targetSquare]; - bitboard_array_global[piece] &= ~SQUARE_BBS[startingSquare]; - ep_global = NO_SQUARE; + board.bitboard_array_global[gen_const.WQ] |= move_constants.SQUARE_BBS[targetSquare]; + board.bitboard_array_global[piece] &= ~move_constants.SQUARE_BBS[startingSquare]; + board.ep_global = gen_const.NO_SQUARE; }, 15 => { //WRPr - bitboard_array_global[WR] |= SQUARE_BBS[targetSquare]; - bitboard_array_global[piece] &= ~SQUARE_BBS[startingSquare]; - ep_global = NO_SQUARE; + board.bitboard_array_global[gen_const.WR] |= move_constants.SQUARE_BBS[targetSquare]; + board.bitboard_array_global[piece] &= ~move_constants.SQUARE_BBS[startingSquare]; + board.ep_global = gen_const.NO_SQUARE; }, 16 => { //BNPrCAP - bitboard_array_global[BN] |= SQUARE_BBS[targetSquare]; - bitboard_array_global[piece] &= ~SQUARE_BBS[startingSquare]; - ep_global = NO_SQUARE; - for (WHITE_START_INDEX..BP) |i| - { - if ((bitboard_array_global[i] & SQUARE_BBS[targetSquare]) != 0) - { + board.bitboard_array_global[gen_const.BN] |= move_constants.SQUARE_BBS[targetSquare]; + board.bitboard_array_global[piece] &= ~move_constants.SQUARE_BBS[startingSquare]; + board.ep_global = gen_const.NO_SQUARE; + for (gen_const.WHITE_START_INDEX..gen_const.BP) |i| { + if ((board.bitboard_array_global[i] & move_constants.SQUARE_BBS[targetSquare]) != 0) { captureIndex = i; break; } } - bitboard_array_global[captureIndex] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[captureIndex] &= ~move_constants.SQUARE_BBS[targetSquare]; }, 17 => { //BBPrCAP - bitboard_array_global[BB] |= SQUARE_BBS[targetSquare]; - bitboard_array_global[piece] &= ~SQUARE_BBS[startingSquare]; - ep_global = NO_SQUARE; - for (WHITE_START_INDEX..BP) |i| - { - if ((bitboard_array_global[i] & SQUARE_BBS[targetSquare]) != 0) - { + board.bitboard_array_global[gen_const.BB] |= move_constants.SQUARE_BBS[targetSquare]; + board.bitboard_array_global[piece] &= ~move_constants.SQUARE_BBS[startingSquare]; + board.ep_global = gen_const.NO_SQUARE; + for (gen_const.WHITE_START_INDEX..gen_const.BP) |i| { + if ((board.bitboard_array_global[i] & move_constants.SQUARE_BBS[targetSquare]) != 0) { captureIndex = i; break; } } - bitboard_array_global[captureIndex] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[captureIndex] &= ~move_constants.SQUARE_BBS[targetSquare]; }, 18 => { //BQPrCAP - bitboard_array_global[BQ] |= SQUARE_BBS[targetSquare]; - bitboard_array_global[piece] &= ~SQUARE_BBS[startingSquare]; - ep_global = NO_SQUARE; - for (WHITE_START_INDEX..BP) |i| - { - if ((bitboard_array_global[i] & SQUARE_BBS[targetSquare]) != 0) - { + board.bitboard_array_global[gen_const.BQ] |= move_constants.SQUARE_BBS[targetSquare]; + board.bitboard_array_global[piece] &= ~move_constants.SQUARE_BBS[startingSquare]; + board.ep_global = gen_const.NO_SQUARE; + for (gen_const.WHITE_START_INDEX..gen_const.BP) |i| { + if ((board.bitboard_array_global[i] & move_constants.SQUARE_BBS[targetSquare]) != 0) { captureIndex = i; break; } } - bitboard_array_global[captureIndex] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[captureIndex] &= ~move_constants.SQUARE_BBS[targetSquare]; }, 19 => { //BRPrCAP - bitboard_array_global[BR] |= SQUARE_BBS[targetSquare]; - bitboard_array_global[piece] &= ~SQUARE_BBS[startingSquare]; - ep_global = NO_SQUARE; - for (WHITE_START_INDEX..BP) |i| { + board.bitboard_array_global[gen_const.BR] |= move_constants.SQUARE_BBS[targetSquare]; + board.bitboard_array_global[piece] &= ~move_constants.SQUARE_BBS[startingSquare]; + board.ep_global = gen_const.NO_SQUARE; + for (gen_const.WHITE_START_INDEX..gen_const.BP) |i| { - if ((bitboard_array_global[i] & SQUARE_BBS[targetSquare]) != 0) - { + if ((board.bitboard_array_global[i] & move_constants.SQUARE_BBS[targetSquare]) != 0) { captureIndex = i; break; } } - bitboard_array_global[captureIndex] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[captureIndex] &= ~move_constants.SQUARE_BBS[targetSquare]; }, 20 => { //WNPrCAP - bitboard_array_global[WN] |= SQUARE_BBS[targetSquare]; - bitboard_array_global[piece] &= ~SQUARE_BBS[startingSquare]; - ep_global = NO_SQUARE; - for (BP..12) |i| - { - if ((bitboard_array_global[i] & SQUARE_BBS[targetSquare]) != 0) - { + board.bitboard_array_global[gen_const.WN] |= move_constants.SQUARE_BBS[targetSquare]; + board.bitboard_array_global[piece] &= ~move_constants.SQUARE_BBS[startingSquare]; + board.ep_global = gen_const.NO_SQUARE; + for (gen_const.BP..12) |i| { + if ((board.bitboard_array_global[i] & move_constants.SQUARE_BBS[targetSquare]) != 0) { captureIndex = i; break; } } - bitboard_array_global[captureIndex] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[captureIndex] &= ~move_constants.SQUARE_BBS[targetSquare]; }, 21 => { //WBPrCAP - bitboard_array_global[WB] |= SQUARE_BBS[targetSquare]; - bitboard_array_global[piece] &= ~SQUARE_BBS[startingSquare]; - ep_global = NO_SQUARE; - for (BP..12) |i| - { - if ((bitboard_array_global[i] & SQUARE_BBS[targetSquare]) != 0) - { + board.bitboard_array_global[gen_const.WB] |= move_constants.SQUARE_BBS[targetSquare]; + board.bitboard_array_global[piece] &= ~move_constants.SQUARE_BBS[startingSquare]; + board.ep_global = gen_const.NO_SQUARE; + for (gen_const.BP..12) |i| { + if ((board.bitboard_array_global[i] & move_constants.SQUARE_BBS[targetSquare]) != 0) { captureIndex = i; break; } } - bitboard_array_global[captureIndex] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[captureIndex] &= ~move_constants.SQUARE_BBS[targetSquare]; }, 22 => { //WQPrCAP - bitboard_array_global[WQ] |= SQUARE_BBS[targetSquare]; - bitboard_array_global[piece] &= ~SQUARE_BBS[startingSquare]; - ep_global = NO_SQUARE; - for (BLACK_START_INDEX..12) |i| - { - if ((bitboard_array_global[i] & SQUARE_BBS[targetSquare]) != 0) - { + board.bitboard_array_global[gen_const.WQ] |= move_constants.SQUARE_BBS[targetSquare]; + board.bitboard_array_global[piece] &= ~move_constants.SQUARE_BBS[startingSquare]; + board.ep_global = gen_const.NO_SQUARE; + for (gen_const.BLACK_START_INDEX..12) |i| { + if ((board.bitboard_array_global[i] & move_constants.SQUARE_BBS[targetSquare]) != 0) { captureIndex = i; break; } } - bitboard_array_global[captureIndex] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[captureIndex] &= ~move_constants.SQUARE_BBS[targetSquare]; }, 23 => { //WRPrCAP - bitboard_array_global[WR] |= SQUARE_BBS[targetSquare]; - bitboard_array_global[piece] &= ~SQUARE_BBS[startingSquare]; + board.bitboard_array_global[gen_const.WR] |= move_constants.SQUARE_BBS[targetSquare]; + board.bitboard_array_global[piece] &= ~move_constants.SQUARE_BBS[startingSquare]; - ep_global = NO_SQUARE; - for (BP..12) |i| - { - if ((bitboard_array_global[i] & SQUARE_BBS[targetSquare]) != 0) - { + board.ep_global = gen_const.NO_SQUARE; + for (gen_const.BP..12) |i| { + if ((board.bitboard_array_global[i] & move_constants.SQUARE_BBS[targetSquare]) != 0) { captureIndex = i; break; } } - bitboard_array_global[captureIndex] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[captureIndex] &= ~move_constants.SQUARE_BBS[targetSquare]; }, 24 => { //WDouble - bitboard_array_global[WP] |= SQUARE_BBS[targetSquare]; - bitboard_array_global[WP] &= ~SQUARE_BBS[startingSquare]; - ep_global = targetSquare + 8; + board.bitboard_array_global[gen_const.WP] |= move_constants.SQUARE_BBS[targetSquare]; + board.bitboard_array_global[gen_const.WP] &= ~move_constants.SQUARE_BBS[startingSquare]; + board.ep_global = targetSquare + 8; }, 25 => { //BDouble - bitboard_array_global[BP] |= SQUARE_BBS[targetSquare]; - bitboard_array_global[BP] &= ~SQUARE_BBS[startingSquare]; - ep_global = targetSquare - 8; + board.bitboard_array_global[gen_const.BP] |= move_constants.SQUARE_BBS[targetSquare]; + board.bitboard_array_global[gen_const.BP] &= ~move_constants.SQUARE_BBS[startingSquare]; + board.ep_global = targetSquare - 8; }, else => { unreachable; } } - if (piece == WK) - { - castle_rights_global[WKS_CASTLE_RIGHTS] = false; - castle_rights_global[WQS_CASTLE_RIGHTS] = false; - } - else if (piece == BK) - { - castle_rights_global[BKS_CASTLE_RIGHTS] = false; - castle_rights_global[BQS_CASTLE_RIGHTS] = false; - } - else if (piece == WR) - { - if (castle_rights_global[WKS_CASTLE_RIGHTS] == true) - { - if ((bitboard_array_global[WR] & SQUARE_BBS[H1]) == 0) - { - castle_rights_global[WKS_CASTLE_RIGHTS] = false; + if (piece == gen_const.WK) { + board.castle_rights_global[gen_const.WKS_CASTLE_RIGHTS] = false; + board.castle_rights_global[gen_const.WQS_CASTLE_RIGHTS] = false; + } else if (piece == gen_const.BK) { + board.castle_rights_global[gen_const.BKS_CASTLE_RIGHTS] = false; + board.castle_rights_global[gen_const.BQS_CASTLE_RIGHTS] = false; + } else if (piece == gen_const.WR) { + if (board.castle_rights_global[gen_const.WKS_CASTLE_RIGHTS] == true) { + if ((board.bitboard_array_global[gen_const.WR] & move_constants.SQUARE_BBS[gen_const.H1]) == 0) { + board.castle_rights_global[gen_const.WKS_CASTLE_RIGHTS] = false; } } - if (castle_rights_global[WQS_CASTLE_RIGHTS] == true) - { - if ((bitboard_array_global[WR] & SQUARE_BBS[A1]) == 0) - { - castle_rights_global[WQS_CASTLE_RIGHTS] = false; + if (board.castle_rights_global[gen_const.WQS_CASTLE_RIGHTS] == true) { + if ((board.bitboard_array_global[gen_const.WR] & move_constants.SQUARE_BBS[gen_const.A1]) == 0){ + board.castle_rights_global[gen_const.WQS_CASTLE_RIGHTS] = false; } } - } - else if (piece == BR) - { - if (castle_rights_global[BKS_CASTLE_RIGHTS] == true) - { - if ((bitboard_array_global[BR] & SQUARE_BBS[H8]) == 0) - { - castle_rights_global[BKS_CASTLE_RIGHTS] = false; + } else if (piece == gen_const.BR) { + if (board.castle_rights_global[gen_const.BKS_CASTLE_RIGHTS] == true) { + if ((board.bitboard_array_global[gen_const.BR] & move_constants.SQUARE_BBS[gen_const.H8]) == 0) { + board.castle_rights_global[gen_const.BKS_CASTLE_RIGHTS] = false; } } - if (castle_rights_global[BQS_CASTLE_RIGHTS] == true) - { - if ((bitboard_array_global[BR] & SQUARE_BBS[A8]) == 0) - { - castle_rights_global[BQS_CASTLE_RIGHTS] = false; + if (board.castle_rights_global[gen_const.BQS_CASTLE_RIGHTS] == true) { + if ((board.bitboard_array_global[gen_const.BR] & move_constants.SQUARE_BBS[gen_const.A8]) == 0) { + board.castle_rights_global[gen_const.BQS_CASTLE_RIGHTS] = false; } } } priorNodes = nodes; - nodes += PerftInlineGlobalOcc(depth - 1, ply + 1); + nodes += perftInline(depth - 1, ply + 1); - is_white_global = !is_white_global; + board.is_white_global = !board.is_white_global; - switch (tag) - { + switch (tag) { 0, 26 => { //check - bitboard_array_global[piece] |= SQUARE_BBS[startingSquare]; - bitboard_array_global[piece] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[piece] |= move_constants.SQUARE_BBS[startingSquare]; + board.bitboard_array_global[piece] &= ~move_constants.SQUARE_BBS[targetSquare]; }, 1, 27 => { //check cap - bitboard_array_global[piece] |= SQUARE_BBS[startingSquare]; - bitboard_array_global[piece] &= ~SQUARE_BBS[targetSquare]; - if (piece >= WP and piece <= WK) - { - bitboard_array_global[captureIndex] |= SQUARE_BBS[targetSquare]; - } - else //is black - { - bitboard_array_global[captureIndex] |= SQUARE_BBS[targetSquare]; + board.bitboard_array_global[piece] |= move_constants.SQUARE_BBS[startingSquare]; + board.bitboard_array_global[piece] &= ~move_constants.SQUARE_BBS[targetSquare]; + if (piece >= gen_const.WP and piece <= gen_const.WK) { + board.bitboard_array_global[captureIndex] |= move_constants.SQUARE_BBS[targetSquare]; + } else { //is black + board.bitboard_array_global[captureIndex] |= move_constants.SQUARE_BBS[targetSquare]; } }, 2 => { //white ep - bitboard_array_global[WP] |= SQUARE_BBS[startingSquare]; - bitboard_array_global[WP] &= ~SQUARE_BBS[targetSquare]; - bitboard_array_global[BP] |= SQUARE_BBS[targetSquare + 8]; + board.bitboard_array_global[gen_const.WP] |= move_constants.SQUARE_BBS[startingSquare]; + board.bitboard_array_global[gen_const.WP] &= ~move_constants.SQUARE_BBS[targetSquare]; + board.bitboard_array_global[gen_const.BP] |= move_constants.SQUARE_BBS[targetSquare + 8]; }, 3 => { //black ep - bitboard_array_global[BP] |= SQUARE_BBS[startingSquare]; - bitboard_array_global[BP] &= ~SQUARE_BBS[targetSquare]; - bitboard_array_global[WP] |= SQUARE_BBS[targetSquare - 8]; + board.bitboard_array_global[gen_const.BP] |= move_constants.SQUARE_BBS[startingSquare]; + board.bitboard_array_global[gen_const.BP] &= ~move_constants.SQUARE_BBS[targetSquare]; + board.bitboard_array_global[gen_const.WP] |= move_constants.SQUARE_BBS[targetSquare - 8]; }, 4 => { //WKS //white king - bitboard_array_global[WK] |= SQUARE_BBS[E1]; - bitboard_array_global[WK] &= ~SQUARE_BBS[G1]; + board.bitboard_array_global[gen_const.WK] |= move_constants.SQUARE_BBS[gen_const.E1]; + board.bitboard_array_global[gen_const.WK] &= ~move_constants.SQUARE_BBS[gen_const.G1]; //white rook - bitboard_array_global[WR] |= SQUARE_BBS[H1]; - bitboard_array_global[WR] &= ~SQUARE_BBS[F1]; + board.bitboard_array_global[gen_const.WR] |= move_constants.SQUARE_BBS[gen_const.H1]; + board.bitboard_array_global[gen_const.WR] &= ~move_constants.SQUARE_BBS[gen_const.F1]; }, 5 => { //WQS //white king - bitboard_array_global[WK] |= SQUARE_BBS[E1]; - bitboard_array_global[WK] &= ~SQUARE_BBS[C1]; + board.bitboard_array_global[gen_const.WK] |= move_constants.SQUARE_BBS[gen_const.E1]; + board.bitboard_array_global[gen_const.WK] &= ~move_constants.SQUARE_BBS[gen_const.C1]; //white rook - bitboard_array_global[WR] |= SQUARE_BBS[A1]; - bitboard_array_global[WR] &= ~SQUARE_BBS[D1]; + board.bitboard_array_global[gen_const.WR] |= move_constants.SQUARE_BBS[gen_const.A1]; + board.bitboard_array_global[gen_const.WR] &= ~move_constants.SQUARE_BBS[gen_const.D1]; }, 6 => { //BKS //white king - bitboard_array_global[BK] |= SQUARE_BBS[E8]; - bitboard_array_global[BK] &= ~SQUARE_BBS[G8]; + board.bitboard_array_global[gen_const.BK] |= move_constants.SQUARE_BBS[gen_const.E8]; + board.bitboard_array_global[gen_const.BK] &= ~move_constants.SQUARE_BBS[gen_const.G8]; //white rook - bitboard_array_global[BR] |= SQUARE_BBS[H8]; - bitboard_array_global[BR] &= ~SQUARE_BBS[F8]; + board.bitboard_array_global[gen_const.BR] |= move_constants.SQUARE_BBS[gen_const.H8]; + board.bitboard_array_global[gen_const.BR] &= ~move_constants.SQUARE_BBS[gen_const.F8]; }, 7 => { //BQS //white king - bitboard_array_global[BK] |= SQUARE_BBS[E8]; - bitboard_array_global[BK] &= ~SQUARE_BBS[C8]; + board.bitboard_array_global[gen_const.BK] |= move_constants.SQUARE_BBS[gen_const.E8]; + board.bitboard_array_global[gen_const.BK] &= ~move_constants.SQUARE_BBS[gen_const.C8]; //white rook - bitboard_array_global[BR] |= SQUARE_BBS[A8]; - bitboard_array_global[BR] &= ~SQUARE_BBS[D8]; + board.bitboard_array_global[gen_const.BR] |= move_constants.SQUARE_BBS[gen_const.A8]; + board.bitboard_array_global[gen_const.BR] &= ~move_constants.SQUARE_BBS[gen_const.D8]; }, 8 => { //BNPr - bitboard_array_global[BP] |= SQUARE_BBS[startingSquare]; - bitboard_array_global[BN] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[gen_const.BP] |= move_constants.SQUARE_BBS[startingSquare]; + board.bitboard_array_global[gen_const.BN] &= ~move_constants.SQUARE_BBS[targetSquare]; }, 9 => { //BBPr - bitboard_array_global[BP] |= SQUARE_BBS[startingSquare]; - bitboard_array_global[BB] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[gen_const.BP] |= move_constants.SQUARE_BBS[startingSquare]; + board.bitboard_array_global[gen_const.BB] &= ~move_constants.SQUARE_BBS[targetSquare]; }, 10 => { //BQPr - bitboard_array_global[BP] |= SQUARE_BBS[startingSquare]; - bitboard_array_global[BQ] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[gen_const.BP] |= move_constants.SQUARE_BBS[startingSquare]; + board.bitboard_array_global[gen_const.BQ] &= ~move_constants.SQUARE_BBS[targetSquare]; }, 11 => { //BRPr - bitboard_array_global[BP] |= SQUARE_BBS[startingSquare]; - bitboard_array_global[BR] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[gen_const.BP] |= move_constants.SQUARE_BBS[startingSquare]; + board.bitboard_array_global[gen_const.BR] &= ~move_constants.SQUARE_BBS[targetSquare]; }, 12 => { //WNPr - bitboard_array_global[WP] |= SQUARE_BBS[startingSquare]; - bitboard_array_global[WN] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[gen_const.WP] |= move_constants.SQUARE_BBS[startingSquare]; + board.bitboard_array_global[gen_const.WN] &= ~move_constants.SQUARE_BBS[targetSquare]; }, 13 => { //WBPr - bitboard_array_global[WP] |= SQUARE_BBS[startingSquare]; - bitboard_array_global[WB] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[gen_const.WP] |= move_constants.SQUARE_BBS[startingSquare]; + board.bitboard_array_global[gen_const.WB] &= ~move_constants.SQUARE_BBS[targetSquare]; }, 14 => { //WQPr - bitboard_array_global[WP] |= SQUARE_BBS[startingSquare]; - bitboard_array_global[WQ] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[gen_const.WP] |= move_constants.SQUARE_BBS[startingSquare]; + board.bitboard_array_global[gen_const.WQ] &= ~move_constants.SQUARE_BBS[targetSquare]; }, 15 => { //WRPr - bitboard_array_global[WP] |= SQUARE_BBS[startingSquare]; - bitboard_array_global[WR] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[gen_const.WP] |= move_constants.SQUARE_BBS[startingSquare]; + board.bitboard_array_global[gen_const.WR] &= ~move_constants.SQUARE_BBS[targetSquare]; }, 16 => { //BNPrCAP - bitboard_array_global[BP] |= SQUARE_BBS[startingSquare]; - bitboard_array_global[BN] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[gen_const.BP] |= move_constants.SQUARE_BBS[startingSquare]; + board.bitboard_array_global[gen_const.BN] &= ~move_constants.SQUARE_BBS[targetSquare]; - bitboard_array_global[captureIndex] |= SQUARE_BBS[targetSquare]; + board.bitboard_array_global[captureIndex] |= move_constants.SQUARE_BBS[targetSquare]; }, 17 => { //BBPrCAP - bitboard_array_global[BP] |= SQUARE_BBS[startingSquare]; - bitboard_array_global[BB] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[gen_const.BP] |= move_constants.SQUARE_BBS[startingSquare]; + board.bitboard_array_global[gen_const.BB] &= ~move_constants.SQUARE_BBS[targetSquare]; - bitboard_array_global[captureIndex] |= SQUARE_BBS[targetSquare]; + board.bitboard_array_global[captureIndex] |= move_constants.SQUARE_BBS[targetSquare]; }, 18 => { //BQPrCAP - bitboard_array_global[BP] |= SQUARE_BBS[startingSquare]; - bitboard_array_global[BQ] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[gen_const.BP] |= move_constants.SQUARE_BBS[startingSquare]; + board.bitboard_array_global[gen_const.BQ] &= ~move_constants.SQUARE_BBS[targetSquare]; - bitboard_array_global[captureIndex] |= SQUARE_BBS[targetSquare]; + board.bitboard_array_global[captureIndex] |= move_constants.SQUARE_BBS[targetSquare]; }, 19 => { //BRPrCAP - bitboard_array_global[BP] |= SQUARE_BBS[startingSquare]; - bitboard_array_global[BR] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[gen_const.BP] |= move_constants.SQUARE_BBS[startingSquare]; + board.bitboard_array_global[gen_const.BR] &= ~move_constants.SQUARE_BBS[targetSquare]; - bitboard_array_global[captureIndex] |= SQUARE_BBS[targetSquare]; + board.bitboard_array_global[captureIndex] |= move_constants.SQUARE_BBS[targetSquare]; }, 20 => { //WNPrCAP - bitboard_array_global[WP] |= SQUARE_BBS[startingSquare]; - bitboard_array_global[WN] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[gen_const.WP] |= move_constants.SQUARE_BBS[startingSquare]; + board.bitboard_array_global[gen_const.WN] &= ~move_constants.SQUARE_BBS[targetSquare]; - bitboard_array_global[captureIndex] |= SQUARE_BBS[targetSquare]; + board.bitboard_array_global[captureIndex] |= move_constants.SQUARE_BBS[targetSquare]; }, 21 => { //WBPrCAP - bitboard_array_global[WP] |= SQUARE_BBS[startingSquare]; - bitboard_array_global[WB] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[gen_const.WP] |= move_constants.SQUARE_BBS[startingSquare]; + board.bitboard_array_global[gen_const.WB] &= ~move_constants.SQUARE_BBS[targetSquare]; - bitboard_array_global[captureIndex] |= SQUARE_BBS[targetSquare]; + board.bitboard_array_global[captureIndex] |= move_constants.SQUARE_BBS[targetSquare]; }, 22 => { //WQPrCAP - bitboard_array_global[WP] |= SQUARE_BBS[startingSquare]; - bitboard_array_global[WQ] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[gen_const.WP] |= move_constants.SQUARE_BBS[startingSquare]; + board.bitboard_array_global[gen_const.WQ] &= ~move_constants.SQUARE_BBS[targetSquare]; - bitboard_array_global[captureIndex] |= SQUARE_BBS[targetSquare]; + board.bitboard_array_global[captureIndex] |= move_constants.SQUARE_BBS[targetSquare]; }, 23 => { //WRPrCAP - bitboard_array_global[WP] |= SQUARE_BBS[startingSquare]; - bitboard_array_global[WR] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[gen_const.WP] |= move_constants.SQUARE_BBS[startingSquare]; + board.bitboard_array_global[gen_const.WR] &= ~move_constants.SQUARE_BBS[targetSquare]; - bitboard_array_global[captureIndex] |= SQUARE_BBS[targetSquare]; + board.bitboard_array_global[captureIndex] |= move_constants.SQUARE_BBS[targetSquare]; }, 24 => { //WDouble - bitboard_array_global[WP] |= SQUARE_BBS[startingSquare]; - bitboard_array_global[WP] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[gen_const.WP] |= move_constants.SQUARE_BBS[startingSquare]; + board.bitboard_array_global[gen_const.WP] &= ~move_constants.SQUARE_BBS[targetSquare]; }, 25 => { //BDouble - bitboard_array_global[BP] |= SQUARE_BBS[startingSquare]; - bitboard_array_global[BP] &= ~SQUARE_BBS[targetSquare]; + board.bitboard_array_global[gen_const.BP] |= move_constants.SQUARE_BBS[startingSquare]; + board.bitboard_array_global[gen_const.BP] &= ~move_constants.SQUARE_BBS[targetSquare]; }, else => { unreachable; } } - castle_rights_global[0] = copy_castle[0]; - castle_rights_global[1] = copy_castle[1]; - castle_rights_global[2] = copy_castle[2]; - castle_rights_global[3] = copy_castle[3]; - ep_global = copyEp; + board.castle_rights_global[0] = copy_castle[0]; + board.castle_rights_global[1] = copy_castle[1]; + board.castle_rights_global[2] = copy_castle[2]; + board.castle_rights_global[3] = copy_castle[3]; + board.ep_global = copyEp; - //if (epGlobal != NO_SQUARE) + //if (epGlobal != general_constants.NO_SQUARE) //{ // std::cout << " ep: " << SQ_CHAR_X[epGlobal] << SQ_CHAR_Y[epGlobal] << '\n'; //} @@ -3140,11 +2847,11 @@ fn PerftInlineGlobalOcc(depth:i8, ply:u8) usize { return nodes; } -fn RunPerftInlineGlobalOcc(depth:i8) void { +pub fn runPerftInline(depth:i8) void { const start_time: i64 = std.time.milliTimestamp(); - const nodes = PerftInlineGlobalOcc(depth, 0); + const nodes = perftInline(depth, 0); const stop_time: i64 = std.time.milliTimestamp(); @@ -3156,5 +2863,5 @@ fn RunPerftInlineGlobalOcc(depth:i8) void { pub fn main() void { ParseFenGlobal(FEN_STARTING_POSITION, 0); - RunPerftInlineGlobalOcc(6); + RunPerftInline(6); }