From 93dd63d5ed536ac579a76ed9fb3880d43d24d4b4 Mon Sep 17 00:00:00 2001 From: Jakob Date: Mon, 5 May 2025 17:47:55 +0200 Subject: [PATCH 1/8] Chore: debug stuff --- src/attacks.zig | 19 +++++----- src/bitboard.zig | 92 +++++++++++++++++++++++++++++++++++++++++------- src/main.zig | 17 +++++---- 3 files changed, 98 insertions(+), 30 deletions(-) diff --git a/src/attacks.zig b/src/attacks.zig index d8e04a2..f387efd 100644 --- a/src/attacks.zig +++ b/src/attacks.zig @@ -40,25 +40,21 @@ pub var pawn_attacks: [2][64]u64 = undefined; pub var pseudo_legal_attacks: [6][64]u64 = undefined; pub fn initialise_pseudo_legal() void { - // copy pawn-attack tables directly pawn_attacks[0] = tabele.White_pawn_attacks_tabele; pawn_attacks[1] = tabele.Black_pawn_attacks_tabele; - // copy fixed knight & king tables const knight_i = @intFromEnum(types.PieceType.Knight); const king_i = @intFromEnum(types.PieceType.King); pseudo_legal_attacks[knight_i] = tabele.Knight_attackes_tabele; pseudo_legal_attacks[king_i] = tabele.King_attackes_tabele; - // build rook, bishop, queen on empty board const rook_i = @intFromEnum(types.PieceType.Rook); const bishop_i = @intFromEnum(types.PieceType.Bishop); const queen_i = @intFromEnum(types.PieceType.Queen); - // single pass over all 64 squares for (types.square_number) |s| { const sq: u8 = @intCast(s); - const occ = 0; // empty occupancy + const occ = 0; // sliding attacks const r_att = get_rook_attacks_for_init(sq, occ); @@ -70,7 +66,6 @@ pub fn initialise_pseudo_legal() void { } } -/// Returns the pawn-attack mask for square `s` (0..63) and color `c` pub inline fn pawn_attacks_from_square(s: usize, c: types.Color) u64 { return pawn_attacks[@intFromEnum(c)][s]; } @@ -216,6 +211,14 @@ pub inline fn get_rook_attacks(square: u6, occ: u64) u64 { const shift: u6 = @intCast(64 - tabele.Rook_index_bit[square]); const relevant: u64 = occ & mask; const idx: usize = @intCast((relevant *% magic) >> shift); + + // const result = Rook_attacks[square][idx]; + // + // std.debug.print("LOOKUP sq={} mask=0x{x} occ&mask=0x{x}\n", .{ square, mask, relevant }); + // std.debug.print(" magic=0x{x} shift={} → idx={} → result=0x{x}\n\n", .{ magic, shift, idx, result }); + // + // bitboard.print_board(result); + // return Rook_attacks[square][idx]; } @@ -272,13 +275,13 @@ pub inline fn get_queen_attacks(square: u6, occ: u64) u64 { return queen_attacks; } -pub fn piece_attacks(square: u6, occ: u64, comptime Piece: types.PieceType) void { +pub fn piece_attacks(square: u6, occ: u64, comptime Piece: types.PieceType) types.Bitboard { if (Piece != types.PieceType.Pawn) { return switch (Piece) { types.PieceType.Bishop => get_bishop_attacks(square, occ), types.PieceType.Rook => get_rook_attacks(square, occ), types.PieceType.Queen => get_queen_attacks(square, occ), - else => print("pseudo legal attacks", .{}), + else => (&pseudo_legal_attacks)[Piece.toU3()][square], }; } else { @panic("don't pass pawns"); diff --git a/src/bitboard.zig b/src/bitboard.zig index 906c46f..6b792af 100644 --- a/src/bitboard.zig +++ b/src/bitboard.zig @@ -2,6 +2,7 @@ const std = @import("std"); const util = @import("util.zig"); const types = @import("types.zig"); const attacks = @import("attacks.zig"); +const tables = @import("tabeles.zig"); const print = std.debug.print; pub fn print_board(bitboard: types.Bitboard) void { @@ -56,8 +57,9 @@ pub fn print_unicode_board(board: types.Board) void { print(" Bitboard: 0x{0x}\n", .{board.pieces_combined()}); print(" Bitboard: 0b{b}\n\n", .{board.pieces_combined()}); } + // TODO fix bug on the whitte side -// 8 . . . . . . . . +// 7 . . . . . . . . // 7 . . . . . . . X // 6 . . . . . . X . // 5 . . . . . X . . @@ -65,7 +67,7 @@ pub fn print_unicode_board(board: types.Board) void { // 3 X X X X X X X X // 2 X X X X X X X X // 1 . X X X X X X . -pub fn print_attacked_squares(board: *types.Board) void { +pub fn print_attacked_squares(board: types.Board) void { const occ = board.pieces_combined(); const bbs = board.pieces; const side = board.side; @@ -76,21 +78,20 @@ pub fn print_attacked_squares(board: *types.Board) void { print(" {} ", .{8 - rank}); for (0..8) |file| { const square: u6 = @intCast(rank * 8 + file); - const sq_bb = types.squar_bb[square]; const attacked = switch (side) { - .White => (attacks.pawn_attacks_from_bitboard(.White, sq_bb) & bbs[@intFromEnum(types.Piece.WHITE_PAWN)]) != 0 or - (attacks.knight_attacks_from_bitboard(sq_bb) & bbs[@intFromEnum(types.Piece.WHITE_KNIGHT)]) != 0 or - (attacks.get_bishop_attacks(square, occ) & bbs[@intFromEnum(types.Piece.WHITE_BISHOP)]) != 0 or - (attacks.get_rook_attacks(square, occ) & bbs[@intFromEnum(types.Piece.WHITE_ROOK)]) != 0 or + .White => (attacks.pawn_attacks_from_square(square, .Black) & bbs[@intFromEnum(types.Piece.WHITE_PAWN)]) != 0 or + (attacks.piece_attacks(square, occ, types.PieceType.Knight) & bbs[@intFromEnum(types.Piece.WHITE_KNIGHT)]) != 0 or + (attacks.piece_attacks(square, occ, types.PieceType.Bishop) & bbs[@intFromEnum(types.Piece.WHITE_BISHOP)]) != 0 or + (attacks.piece_attacks(square, occ, types.PieceType.Rook) & bbs[@intFromEnum(types.Piece.WHITE_ROOK)]) != 0 or (attacks.get_queen_attacks(square, occ) & bbs[@intFromEnum(types.Piece.WHITE_QUEEN)]) != 0 or - (attacks.king_attacks_from_bitboard(sq_bb) & bbs[@intFromEnum(types.Piece.WHITE_KING)]) != 0, + (attacks.piece_attacks(square, occ, types.PieceType.King) & bbs[@intFromEnum(types.Piece.WHITE_KING)]) != 0, - .Black => (attacks.pawn_attacks_from_bitboard(.Black, sq_bb) & bbs[@intFromEnum(types.Piece.BLACK_PAWN)]) != 0 or - (attacks.knight_attacks_from_bitboard(sq_bb) & bbs[@intFromEnum(types.Piece.BLACK_KNIGHT)]) != 0 or - (attacks.get_bishop_attacks(square, occ) & bbs[@intFromEnum(types.Piece.BLACK_BISHOP)]) != 0 or - (attacks.get_rook_attacks(square, occ) & bbs[@intFromEnum(types.Piece.BLACK_ROOK)]) != 0 or + .Black => (attacks.pawn_attacks_from_square(square, .White) & bbs[@intFromEnum(types.Piece.BLACK_PAWN)]) != 0 or + (attacks.piece_attacks(square, occ, types.PieceType.Knight) & bbs[@intFromEnum(types.Piece.BLACK_KNIGHT)]) != 0 or + (attacks.piece_attacks(square, occ, types.PieceType.Bishop) & bbs[@intFromEnum(types.Piece.BLACK_BISHOP)]) != 0 or + (attacks.piece_attacks(square, occ, types.PieceType.Rook) & bbs[@intFromEnum(types.Piece.BLACK_ROOK)]) != 0 or (attacks.get_queen_attacks(square, occ) & bbs[@intFromEnum(types.Piece.BLACK_QUEEN)]) != 0 or - (attacks.king_attacks_from_bitboard(sq_bb) & bbs[@intFromEnum(types.Piece.BLACK_KING)]) != 0, + (attacks.piece_attacks(square, occ, types.PieceType.King) & bbs[@intFromEnum(types.Piece.BLACK_KING)]) != 0, else => unreachable, }; @@ -103,6 +104,71 @@ pub fn print_attacked_squares(board: *types.Board) void { print("\n a b c d e f g h\n", .{}); } +pub fn is_square_attacked( + square: u6, + by: types.Color, + board: types.Board, +) bool { + const occAll = board.pieces_combined(); + + // Bishop/Queen attackers (diagonals) + const bishopMask = attacks.get_bishop_attacks(square, occAll); + const bishopAttackers = bishopMask & (board.pieces[ + if (by == .White) + types.Piece.WHITE_BISHOP.toU4() + else + types.Piece.BLACK_BISHOP.toU4() + ] | board.pieces[ + if (by == .White) + types.Piece.WHITE_QUEEN.toU4() + else + types.Piece.BLACK_QUEEN.toU4() + ]); + std.debug.print(" bishopMask : 0x{x}\n", .{bishopMask}); + std.debug.print(" bishopAttackers: 0x{x}\n", .{bishopAttackers}); + + // Rook/Queen attackers (ranks & files) + const rookMask = attacks.get_rook_attacks(square, occAll); + const rookAttackers = rookMask & (board.pieces[ + if (by == .White) + types.Piece.WHITE_ROOK.toU4() + else + types.Piece.BLACK_ROOK.toU4() + ] | board.pieces[ + if (by == .White) + types.Piece.WHITE_QUEEN.toU4() + else + types.Piece.BLACK_QUEEN.toU4() + ]); + // std.debug.print(" rookMask : 0x{x}\n", .{rookMask}); + // std.debug.print(" rookAttackers : 0x{x}\n", .{rookAttackers}); + + // Combine all attackers + const attackers = bishopAttackers | rookAttackers; + std.debug.print(" combined attackers: 0x{x}\n", .{attackers}); + + return attackers != 0; +} + +pub fn print_attacked_squares_new(board: types.Board) void { + const side = board.side; + + std.debug.print("=== attacked squares for side: {} ===\n", .{side}); + print("\n", .{}); + for (0..8) |r| { + print(" {} ", .{8 - r}); + for (0..8) |c| { + const sq: u6 = @intCast(r * 8 + c); + const attacked = is_square_attacked(sq, side, board); + const ch: u8 = if (attacked) 'X' else '.'; + print(" {c} ", .{ch}); + } + print("\n", .{}); + } + print("\n a b c d e f g h\n\n", .{}); + std.debug.print("=== end attacked squares ===\n", .{}); +} + pub const FenError = error{ InvalidFormat, InvalidPosition, diff --git a/src/main.zig b/src/main.zig index 63d6328..4c53b5b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -10,15 +10,14 @@ pub fn main() !void { attacks.init_attacks(); var b = types.Board.new(); - //try bitboard.fan_pars(types.start_position, &b); + try bitboard.fan_pars(types.start_position, &b); - //const bb = b.pieces_combined(); - //print("Occupancy (hex): 0x{x}\n", .{bb}); - - const mybb = b.set_pieces(types.Color.White); - bitboard.print_board(mybb); - bitboard.print_unicode_board(b); + const bb = b.pieces_combined(); + print("Occupancy (hex): 0x{x}\n", .{bb}); b.side = types.Color.White; - - bitboard.print_attacked_squares(&b); + bitboard.print_unicode_board(b); + //bitboard.print_attacked_squares(&b); + bitboard.print_attacked_squares_new(b); + bitboard.print_unicode_board(b); + bitboard.print_board(b.pieces_combined()); } From ed70404c9ef0fdb1aac13e0cae7494206400981a Mon Sep 17 00:00:00 2001 From: Jakob Date: Tue, 6 May 2025 17:13:10 +0200 Subject: [PATCH 2/8] Chore: add more debuge stuff --- src/bitboard.zig | 1 + src/main.zig | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bitboard.zig b/src/bitboard.zig index 6b792af..daef9bc 100644 --- a/src/bitboard.zig +++ b/src/bitboard.zig @@ -125,6 +125,7 @@ pub fn is_square_attacked( types.Piece.BLACK_QUEEN.toU4() ]); std.debug.print(" bishopMask : 0x{x}\n", .{bishopMask}); + print_board(bishopMask); std.debug.print(" bishopAttackers: 0x{x}\n", .{bishopAttackers}); // Rook/Queen attackers (ranks & files) diff --git a/src/main.zig b/src/main.zig index 4c53b5b..2aacd5a 100644 --- a/src/main.zig +++ b/src/main.zig @@ -14,7 +14,9 @@ pub fn main() !void { const bb = b.pieces_combined(); print("Occupancy (hex): 0x{x}\n", .{bb}); - b.side = types.Color.White; + + bitboard.print_unicode_board(b); + b.side = types.Color.Black; bitboard.print_unicode_board(b); //bitboard.print_attacked_squares(&b); bitboard.print_attacked_squares_new(b); From 80f4386261c025f794638f1b287c11439ca62bc9 Mon Sep 17 00:00:00 2001 From: Jakob Date: Thu, 12 Jun 2025 09:52:16 +0200 Subject: [PATCH 3/8] Chore: add debug stuff --- src/attacks.zig | 30 +- src/bitboard.zig | 37 +- src/main.zig | 6 +- src/types.zig | 4 + temp.txt | 1390 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1446 insertions(+), 21 deletions(-) create mode 100644 temp.txt diff --git a/src/attacks.zig b/src/attacks.zig index f387efd..f5a79be 100644 --- a/src/attacks.zig +++ b/src/attacks.zig @@ -223,17 +223,7 @@ pub inline fn get_rook_attacks(square: u6, occ: u64) u64 { } pub inline fn get_bishop_attacks_for_init(square: u8, occ: u64) u64 { - const rank_i8: i8 = @intCast(square / 8); - const file_i8: i8 = @intCast(square % 8); - const diag_i: i8 = rank_i8 - file_i8 + 7; - const anti_i: i8 = rank_i8 + file_i8; - const diag_idx: usize = @intCast(diag_i); - const anti_idx: usize = @intCast(anti_i); - const mask1: u64 = types.mask_diagonal_nw_se[diag_idx]; - const mask2: u64 = types.mask_anti_diagonal_ne_sw[anti_idx]; - const att1 = sliding_attacks(square, occ, mask1); - const att2 = sliding_attacks(square, occ, mask2); - return att1 | att2; + return get_bishop_attacks_for_init(square, occ); } // bishop magice Bitboards @@ -244,16 +234,28 @@ pub inline fn init_bishop_attackes() void { const mask = tabele.Bishops_attackes_tabele[square]; const relevantBits = tabele.Bishop_index_bit[square]; const magic = tabele.bishop_magics[square]; - const shift: u6 = @truncate(64 - relevantBits); const sq6 = @as(u8, @intCast(square)); - var subset: types.Bitboard = mask; + // Clear the table for this square first + const table_size = @as(usize, 1) << @intCast(relevantBits); + @memset(Bishop_attacks[square][0..table_size], 0); + + var subset: types.Bitboard = mask; while (true) { var idx64: u64 = @as(u64, subset) *% magic; idx64 = idx64 >> shift; const idx: usize = @intCast(idx64); - Bishop_attacks[square][idx] = get_bishop_attacks_for_init(sq6, subset); + + const correct_attacks = get_bishop_attacks_for_init(sq6, subset); + + // Check for collision + if (Bishop_attacks[square][idx] != 0 and Bishop_attacks[square][idx] != correct_attacks) { + std.debug.panic("Magic collision detected for bishop square {} at index {}: existing=0x{x}, new=0x{x}\n", .{ square, idx, Bishop_attacks[square][idx], correct_attacks }); + } + + Bishop_attacks[square][idx] = correct_attacks; + if (subset == 0) break; subset = (subset - 1) & mask; } diff --git a/src/bitboard.zig b/src/bitboard.zig index daef9bc..c4b2a5d 100644 --- a/src/bitboard.zig +++ b/src/bitboard.zig @@ -67,7 +67,7 @@ pub fn print_unicode_board(board: types.Board) void { // 3 X X X X X X X X // 2 X X X X X X X X // 1 . X X X X X X . -pub fn print_attacked_squares(board: types.Board) void { +pub fn print_attacked_squares(board: *types.Board) void { const occ = board.pieces_combined(); const bbs = board.pieces; const side = board.side; @@ -104,6 +104,33 @@ pub fn print_attacked_squares(board: types.Board) void { print("\n a b c d e f g h\n", .{}); } +pub fn debug_bishop_attack(square: u6, occ: u64) void { + const mask = tables.Bishops_attackes_tabele[square]; + const magic = tables.bishop_magics[square]; + const relevantBits = tables.Bishop_index_bit[square]; + const shift: u6 = @intCast(64 - relevantBits); + const relevant = occ & mask; + const raw_idx = (relevant *% magic) >> shift; + const idx: usize = @intCast(raw_idx); + const result = attacks.Bishop_attacks[square][idx]; + + std.debug.print("=== BISHOP DEBUG for square {} ===\n", .{square}); + std.debug.print(" occ=0x{x}\n", .{occ}); + std.debug.print(" mask=0x{x}\n", .{mask}); + std.debug.print(" relevant=0x{x}\n", .{relevant}); + std.debug.print(" magic=0x{x}\n", .{magic}); + std.debug.print(" shift={}\n", .{shift}); + std.debug.print(" raw_idx={}\n", .{raw_idx}); + std.debug.print(" idx={}\n", .{idx}); + std.debug.print(" result=0x{x}\n", .{result}); + + // Compare with direct calculation + const direct = attacks.get_bishop_attacks_for_init(@intCast(square), occ); + std.debug.print(" direct=0x{x}\n", .{direct}); + std.debug.print(" match: {}\n", .{result == direct}); + std.debug.print("===============================\n\n", .{}); +} + pub fn is_square_attacked( square: u6, by: types.Color, @@ -111,6 +138,10 @@ pub fn is_square_attacked( ) bool { const occAll = board.pieces_combined(); + if (square == 15 or square == 22 or square == 29 or square == 36) { // a8 for example, or pick any square showing wrong results + debug_bishop_attack(square, occAll); + } + // Bishop/Queen attackers (diagonals) const bishopMask = attacks.get_bishop_attacks(square, occAll); const bishopAttackers = bishopMask & (board.pieces[ @@ -141,8 +172,8 @@ pub fn is_square_attacked( else types.Piece.BLACK_QUEEN.toU4() ]); - // std.debug.print(" rookMask : 0x{x}\n", .{rookMask}); - // std.debug.print(" rookAttackers : 0x{x}\n", .{rookAttackers}); + std.debug.print(" rookMask : 0x{x}\n", .{rookMask}); + std.debug.print(" rookAttackers : 0x{x}\n", .{rookAttackers}); // Combine all attackers const attackers = bishopAttackers | rookAttackers; diff --git a/src/main.zig b/src/main.zig index 2aacd5a..afaa77a 100644 --- a/src/main.zig +++ b/src/main.zig @@ -16,10 +16,8 @@ pub fn main() !void { print("Occupancy (hex): 0x{x}\n", .{bb}); bitboard.print_unicode_board(b); - b.side = types.Color.Black; + b.side = types.Color.White; bitboard.print_unicode_board(b); - //bitboard.print_attacked_squares(&b); + bitboard.print_attacked_squares(&b); bitboard.print_attacked_squares_new(b); - bitboard.print_unicode_board(b); - bitboard.print_board(b.pieces_combined()); } diff --git a/src/types.zig b/src/types.zig index efe0cc3..7dbd07a 100644 --- a/src/types.zig +++ b/src/types.zig @@ -74,6 +74,10 @@ pub const PieceType = enum(u8) { Rook, Queen, King, + + pub inline fn toU3(self: PieceType) u3 { + return @intFromEnum(self); + } }; pub const Piece = enum(u8) { diff --git a/temp.txt b/temp.txt new file mode 100644 index 0000000..655ebd2 --- /dev/null +++ b/temp.txt @@ -0,0 +1,1390 @@ +Occupancy (hex): 0xffff00000000ffff + + 8 ♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖ + 7 ♙ ♙ ♙ ♙ ♙ ♙ ♙ ♙ + 6 . . . . . . . . + 5 . . . . . . . . + 4 . . . . . . . . + 3 . . . . . . . . + 2 ♟︎ ♟︎ ♟︎ ♟︎ ♟︎ ♟︎ ♟︎ ♟︎ + 1 ♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜ + + a b c d e f g h + + Side: White + Bitboard: 0xffff00000000ffff + Bitboard: 0b1111111111111111000000000000000000000000000000001111111111111111 + + + 8 ♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖ + 7 ♙ ♙ ♙ ♙ ♙ ♙ ♙ ♙ + 6 . . . . . . . . + 5 . . . . . . . . + 4 . . . . . . . . + 3 . . . . . . . . + 2 ♟︎ ♟︎ ♟︎ ♟︎ ♟︎ ♟︎ ♟︎ ♟︎ + 1 ♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜ + + a b c d e f g h + + Side: White + Bitboard: 0xffff00000000ffff + Bitboard: 0b1111111111111111000000000000000000000000000000001111111111111111 + + + 8 . . . . . . . . + 7 . . . . . . . X + 6 . . . . . . X . + 5 . . . . . X . . + 4 . . . . . . . . + 3 X . X X . X . X + 2 X X X X X X X X + 1 X X X X X X X X + + a b c d e f g h +=== attacked squares for side: types.Color.White === + + 8 bishopMask : 0x200 + + 8 0 0 0 0 0 0 0 0 + 7 0 1 0 0 0 0 0 0 + 6 0 0 0 0 0 0 0 0 + 5 0 0 0 0 0 0 0 0 + 4 0 0 0 0 0 0 0 0 + 3 0 0 0 0 0 0 0 0 + 2 0 0 0 0 0 0 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x200 + Bitboard: 0b1000000000 + + bishopAttackers: 0x0 + rookMask : 0x102 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x500 + + 8 0 0 0 0 0 0 0 0 + 7 1 0 1 0 0 0 0 0 + 6 0 0 0 0 0 0 0 0 + 5 0 0 0 0 0 0 0 0 + 4 0 0 0 0 0 0 0 0 + 3 0 0 0 0 0 0 0 0 + 2 0 0 0 0 0 0 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x500 + Bitboard: 0b10100000000 + + bishopAttackers: 0x0 + rookMask : 0x205 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0xa00 + + 8 0 0 0 0 0 0 0 0 + 7 0 1 0 1 0 0 0 0 + 6 0 0 0 0 0 0 0 0 + 5 0 0 0 0 0 0 0 0 + 4 0 0 0 0 0 0 0 0 + 3 0 0 0 0 0 0 0 0 + 2 0 0 0 0 0 0 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0xa00 + Bitboard: 0b101000000000 + + bishopAttackers: 0x0 + rookMask : 0x40a + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x1400 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 1 0 1 0 0 0 + 6 0 0 0 0 0 0 0 0 + 5 0 0 0 0 0 0 0 0 + 4 0 0 0 0 0 0 0 0 + 3 0 0 0 0 0 0 0 0 + 2 0 0 0 0 0 0 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x1400 + Bitboard: 0b1010000000000 + + bishopAttackers: 0x0 + rookMask : 0x814 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x2800 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 1 0 1 0 0 + 6 0 0 0 0 0 0 0 0 + 5 0 0 0 0 0 0 0 0 + 4 0 0 0 0 0 0 0 0 + 3 0 0 0 0 0 0 0 0 + 2 0 0 0 0 0 0 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x2800 + Bitboard: 0b10100000000000 + + bishopAttackers: 0x0 + rookMask : 0x1028 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x5000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 1 0 1 0 + 6 0 0 0 0 0 0 0 0 + 5 0 0 0 0 0 0 0 0 + 4 0 0 0 0 0 0 0 0 + 3 0 0 0 0 0 0 0 0 + 2 0 0 0 0 0 0 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x5000 + Bitboard: 0b101000000000000 + + bishopAttackers: 0x0 + rookMask : 0x2050 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0xa000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 0 1 0 1 + 6 0 0 0 0 0 0 0 0 + 5 0 0 0 0 0 0 0 0 + 4 0 0 0 0 0 0 0 0 + 3 0 0 0 0 0 0 0 0 + 2 0 0 0 0 0 0 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0xa000 + Bitboard: 0b1010000000000000 + + bishopAttackers: 0x0 + rookMask : 0x40a0 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x4000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 0 0 1 0 + 6 0 0 0 0 0 0 0 0 + 5 0 0 0 0 0 0 0 0 + 4 0 0 0 0 0 0 0 0 + 3 0 0 0 0 0 0 0 0 + 2 0 0 0 0 0 0 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x4000 + Bitboard: 0b100000000000000 + + bishopAttackers: 0x0 + rookMask : 0x8040 + rookAttackers : 0x0 + combined attackers: 0x0 + . + 7 bishopMask : 0x20100804020002 + + 8 0 1 0 0 0 0 0 0 + 7 0 0 0 0 0 0 0 0 + 6 0 1 0 0 0 0 0 0 + 5 0 0 1 0 0 0 0 0 + 4 0 0 0 1 0 0 0 0 + 3 0 0 0 0 1 0 0 0 + 2 0 0 0 0 0 1 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x20100804020002 + Bitboard: 0b100000000100000000100000000100000000100000000000000010 + + bishopAttackers: 0x0 + rookMask : 0x1010101010201 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x40201008050005 + + 8 1 0 1 0 0 0 0 0 + 7 0 0 0 0 0 0 0 0 + 6 1 0 1 0 0 0 0 0 + 5 0 0 0 1 0 0 0 0 + 4 0 0 0 0 1 0 0 0 + 3 0 0 0 0 0 1 0 0 + 2 0 0 0 0 0 0 1 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x40201008050005 + Bitboard: 0b1000000001000000001000000001000000001010000000000000101 + + bishopAttackers: 0x0 + rookMask : 0x2020202020502 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x804020110a000a + + 8 0 1 0 1 0 0 0 0 + 7 0 0 0 0 0 0 0 0 + 6 0 1 0 1 0 0 0 0 + 5 1 0 0 0 1 0 0 0 + 4 0 0 0 0 0 1 0 0 + 3 0 0 0 0 0 0 1 0 + 2 0 0 0 0 0 0 0 1 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x804020110a000a + Bitboard: 0b10000000010000000010000000010001000010100000000000001010 + + bishopAttackers: 0x0 + rookMask : 0x4040404040a04 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x804122140014 + + 8 0 0 1 0 1 0 0 0 + 7 0 0 0 0 0 0 0 0 + 6 0 0 1 0 1 0 0 0 + 5 0 1 0 0 0 1 0 0 + 4 1 0 0 0 0 0 1 0 + 3 0 0 0 0 0 0 0 1 + 2 0 0 0 0 0 0 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x804122140014 + Bitboard: 0b100000000100000100100010000101000000000000010100 + + bishopAttackers: 0x0 + rookMask : 0x8080808081408 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x18244280028 + + 8 0 0 0 1 0 1 0 0 + 7 0 0 0 0 0 0 0 0 + 6 0 0 0 1 0 1 0 0 + 5 0 0 1 0 0 0 1 0 + 4 0 1 0 0 0 0 0 1 + 3 1 0 0 0 0 0 0 0 + 2 0 0 0 0 0 0 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x18244280028 + Bitboard: 0b11000001001000100001010000000000000101000 + + bishopAttackers: 0x0 + rookMask : 0x10101010102810 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x1020488500050 + + 8 0 0 0 0 1 0 1 0 + 7 0 0 0 0 0 0 0 0 + 6 0 0 0 0 1 0 1 0 + 5 0 0 0 1 0 0 0 1 + 4 0 0 1 0 0 0 0 0 + 3 0 1 0 0 0 0 0 0 + 2 1 0 0 0 0 0 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x1020488500050 + Bitboard: 0b1000000100000010010001000010100000000000001010000 + + bishopAttackers: 0x0 + rookMask : 0x20202020205020 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x2040810a000a0 + + 8 0 0 0 0 0 1 0 1 + 7 0 0 0 0 0 0 0 0 + 6 0 0 0 0 0 1 0 1 + 5 0 0 0 0 1 0 0 0 + 4 0 0 0 1 0 0 0 0 + 3 0 0 1 0 0 0 0 0 + 2 0 1 0 0 0 0 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x2040810a000a0 + Bitboard: 0b10000001000000100000010000101000000000000010100000 + + bishopAttackers: 0x0 + rookMask : 0x4040404040a040 + rookAttackers : 0x0 + combined attackers: 0x0 + . === BISHOP DEBUG for square 15 === + occ=0xffff00000000ffff + mask=0x4081020400000 + relevant=0x4000000000000 + magic=0x2082082000 + shift=59 + raw_idx=16 + idx=16 + result=0x2040810204080040 + direct=0x40810204080040 + match: false +=============================== + + bishopMask : 0x2040810204080040 + + 8 0 0 0 0 0 0 1 0 + 7 0 0 0 0 0 0 0 0 + 6 0 0 0 1 0 0 0 0 + 5 0 0 1 0 0 0 0 0 + 4 0 1 0 0 0 0 0 0 + 3 1 0 0 0 0 0 0 1 + 2 0 0 0 0 0 0 1 0 + 1 0 0 0 0 0 1 0 0 + + a b c d e f g h + + Bitboard: 0x2040810204080040 + Bitboard: 0b10000001000000100000010000001000000100000010000000000001000000 + + bishopAttackers: 0x2000000000000000 + rookMask : 0x80808080804080 + rookAttackers : 0x0 + combined attackers: 0x2000000000000000 + X + 6 bishopMask : 0x10080402000200 + + 8 0 0 0 0 0 0 0 0 + 7 0 1 0 0 0 0 0 0 + 6 0 0 0 0 0 0 0 0 + 5 0 1 0 0 0 0 0 0 + 4 0 0 1 0 0 0 0 0 + 3 0 0 0 1 0 0 0 0 + 2 0 0 0 0 1 0 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x10080402000200 + Bitboard: 0b10000000010000000010000000010000000000000001000000000 + + bishopAttackers: 0x0 + rookMask : 0x1010101fe0100 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x20100805000500 + + 8 0 0 0 0 0 0 0 0 + 7 1 0 1 0 0 0 0 0 + 6 0 0 0 0 0 0 0 0 + 5 1 0 1 0 0 0 0 0 + 4 0 0 0 1 0 0 0 0 + 3 0 0 0 0 1 0 0 0 + 2 0 0 0 0 0 1 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x20100805000500 + Bitboard: 0b100000000100000000100000000101000000000000010100000000 + + bishopAttackers: 0x0 + rookMask : 0x2020202fd0200 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x4020110a000a00 + + 8 0 0 0 0 0 0 0 0 + 7 0 1 0 1 0 0 0 0 + 6 0 0 0 0 0 0 0 0 + 5 0 1 0 1 0 0 0 0 + 4 1 0 0 0 1 0 0 0 + 3 0 0 0 0 0 1 0 0 + 2 0 0 0 0 0 0 1 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x4020110a000a00 + Bitboard: 0b1000000001000000001000100001010000000000000101000000000 + + bishopAttackers: 0x0 + rookMask : 0x4040404fb0400 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x80412214001400 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 1 0 1 0 0 0 + 6 0 0 0 0 0 0 0 0 + 5 0 0 1 0 1 0 0 0 + 4 0 1 0 0 0 1 0 0 + 3 1 0 0 0 0 0 1 0 + 2 0 0 0 0 0 0 0 1 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x80412214001400 + Bitboard: 0b10000000010000010010001000010100000000000001010000000000 + + bishopAttackers: 0x0 + rookMask : 0x8080808f70800 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x1824428002800 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 1 0 1 0 0 + 6 0 0 0 0 0 0 0 0 + 5 0 0 0 1 0 1 0 0 + 4 0 0 1 0 0 0 1 0 + 3 0 1 0 0 0 0 0 1 + 2 1 0 0 0 0 0 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x1824428002800 + Bitboard: 0b1100000100100010000101000000000000010100000000000 + + bishopAttackers: 0x0 + rookMask : 0x10101010ef1000 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x2048850005000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 1 0 1 0 + 6 0 0 0 0 0 0 0 0 + 5 0 0 0 0 1 0 1 0 + 4 0 0 0 1 0 0 0 1 + 3 0 0 1 0 0 0 0 0 + 2 0 1 0 0 0 0 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x2048850005000 + Bitboard: 0b10000001001000100001010000000000000101000000000000 + + bishopAttackers: 0x0 + rookMask : 0x20202020df2000 + rookAttackers : 0x0 + combined attackers: 0x0 + . === BISHOP DEBUG for square 22 === + occ=0xffff00000000ffff + mask=0x4081020002000 + relevant=0x4000000002000 + magic=0x400082082000 + shift=59 + raw_idx=17 + idx=17 + result=0x2040810284082000 + direct=0x40810284082000 + match: false +=============================== + + bishopMask : 0x2040810284082000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 0 1 0 0 + 6 0 0 0 1 0 0 0 0 + 5 0 0 1 0 0 0 0 1 + 4 0 1 0 0 0 0 0 0 + 3 1 0 0 0 0 0 0 1 + 2 0 0 0 0 0 0 1 0 + 1 0 0 0 0 0 1 0 0 + + a b c d e f g h + + Bitboard: 0x2040810284082000 + Bitboard: 0b10000001000000100000010000001010000100000010000010000000000000 + + bishopAttackers: 0x2000000000000000 + rookMask : 0x40404040bf4000 + rookAttackers : 0x0 + combined attackers: 0x2000000000000000 + X bishopMask : 0x4081020408004000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 0 0 1 0 + 6 0 0 0 0 0 0 0 0 + 5 0 0 0 1 0 0 0 0 + 4 0 0 1 0 0 0 0 0 + 3 0 1 0 0 0 0 0 0 + 2 1 0 0 0 0 0 0 1 + 1 0 0 0 0 0 0 1 0 + + a b c d e f g h + + Bitboard: 0x4081020408004000 + Bitboard: 0b100000010000001000000100000010000001000000000000100000000000000 + + bishopAttackers: 0x0 + rookMask : 0x808080807f8000 + rookAttackers : 0x0 + combined attackers: 0x0 + . + 5 bishopMask : 0x8040200020400 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 1 0 0 0 0 0 + 6 0 1 0 0 0 0 0 0 + 5 0 0 0 0 0 0 0 0 + 4 0 1 0 0 0 0 0 0 + 3 0 0 1 0 0 0 0 0 + 2 0 0 0 1 0 0 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x8040200020400 + Bitboard: 0b1000000001000000001000000000000000100000010000000000 + + bishopAttackers: 0x0 + rookMask : 0x10101fe010100 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x10080500050800 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 1 0 0 0 0 + 6 1 0 1 0 0 0 0 0 + 5 0 0 0 0 0 0 0 0 + 4 1 0 1 0 0 0 0 0 + 3 0 0 0 1 0 0 0 0 + 2 0 0 0 0 1 0 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x10080500050800 + Bitboard: 0b10000000010000000010100000000000001010000100000000000 + + bishopAttackers: 0x0 + rookMask : 0x20202fd020200 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x20110a000a1100 + + 8 0 0 0 0 0 0 0 0 + 7 1 0 0 0 1 0 0 0 + 6 0 1 0 1 0 0 0 0 + 5 0 0 0 0 0 0 0 0 + 4 0 1 0 1 0 0 0 0 + 3 1 0 0 0 1 0 0 0 + 2 0 0 0 0 0 1 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x20110a000a1100 + Bitboard: 0b100000000100010000101000000000000010100001000100000000 + + bishopAttackers: 0x0 + rookMask : 0x40404fb040400 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x41221400142200 + + 8 0 0 0 0 0 0 0 0 + 7 0 1 0 0 0 1 0 0 + 6 0 0 1 0 1 0 0 0 + 5 0 0 0 0 0 0 0 0 + 4 0 0 1 0 1 0 0 0 + 3 0 1 0 0 0 1 0 0 + 2 1 0 0 0 0 0 1 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x41221400142200 + Bitboard: 0b1000001001000100001010000000000000101000010001000000000 + + bishopAttackers: 0x0 + rookMask : 0x80808f7080800 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x82442800284400 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 1 0 0 0 1 0 + 6 0 0 0 1 0 1 0 0 + 5 0 0 0 0 0 0 0 0 + 4 0 0 0 1 0 1 0 0 + 3 0 0 1 0 0 0 1 0 + 2 0 1 0 0 0 0 0 1 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x82442800284400 + Bitboard: 0b10000010010001000010100000000000001010000100010000000000 + + bishopAttackers: 0x0 + rookMask : 0x101010ef101000 + rookAttackers : 0x0 + combined attackers: 0x0 + . === BISHOP DEBUG for square 29 === + occ=0xffff00000000ffff + mask=0x4085000500800 + relevant=0x4000000000800 + magic=0x404002011000 + shift=57 + raw_idx=33 + idx=33 + result=0x2040814204180800 + direct=0x40814204180800 + match: false +=============================== + + bishopMask : 0x2040814204180800 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 1 0 0 0 0 + 6 0 0 0 1 1 0 0 0 + 5 0 0 1 0 0 0 0 0 + 4 0 1 0 0 0 0 1 0 + 3 1 0 0 0 0 0 0 1 + 2 0 0 0 0 0 0 1 0 + 1 0 0 0 0 0 1 0 0 + + a b c d e f g h + + Bitboard: 0x2040814204180800 + Bitboard: 0b10000001000000100000010100001000000100000110000000100000000000 + + bishopAttackers: 0x2000000000000000 + rookMask : 0x202020df202000 + rookAttackers : 0x0 + combined attackers: 0x2000000000000000 + X bishopMask : 0x4081028408201000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 1 0 0 0 + 6 0 0 0 0 0 1 0 0 + 5 0 0 0 1 0 0 0 0 + 4 0 0 1 0 0 0 0 1 + 3 0 1 0 0 0 0 0 0 + 2 1 0 0 0 0 0 0 1 + 1 0 0 0 0 0 0 1 0 + + a b c d e f g h + + Bitboard: 0x4081028408201000 + Bitboard: 0b100000010000001000000101000010000001000001000000001000000000000 + + bishopAttackers: 0x0 + rookMask : 0x404040bf404000 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x8102040800402000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 0 1 0 0 + 6 0 0 0 0 0 0 1 0 + 5 0 0 0 0 0 0 0 0 + 4 0 0 0 1 0 0 0 0 + 3 0 0 1 0 0 0 0 0 + 2 0 1 0 0 0 0 0 0 + 1 1 0 0 0 0 0 0 1 + + a b c d e f g h + + Bitboard: 0x8102040800402000 + Bitboard: 0b1000000100000010000001000000100000000000010000000010000000000000 + + bishopAttackers: 0x0 + rookMask : 0x8080807f808000 + rookAttackers : 0x0 + combined attackers: 0x0 + . + 4 bishopMask : 0x4020002040800 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 1 0 0 0 0 + 6 0 0 1 0 0 0 0 0 + 5 0 1 0 0 0 0 0 0 + 4 0 0 0 0 0 0 0 0 + 3 0 1 0 0 0 0 0 0 + 2 0 0 1 0 0 0 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x4020002040800 + Bitboard: 0b100000000100000000000000010000001000000100000000000 + + bishopAttackers: 0x0 + rookMask : 0x101fe01010100 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x8050005081000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 1 0 0 0 + 6 0 0 0 1 0 0 0 0 + 5 1 0 1 0 0 0 0 0 + 4 0 0 0 0 0 0 0 0 + 3 1 0 1 0 0 0 0 0 + 2 0 0 0 1 0 0 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x8050005081000 + Bitboard: 0b1000000001010000000000000101000010000001000000000000 + + bishopAttackers: 0x0 + rookMask : 0x202fd02020200 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x110a000a112000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 0 1 0 0 + 6 1 0 0 0 1 0 0 0 + 5 0 1 0 1 0 0 0 0 + 4 0 0 0 0 0 0 0 0 + 3 0 1 0 1 0 0 0 0 + 2 1 0 0 0 1 0 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x110a000a112000 + Bitboard: 0b10001000010100000000000001010000100010010000000000000 + + bishopAttackers: 0x0 + rookMask : 0x404fb04040400 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x22140014224100 + + 8 0 0 0 0 0 0 0 0 + 7 1 0 0 0 0 0 1 0 + 6 0 1 0 0 0 1 0 0 + 5 0 0 1 0 1 0 0 0 + 4 0 0 0 0 0 0 0 0 + 3 0 0 1 0 1 0 0 0 + 2 0 1 0 0 0 1 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x22140014224100 + Bitboard: 0b100010000101000000000000010100001000100100000100000000 + + bishopAttackers: 0x0 + rookMask : 0x808f708080800 + rookAttackers : 0x0 + combined attackers: 0x0 + . === BISHOP DEBUG for square 36 === + occ=0xffff00000000ffff + mask=0x44280028440200 + relevant=0x44000000000200 + magic=0x404040040100 + shift=55 + raw_idx=137 + idx=137 + result=0x40a1020c0c0200 + direct=0x40a1020c0c0200 + match: true +=============================== + + bishopMask : 0x40a1020c0c0200 + + 8 0 0 0 0 0 0 0 0 + 7 0 1 0 0 0 0 0 0 + 6 0 0 1 1 0 0 0 0 + 5 0 0 1 1 0 0 0 0 + 4 0 1 0 0 0 0 0 0 + 3 1 0 0 0 0 1 0 1 + 2 0 0 0 0 0 0 1 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x40a1020c0c0200 + Bitboard: 0b1000000101000010000001000001100000011000000001000000000 + + bishopAttackers: 0x0 + rookMask : 0x1010ef10101000 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x4081420418080400 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 1 0 0 0 0 0 + 6 0 0 0 1 0 0 0 0 + 5 0 0 0 1 1 0 0 0 + 4 0 0 1 0 0 0 0 0 + 3 0 1 0 0 0 0 1 0 + 2 1 0 0 0 0 0 0 1 + 1 0 0 0 0 0 0 1 0 + + a b c d e f g h + + Bitboard: 0x4081420418080400 + Bitboard: 0b100000010000001010000100000010000011000000010000000010000000000 + + bishopAttackers: 0x0 + rookMask : 0x2020df20202000 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x8102840820100800 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 1 0 0 0 0 + 6 0 0 0 0 1 0 0 0 + 5 0 0 0 0 0 1 0 0 + 4 0 0 0 1 0 0 0 0 + 3 0 0 1 0 0 0 0 1 + 2 0 1 0 0 0 0 0 0 + 1 1 0 0 0 0 0 0 1 + + a b c d e f g h + + Bitboard: 0x8102840820100800 + Bitboard: 0b1000000100000010100001000000100000100000000100000000100000000000 + + bishopAttackers: 0x0 + rookMask : 0x4040bf40404000 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x20400040201000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 1 0 0 0 + 6 0 0 0 0 0 1 0 0 + 5 0 0 0 0 0 0 1 0 + 4 0 0 0 0 0 0 0 0 + 3 0 0 0 0 0 0 1 0 + 2 0 0 0 0 0 1 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x20400040201000 + Bitboard: 0b100000010000000000000001000000001000000001000000000000 + + bishopAttackers: 0x0 + rookMask : 0x80807f80808000 + rookAttackers : 0x0 + combined attackers: 0x0 + . + 3 bishopMask : 0x2000204081000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 1 0 0 0 + 6 0 0 0 1 0 0 0 0 + 5 0 0 1 0 0 0 0 0 + 4 0 1 0 0 0 0 0 0 + 3 0 0 0 0 0 0 0 0 + 2 0 1 0 0 0 0 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x2000204081000 + Bitboard: 0b10000000000000001000000100000010000001000000000000 + + bishopAttackers: 0x0 + rookMask : 0x1fe0101010100 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x5000508102000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 0 1 0 0 + 6 0 0 0 0 1 0 0 0 + 5 0 0 0 1 0 0 0 0 + 4 1 0 1 0 0 0 0 0 + 3 0 0 0 0 0 0 0 0 + 2 1 0 1 0 0 0 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x5000508102000 + Bitboard: 0b101000000000000010100001000000100000010000000000000 + + bishopAttackers: 0x0 + rookMask : 0x2fd0202020200 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0xa000a11204000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 0 0 1 0 + 6 0 0 0 0 0 1 0 0 + 5 1 0 0 0 1 0 0 0 + 4 0 1 0 1 0 0 0 0 + 3 0 0 0 0 0 0 0 0 + 2 0 1 0 1 0 0 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0xa000a11204000 + Bitboard: 0b1010000000000000101000010001001000000100000000000000 + + bishopAttackers: 0x0 + rookMask : 0x4fb0404040400 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x2050810606090000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 0 0 0 0 + 6 1 0 0 1 0 0 0 0 + 5 0 1 1 0 0 0 0 0 + 4 0 1 1 0 0 0 0 0 + 3 1 0 0 0 0 0 0 1 + 2 0 0 0 0 1 0 1 0 + 1 0 0 0 0 0 1 0 0 + + a b c d e f g h + + Bitboard: 0x2050810606090000 + Bitboard: 0b10000001010000100000010000011000000110000010010000000000000000 + + bishopAttackers: 0x2000000000000000 + rookMask : 0x8f70808080800 + rookAttackers : 0x0 + combined attackers: 0x2000000000000000 + X bishopMask : 0x40a1020c0c020100 + + 8 0 0 0 0 0 0 0 0 + 7 1 0 0 0 0 0 0 0 + 6 0 1 0 0 0 0 0 0 + 5 0 0 1 1 0 0 0 0 + 4 0 0 1 1 0 0 0 0 + 3 0 1 0 0 0 0 0 0 + 2 1 0 0 0 0 1 0 1 + 1 0 0 0 0 0 0 1 0 + + a b c d e f g h + + Bitboard: 0x40a1020c0c020100 + Bitboard: 0b100000010100001000000100000110000001100000000100000000100000000 + + bishopAttackers: 0x0 + rookMask : 0x10ef1010101000 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x8142041808040200 + + 8 0 0 0 0 0 0 0 0 + 7 0 1 0 0 0 0 0 0 + 6 0 0 1 0 0 0 0 0 + 5 0 0 0 1 0 0 0 0 + 4 0 0 0 1 1 0 0 0 + 3 0 0 1 0 0 0 0 0 + 2 0 1 0 0 0 0 1 0 + 1 1 0 0 0 0 0 0 1 + + a b c d e f g h + + Bitboard: 0x8142041808040200 + Bitboard: 0b1000000101000010000001000001100000001000000001000000001000000000 + + bishopAttackers: 0x0 + rookMask : 0x20df2020202000 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0xa000a010080400 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 1 0 0 0 0 0 + 6 0 0 0 1 0 0 0 0 + 5 0 0 0 0 1 0 0 0 + 4 0 0 0 0 0 1 0 1 + 3 0 0 0 0 0 0 0 0 + 2 0 0 0 0 0 1 0 1 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0xa000a010080400 + Bitboard: 0b10100000000000001010000000010000000010000000010000000000 + + bishopAttackers: 0x0 + rookMask : 0x40bf4040404000 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x40004020100800 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 1 0 0 0 0 + 6 0 0 0 0 1 0 0 0 + 5 0 0 0 0 0 1 0 0 + 4 0 0 0 0 0 0 1 0 + 3 0 0 0 0 0 0 0 0 + 2 0 0 0 0 0 0 1 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x40004020100800 + Bitboard: 0b1000000000000000100000000100000000100000000100000000000 + + bishopAttackers: 0x0 + rookMask : 0x807f8080808000 + rookAttackers : 0x0 + combined attackers: 0x0 + . + 2 bishopMask : 0x200020408102000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 0 1 0 0 + 6 0 0 0 0 1 0 0 0 + 5 0 0 0 1 0 0 0 0 + 4 0 0 1 0 0 0 0 0 + 3 0 1 0 0 0 0 0 0 + 2 0 0 0 0 0 0 0 0 + 1 0 1 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x200020408102000 + Bitboard: 0b1000000000000000100000010000001000000100000010000000000000 + + bishopAttackers: 0x0 + rookMask : 0x102010101010100 + rookAttackers : 0x100000000000000 + combined attackers: 0x100000000000000 + X bishopMask : 0x500050810204000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 0 0 1 0 + 6 0 0 0 0 0 1 0 0 + 5 0 0 0 0 1 0 0 0 + 4 0 0 0 1 0 0 0 0 + 3 1 0 1 0 0 0 0 0 + 2 0 0 0 0 0 0 0 0 + 1 1 0 1 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x500050810204000 + Bitboard: 0b10100000000000001010000100000010000001000000100000000000000 + + bishopAttackers: 0x400000000000000 + rookMask : 0x205020202020200 + rookAttackers : 0x0 + combined attackers: 0x400000000000000 + X bishopMask : 0x2840830304080000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 0 0 0 0 + 6 0 0 0 1 0 0 0 0 + 5 0 0 1 0 0 0 0 0 + 4 1 1 0 0 0 0 0 0 + 3 1 1 0 0 0 0 0 1 + 2 0 0 0 0 0 0 1 0 + 1 0 0 0 1 0 1 0 0 + + a b c d e f g h + + Bitboard: 0x2840830304080000 + Bitboard: 0b10100001000000100000110000001100000100000010000000000000000000 + + bishopAttackers: 0x2800000000000000 + rookMask : 0x40a040404040400 + rookAttackers : 0x0 + combined attackers: 0x2800000000000000 + X bishopMask : 0x5081060609000000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 0 0 0 0 + 6 0 0 0 0 0 0 0 0 + 5 1 0 0 1 0 0 0 0 + 4 0 1 1 0 0 0 0 0 + 3 0 1 1 0 0 0 0 0 + 2 1 0 0 0 0 0 0 1 + 1 0 0 0 0 1 0 1 0 + + a b c d e f g h + + Bitboard: 0x5081060609000000 + Bitboard: 0b101000010000001000001100000011000001001000000000000000000000000 + + bishopAttackers: 0x0 + rookMask : 0x814080808080800 + rookAttackers : 0x800000000000000 + combined attackers: 0x800000000000000 + X bishopMask : 0xa1020c0c02010000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 0 0 0 0 + 6 1 0 0 0 0 0 0 0 + 5 0 1 0 0 0 0 0 0 + 4 0 0 1 1 0 0 0 0 + 3 0 0 1 1 0 0 0 0 + 2 0 1 0 0 0 0 0 0 + 1 1 0 0 0 0 1 0 1 + + a b c d e f g h + + Bitboard: 0xa1020c0c02010000 + Bitboard: 0b1010000100000010000011000000110000000010000000010000000000000000 + + bishopAttackers: 0x2000000000000000 + rookMask : 0x1028101010101000 + rookAttackers : 0x0 + combined attackers: 0x2000000000000000 + X bishopMask : 0x5000508804020100 + + 8 0 0 0 0 0 0 0 0 + 7 1 0 0 0 0 0 0 0 + 6 0 1 0 0 0 0 0 0 + 5 0 0 1 0 0 0 0 0 + 4 0 0 0 1 0 0 0 1 + 3 0 0 0 0 1 0 1 0 + 2 0 0 0 0 0 0 0 0 + 1 0 0 0 0 1 0 1 0 + + a b c d e f g h + + Bitboard: 0x5000508804020100 + Bitboard: 0b101000000000000010100001000100000000100000000100000000100000000 + + bishopAttackers: 0x0 + rookMask : 0x2050202020202000 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0xa000a01008040200 + + 8 0 0 0 0 0 0 0 0 + 7 0 1 0 0 0 0 0 0 + 6 0 0 1 0 0 0 0 0 + 5 0 0 0 1 0 0 0 0 + 4 0 0 0 0 1 0 0 0 + 3 0 0 0 0 0 1 0 1 + 2 0 0 0 0 0 0 0 0 + 1 0 0 0 0 0 1 0 1 + + a b c d e f g h + + Bitboard: 0xa000a01008040200 + Bitboard: 0b1010000000000000101000000001000000001000000001000000001000000000 + + bishopAttackers: 0x2000000000000000 + rookMask : 0x40a0404040404000 + rookAttackers : 0x0 + combined attackers: 0x2000000000000000 + X bishopMask : 0x4000402010080400 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 1 0 0 0 0 0 + 6 0 0 0 1 0 0 0 0 + 5 0 0 0 0 1 0 0 0 + 4 0 0 0 0 0 1 0 0 + 3 0 0 0 0 0 0 1 0 + 2 0 0 0 0 0 0 0 0 + 1 0 0 0 0 0 0 1 0 + + a b c d e f g h + + Bitboard: 0x4000402010080400 + Bitboard: 0b100000000000000010000000010000000010000000010000000010000000000 + + bishopAttackers: 0x0 + rookMask : 0x8040808080808000 + rookAttackers : 0x8000000000000000 + combined attackers: 0x8000000000000000 + X + 1 bishopMask : 0x2000000000000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 0 0 0 0 + 6 0 0 0 0 0 0 0 0 + 5 0 0 0 0 0 0 0 0 + 4 0 0 0 0 0 0 0 0 + 3 0 0 0 0 0 0 0 0 + 2 0 1 0 0 0 0 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x2000000000000 + Bitboard: 0b10000000000000000000000000000000000000000000000000 + + bishopAttackers: 0x0 + rookMask : 0x201000000000000 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x2041810204080000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 0 0 0 0 + 6 0 0 0 1 0 0 0 0 + 5 0 0 1 0 0 0 0 0 + 4 0 1 0 0 0 0 0 0 + 3 1 0 0 0 0 0 0 1 + 2 1 0 0 0 0 0 1 0 + 1 0 0 0 0 0 1 0 0 + + a b c d e f g h + + Bitboard: 0x2041810204080000 + Bitboard: 0b10000001000001100000010000001000000100000010000000000000000000 + + bishopAttackers: 0x2000000000000000 + rookMask : 0x502000000000000 + rookAttackers : 0x100000000000000 + combined attackers: 0x2100000000000000 + X bishopMask : 0x4083020408000000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 0 0 0 0 + 6 0 0 0 0 0 0 0 0 + 5 0 0 0 1 0 0 0 0 + 4 0 0 1 0 0 0 0 0 + 3 0 1 0 0 0 0 0 0 + 2 1 1 0 0 0 0 0 1 + 1 0 0 0 0 0 0 1 0 + + a b c d e f g h + + Bitboard: 0x4083020408000000 + Bitboard: 0b100000010000011000000100000010000001000000000000000000000000000 + + bishopAttackers: 0x0 + rookMask : 0xa04000000000000 + rookAttackers : 0x800000000000000 + combined attackers: 0x800000000000000 + X bishopMask : 0x8106040800000000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 0 0 0 0 + 6 0 0 0 0 0 0 0 0 + 5 0 0 0 0 0 0 0 0 + 4 0 0 0 1 0 0 0 0 + 3 0 0 1 0 0 0 0 0 + 2 0 1 1 0 0 0 0 0 + 1 1 0 0 0 0 0 0 1 + + a b c d e f g h + + Bitboard: 0x8106040800000000 + Bitboard: 0b1000000100000110000001000000100000000000000000000000000000000000 + + bishopAttackers: 0x0 + rookMask : 0x1408000000000000 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0x28000000000000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 0 0 0 0 + 6 0 0 0 0 0 0 0 0 + 5 0 0 0 0 0 0 0 0 + 4 0 0 0 0 0 0 0 0 + 3 0 0 0 0 0 0 0 0 + 2 0 0 0 1 0 1 0 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x28000000000000 + Bitboard: 0b101000000000000000000000000000000000000000000000000000 + + bishopAttackers: 0x0 + rookMask : 0x2810000000000000 + rookAttackers : 0x800000000000000 + combined attackers: 0x800000000000000 + X bishopMask : 0x50000000000000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 0 0 0 0 + 6 0 0 0 0 0 0 0 0 + 5 0 0 0 0 0 0 0 0 + 4 0 0 0 0 0 0 0 0 + 3 0 0 0 0 0 0 0 0 + 2 0 0 0 0 1 0 1 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x50000000000000 + Bitboard: 0b1010000000000000000000000000000000000000000000000000000 + + bishopAttackers: 0x0 + rookMask : 0x5020000000000000 + rookAttackers : 0x0 + combined attackers: 0x0 + . bishopMask : 0xa0000000000000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 0 0 0 0 + 6 0 0 0 0 0 0 0 0 + 5 0 0 0 0 0 0 0 0 + 4 0 0 0 0 0 0 0 0 + 3 0 0 0 0 0 0 0 0 + 2 0 0 0 0 0 1 0 1 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0xa0000000000000 + Bitboard: 0b10100000000000000000000000000000000000000000000000000000 + + bishopAttackers: 0x0 + rookMask : 0xa040000000000000 + rookAttackers : 0x8000000000000000 + combined attackers: 0x8000000000000000 + X bishopMask : 0x40000000000000 + + 8 0 0 0 0 0 0 0 0 + 7 0 0 0 0 0 0 0 0 + 6 0 0 0 0 0 0 0 0 + 5 0 0 0 0 0 0 0 0 + 4 0 0 0 0 0 0 0 0 + 3 0 0 0 0 0 0 0 0 + 2 0 0 0 0 0 0 1 0 + 1 0 0 0 0 0 0 0 0 + + a b c d e f g h + + Bitboard: 0x40000000000000 + Bitboard: 0b1000000000000000000000000000000000000000000000000000000 + + bishopAttackers: 0x0 + rookMask : 0x4080000000000000 + rookAttackers : 0x0 + combined attackers: 0x0 + . + + a b c d e f g h + +=== end attacked squares === From ccf0c8121f427a08126ab82244aa1c6aa1abab79 Mon Sep 17 00:00:00 2001 From: Jakob Date: Thu, 12 Jun 2025 14:27:25 +0200 Subject: [PATCH 4/8] test: verifying GPG signature setup --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 340c3ea..e2ee939 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This chess engine is still in development. When I have it in working order and w ## Strength -**TODO:** +**TODO :** - Update the strength table: From e40d2dfcaaa42f7b8ee94fd1444ee9c1506b4adc Mon Sep 17 00:00:00 2001 From: Jakob Date: Thu, 12 Jun 2025 14:46:11 +0200 Subject: [PATCH 5/8] test: verifying GPG signature setup From d57e28cbd1e4f462e8c8a1305f53073aeaf01733 Mon Sep 17 00:00:00 2001 From: Jakob Date: Mon, 16 Jun 2025 14:49:14 +0200 Subject: [PATCH 6/8] Chore: use a difretn methode for bishop attacks --- src/attacks.zig | 102 ++- src/bitboard.zig | 148 ++--- src/main.zig | 4 +- src/move_generation.zig | 4 + src/test.zig | 1 + src/types.zig | 27 +- temp.txt | 1390 --------------------------------------- 7 files changed, 161 insertions(+), 1515 deletions(-) delete mode 100644 temp.txt diff --git a/src/attacks.zig b/src/attacks.zig index f5a79be..9c23189 100644 --- a/src/attacks.zig +++ b/src/attacks.zig @@ -1,9 +1,10 @@ +const print = std.debug.print; const types = @import("types.zig"); const std = @import("std"); -const print = std.debug.print; const tabele = @import("tabeles.zig"); const util = @import("util.zig"); const bitboard = @import("bitboard.zig"); + // generate knight attacks tabele pub inline fn knight_attacks_from_bitboard(bb: types.Bitboard) types.Bitboard { return (((bb << 17) & ~@intFromEnum(types.MaskFile.AFILE)) | @@ -198,7 +199,10 @@ pub inline fn init_rook_attackes() void { var idx64: u64 = @as(u64, subset) *% magic; idx64 = idx64 >> shift; const idx: usize = @intCast(idx64); - Rook_attacks[square][idx] = get_rook_attacks_for_init(sq6, subset); + Rook_attacks[square][idx] = get_rook_attacks_for_init( + sq6, + subset, + ); if (subset == 0) break; subset = (subset - 1) & mask; } @@ -212,18 +216,63 @@ pub inline fn get_rook_attacks(square: u6, occ: u64) u64 { const relevant: u64 = occ & mask; const idx: usize = @intCast((relevant *% magic) >> shift); - // const result = Rook_attacks[square][idx]; - // - // std.debug.print("LOOKUP sq={} mask=0x{x} occ&mask=0x{x}\n", .{ square, mask, relevant }); - // std.debug.print(" magic=0x{x} shift={} → idx={} → result=0x{x}\n\n", .{ magic, shift, idx, result }); - // - // bitboard.print_board(result); - // return Rook_attacks[square][idx]; } -pub inline fn get_bishop_attacks_for_init(square: u8, occ: u64) u64 { - return get_bishop_attacks_for_init(square, occ); +// Correct on-the-fly attack generation for bishops using simple ray-casting. +// This is a one-time cost at initialization. +pub fn get_bishop_attacks_for_init(square: u8, blockers: u64) u64 { + var attacks: u64 = 0; + const r: i8 = @intCast(square / 8); + const f: i8 = @intCast(square % 8); + const one: u64 = 1; + + // North-East + var cr = r + 1; + var cf = f + 1; + while (cr <= 7 and cf <= 7) : ({ + cr += 1; + cf += 1; + }) { + const s = cr * 8 + cf; + attacks |= (one << @intCast(s)); + if ((blockers & (one << @intCast(s))) != 0) break; + } + // South-West + cr = r - 1; + cf = f - 1; + while (cr >= 0 and cf >= 0) : ({ + cr -= 1; + cf -= 1; + }) { + const s = cr * 8 + cf; + attacks |= (one << @intCast(s)); + if ((blockers & (one << @intCast(s))) != 0) break; + } + // North-West + cr = r + 1; + cf = f - 1; + while (cr <= 7 and cf >= 0) : ({ + cr += 1; + cf -= 1; + }) { + const s = cr * 8 + cf; + attacks |= (one << @intCast(s)); + if ((blockers & (one << @intCast(s))) != 0) break; + } + // South-East + cr = r - 1; + cf = f + 1; + while (cr >= 0 and cf <= 7) : ({ + cr -= 1; + cf += 1; + }) { + const s = cr * 8 + cf; + attacks |= (one << @intCast(s)); + if ((blockers & (one << @intCast(s))) != 0) break; + } + + return attacks; } // bishop magice Bitboards @@ -247,11 +296,24 @@ pub inline fn init_bishop_attackes() void { idx64 = idx64 >> shift; const idx: usize = @intCast(idx64); - const correct_attacks = get_bishop_attacks_for_init(sq6, subset); + const correct_attacks = get_bishop_attacks_for_init( + sq6, + subset, + ); // Check for collision - if (Bishop_attacks[square][idx] != 0 and Bishop_attacks[square][idx] != correct_attacks) { - std.debug.panic("Magic collision detected for bishop square {} at index {}: existing=0x{x}, new=0x{x}\n", .{ square, idx, Bishop_attacks[square][idx], correct_attacks }); + if (Bishop_attacks[square][idx] != 0 and + Bishop_attacks[square][idx] != correct_attacks) + { + std.debug.panic( + "Magic collision detected for bishop square {} at index {}: existing=0x{x}, new=0x{x}\n", + .{ + square, + idx, + Bishop_attacks[square][idx], + correct_attacks, + }, + ); } Bishop_attacks[square][idx] = correct_attacks; @@ -267,17 +329,21 @@ pub inline fn get_bishop_attacks(square: u6, occ: u64) u64 { const magic: u64 = tabele.bishop_magics[square]; const shift: u6 = @intCast(64 - tabele.Bishop_index_bit[square]); const relevant: u64 = occ & mask; - const raw_idx: u64 = (relevant *% magic) >> shift; - const idx: usize = @intCast(raw_idx); + const idx: usize = @intCast((relevant *% magic) >> shift); return Bishop_attacks[square][idx]; } pub inline fn get_queen_attacks(square: u6, occ: u64) u64 { - const queen_attacks: u64 = get_bishop_attacks(square, occ) | get_rook_attacks(square, occ); + const queen_attacks: u64 = get_bishop_attacks(square, occ) | + get_rook_attacks(square, occ); return queen_attacks; } -pub fn piece_attacks(square: u6, occ: u64, comptime Piece: types.PieceType) types.Bitboard { +pub fn piece_attacks( + square: u6, + occ: u64, + comptime Piece: types.PieceType, +) types.Bitboard { if (Piece != types.PieceType.Pawn) { return switch (Piece) { types.PieceType.Bishop => get_bishop_attacks(square, occ), diff --git a/src/bitboard.zig b/src/bitboard.zig index c4b2a5d..d66c9a7 100644 --- a/src/bitboard.zig +++ b/src/bitboard.zig @@ -58,15 +58,6 @@ pub fn print_unicode_board(board: types.Board) void { print(" Bitboard: 0b{b}\n\n", .{board.pieces_combined()}); } -// TODO fix bug on the whitte side -// 7 . . . . . . . . -// 7 . . . . . . . X -// 6 . . . . . . X . -// 5 . . . . . X . . -// 4 . . . . . . . . -// 3 X X X X X X X X -// 2 X X X X X X X X -// 1 . X X X X X X . pub fn print_attacked_squares(board: *types.Board) void { const occ = board.pieces_combined(); const bbs = board.pieces; @@ -104,101 +95,78 @@ pub fn print_attacked_squares(board: *types.Board) void { print("\n a b c d e f g h\n", .{}); } -pub fn debug_bishop_attack(square: u6, occ: u64) void { - const mask = tables.Bishops_attackes_tabele[square]; - const magic = tables.bishop_magics[square]; - const relevantBits = tables.Bishop_index_bit[square]; - const shift: u6 = @intCast(64 - relevantBits); - const relevant = occ & mask; - const raw_idx = (relevant *% magic) >> shift; - const idx: usize = @intCast(raw_idx); - const result = attacks.Bishop_attacks[square][idx]; - - std.debug.print("=== BISHOP DEBUG for square {} ===\n", .{square}); - std.debug.print(" occ=0x{x}\n", .{occ}); - std.debug.print(" mask=0x{x}\n", .{mask}); - std.debug.print(" relevant=0x{x}\n", .{relevant}); - std.debug.print(" magic=0x{x}\n", .{magic}); - std.debug.print(" shift={}\n", .{shift}); - std.debug.print(" raw_idx={}\n", .{raw_idx}); - std.debug.print(" idx={}\n", .{idx}); - std.debug.print(" result=0x{x}\n", .{result}); - - // Compare with direct calculation - const direct = attacks.get_bishop_attacks_for_init(@intCast(square), occ); - std.debug.print(" direct=0x{x}\n", .{direct}); - std.debug.print(" match: {}\n", .{result == direct}); - std.debug.print("===============================\n\n", .{}); -} - pub fn is_square_attacked( + board: *const types.Board, square: u6, - by: types.Color, - board: types.Board, + by_side: types.Color, ) bool { - const occAll = board.pieces_combined(); - - if (square == 15 or square == 22 or square == 29 or square == 36) { // a8 for example, or pick any square showing wrong results - debug_bishop_attack(square, occAll); - } - - // Bishop/Queen attackers (diagonals) - const bishopMask = attacks.get_bishop_attacks(square, occAll); - const bishopAttackers = bishopMask & (board.pieces[ - if (by == .White) - types.Piece.WHITE_BISHOP.toU4() - else - types.Piece.BLACK_BISHOP.toU4() - ] | board.pieces[ - if (by == .White) - types.Piece.WHITE_QUEEN.toU4() - else - types.Piece.BLACK_QUEEN.toU4() - ]); - std.debug.print(" bishopMask : 0x{x}\n", .{bishopMask}); - print_board(bishopMask); - std.debug.print(" bishopAttackers: 0x{x}\n", .{bishopAttackers}); + const occ = board.pieces_combined(); + const bbs = board.pieces; - // Rook/Queen attackers (ranks & files) - const rookMask = attacks.get_rook_attacks(square, occAll); - const rookAttackers = rookMask & (board.pieces[ - if (by == .White) - types.Piece.WHITE_ROOK.toU4() - else - types.Piece.BLACK_ROOK.toU4() - ] | board.pieces[ - if (by == .White) - types.Piece.WHITE_QUEEN.toU4() - else - types.Piece.BLACK_QUEEN.toU4() - ]); - std.debug.print(" rookMask : 0x{x}\n", .{rookMask}); - std.debug.print(" rookAttackers : 0x{x}\n", .{rookAttackers}); + return switch (by_side) { + .White => { + // Pawns (reverse attack to find attacker) + if ((attacks.pawn_attacks_from_square(square, .Black) & + bbs[@intFromEnum(types.Piece.WHITE_PAWN)]) != 0) return true; + // Knights + if ((attacks.piece_attacks(square, occ, .Knight) & + bbs[@intFromEnum(types.Piece.WHITE_KNIGHT)]) != 0) return true; + // King + if ((attacks.piece_attacks(square, occ, .King) & + bbs[@intFromEnum(types.Piece.WHITE_KING)]) != 0) return true; + // Bishops & Queens (diagonal) + if ((attacks.piece_attacks(square, occ, .Bishop) & + (bbs[@intFromEnum(types.Piece.WHITE_BISHOP)] | + bbs[@intFromEnum(types.Piece.WHITE_QUEEN)])) != 0) return true; + // Rooks & Queens (orthogonal) + if ((attacks.piece_attacks(square, occ, .Rook) & + (bbs[@intFromEnum(types.Piece.WHITE_ROOK)] | + bbs[@intFromEnum(types.Piece.WHITE_QUEEN)])) != 0) return true; - // Combine all attackers - const attackers = bishopAttackers | rookAttackers; - std.debug.print(" combined attackers: 0x{x}\n", .{attackers}); + return false; + }, + .Black => { + // Pawns (reverse attack to find attacker) + if ((attacks.pawn_attacks_from_square(square, .White) & + bbs[@intFromEnum(types.Piece.BLACK_PAWN)]) != 0) return true; + // Knights + if ((attacks.piece_attacks(square, occ, .Knight) & + bbs[@intFromEnum(types.Piece.BLACK_KNIGHT)]) != 0) return true; + // King + if ((attacks.piece_attacks(square, occ, .King) & + bbs[@intFromEnum(types.Piece.BLACK_KING)]) != 0) return true; + // Bishops & Queens (diagonal) + if ((attacks.piece_attacks(square, occ, .Bishop) & + (bbs[@intFromEnum(types.Piece.BLACK_BISHOP)] | + bbs[@intFromEnum(types.Piece.BLACK_QUEEN)])) != 0) return true; + // Rooks & Queens (orthogonal) + if ((attacks.piece_attacks(square, occ, .Rook) & + (bbs[@intFromEnum(types.Piece.BLACK_ROOK)] | + bbs[@intFromEnum(types.Piece.BLACK_QUEEN)])) != 0) return true; - return attackers != 0; + return false; + }, + .both => unreachable, + }; } -pub fn print_attacked_squares_new(board: types.Board) void { - const side = board.side; - - std.debug.print("=== attacked squares for side: {} ===\n", .{side}); +// This function is now much cleaner and uses the new is_square_attacked function. +pub fn print_attacked_squares_new(board: *types.Board) void { print("\n", .{}); - for (0..8) |r| { - print(" {} ", .{8 - r}); - for (0..8) |c| { - const sq: u6 = @intCast(r * 8 + c); - const attacked = is_square_attacked(sq, side, board); + print("--- Attacked squares for side: {} ---\n", .{board.side}); + + for (0..8) |rank| { + print(" {} ", .{8 - rank}); + for (0..8) |file| { + const square: u6 = @intCast(rank * 8 + file); + const attacked = is_square_attacked(board, square, board.side); const ch: u8 = if (attacked) 'X' else '.'; print(" {c} ", .{ch}); } print("\n", .{}); } - print("\n a b c d e f g h\n\n", .{}); - std.debug.print("=== end attacked squares ===\n", .{}); + + print("\n a b c d e f g h\n", .{}); } pub const FenError = error{ diff --git a/src/main.zig b/src/main.zig index afaa77a..55859cc 100644 --- a/src/main.zig +++ b/src/main.zig @@ -15,9 +15,7 @@ pub fn main() !void { const bb = b.pieces_combined(); print("Occupancy (hex): 0x{x}\n", .{bb}); - bitboard.print_unicode_board(b); b.side = types.Color.White; - bitboard.print_unicode_board(b); bitboard.print_attacked_squares(&b); - bitboard.print_attacked_squares_new(b); + bitboard.print_attacked_squares_new(&b); } diff --git a/src/move_generation.zig b/src/move_generation.zig index 0237d69..ec35dea 100644 --- a/src/move_generation.zig +++ b/src/move_generation.zig @@ -15,5 +15,9 @@ pub const Move = struct { }; pub fn generate_moves(list: *lists.MoveList) void { + const us = types.Board.side; // side to move + const them = if (types.Board.side == .white) .black else .white; + _ = us; + _ = them; _ = list; } diff --git a/src/test.zig b/src/test.zig index 7d4aa33..ff1db05 100644 --- a/src/test.zig +++ b/src/test.zig @@ -16,6 +16,7 @@ test "test print bitboard" { test "test print bitboard unicode" { var b: types.Board = .{ .pieces = [_]types.Bitboard{0} ** types.Board.PieceCount, + .board = undefined, .side = types.Color.Black, .enpassant = types.square.e3, .castle = @intFromEnum(types.Castle.WK) | @intFromEnum(types.Castle.WQ) | @intFromEnum(types.Castle.BK) | @intFromEnum(types.Castle.BQ), diff --git a/src/types.zig b/src/types.zig index 7dbd07a..38a11b2 100644 --- a/src/types.zig +++ b/src/types.zig @@ -115,16 +115,16 @@ pub const MoveFlags = enum(u4) { CAPTURE = 0b1000, // 8 CAPTURES = 0b1011, // 11 EN_PASSANT = 0b1010, // 10 - + // Promotions (no capture) PR_KNIGHT = 0b0100, // 4 PR_BISHOP = 0b0101, // 5 - PR_ROOK = 0b0110, // 6 - PR_QUEEN = 0b0111, // 7 + PR_ROOK = 0b0110, // 6 + PR_QUEEN = 0b0111, // 7 PC_KNIGHT = 0b1100, // 12 PC_BISHOP = 0b1101, // 13 - PC_ROOK = 0b1110, // 14 - PC_QUEEN = 0b1111, // 15 + PC_ROOK = 0b1110, // 14 + PC_QUEEN = 0b1111, // 15 }; pub const Castle = enum(u8) { @@ -138,10 +138,11 @@ pub const Board = struct { pub const PieceCount = @intFromEnum(Piece.NO_PIECE) + 1; pieces: [PieceCount]Bitboard, + board: [64]Piece, side: Color, enpassant: square, castle: u8, // bitmask of Castle.* - + pub fn pieces_combined(self: *const Board) Bitboard { var bb: Bitboard = 0; for (self.pieces) |p| bb |= p; @@ -151,30 +152,28 @@ pub const Board = struct { pub fn new() Board { var b: Board = undefined; - @memset(b.pieces[0..],0); + @memset(b.pieces[0..], 0); b.side = Color.White; b.enpassant = square.NO_SQUARE; b.castle = 0; - return b; + return b; } - pub inline fn set_pieces(self: *Board, comptime c: Color) Bitboard{ + pub inline fn set_pieces(self: *Board, comptime c: Color) Bitboard { return if (c == Color.White) self.pieces[Piece.WHITE_PAWN.toU4()] * 8 | self.pieces[Piece.WHITE_KNIGHT.toU4()] | self.pieces[Piece.WHITE_BISHOP.toU4()] | self.pieces[Piece.WHITE_QUEEN.toU4()] | self.pieces[Piece.WHITE_KING.toU4()] else - self.pieces[Piece.BLACK_PAWN.toU4()] * 8 | self.pieces[Piece.BLACK_KNIGHT.toU4()] | self.pieces[Piece.BLACK_BISHOP.toU4()] | self.pieces[Piece.BLACK_QUEEN.toU4()] | self.pieces[Piece.BLACK_KING.toU4()]; - + self.pieces[Piece.BLACK_PAWN.toU4()] * 8 | self.pieces[Piece.BLACK_KNIGHT.toU4()] | self.pieces[Piece.BLACK_BISHOP.toU4()] | self.pieces[Piece.BLACK_QUEEN.toU4()] | self.pieces[Piece.BLACK_KING.toU4()]; } pub inline fn set_white(self: *Board) Bitboard { - return self.pieces[Piece.WHITE_PAWN.toU4()] * 8 | self.pieces[Piece.WHITE_KNIGHT.toU4()] | self.pieces[Piece.WHITE_BISHOP.toU4()] | self.pieces[Piece.WHITE_QUEEN.toU4()] | self.pieces[Piece.WHITE_KING.toU4()]; + return self.pieces[Piece.WHITE_PAWN.toU4()] * 8 | self.pieces[Piece.WHITE_KNIGHT.toU4()] | self.pieces[Piece.WHITE_BISHOP.toU4()] | self.pieces[Piece.WHITE_QUEEN.toU4()] | self.pieces[Piece.WHITE_KING.toU4()]; } pub inline fn set_black(self: *Board) Bitboard { - return self.pieces[Piece.BLACK_PAWN.toU4()] * 8 | self.pieces[Piece.BLACK_KNIGHT.toU4()] | self.pieces[Piece.BLACK_BISHOP.toU4()] | self.pieces[Piece.BLACK_QUEEN.toU4()] | self.pieces[Piece.BLACK_KING.toU4()]; + return self.pieces[Piece.BLACK_PAWN.toU4()] * 8 | self.pieces[Piece.BLACK_KNIGHT.toU4()] | self.pieces[Piece.BLACK_BISHOP.toU4()] | self.pieces[Piece.BLACK_QUEEN.toU4()] | self.pieces[Piece.BLACK_KING.toU4()]; } }; - // Attacking directions for the pieces pub const Direction = enum(i32) { North = 8, diff --git a/temp.txt b/temp.txt deleted file mode 100644 index 655ebd2..0000000 --- a/temp.txt +++ /dev/null @@ -1,1390 +0,0 @@ -Occupancy (hex): 0xffff00000000ffff - - 8 ♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖ - 7 ♙ ♙ ♙ ♙ ♙ ♙ ♙ ♙ - 6 . . . . . . . . - 5 . . . . . . . . - 4 . . . . . . . . - 3 . . . . . . . . - 2 ♟︎ ♟︎ ♟︎ ♟︎ ♟︎ ♟︎ ♟︎ ♟︎ - 1 ♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜ - - a b c d e f g h - - Side: White - Bitboard: 0xffff00000000ffff - Bitboard: 0b1111111111111111000000000000000000000000000000001111111111111111 - - - 8 ♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖ - 7 ♙ ♙ ♙ ♙ ♙ ♙ ♙ ♙ - 6 . . . . . . . . - 5 . . . . . . . . - 4 . . . . . . . . - 3 . . . . . . . . - 2 ♟︎ ♟︎ ♟︎ ♟︎ ♟︎ ♟︎ ♟︎ ♟︎ - 1 ♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜ - - a b c d e f g h - - Side: White - Bitboard: 0xffff00000000ffff - Bitboard: 0b1111111111111111000000000000000000000000000000001111111111111111 - - - 8 . . . . . . . . - 7 . . . . . . . X - 6 . . . . . . X . - 5 . . . . . X . . - 4 . . . . . . . . - 3 X . X X . X . X - 2 X X X X X X X X - 1 X X X X X X X X - - a b c d e f g h -=== attacked squares for side: types.Color.White === - - 8 bishopMask : 0x200 - - 8 0 0 0 0 0 0 0 0 - 7 0 1 0 0 0 0 0 0 - 6 0 0 0 0 0 0 0 0 - 5 0 0 0 0 0 0 0 0 - 4 0 0 0 0 0 0 0 0 - 3 0 0 0 0 0 0 0 0 - 2 0 0 0 0 0 0 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x200 - Bitboard: 0b1000000000 - - bishopAttackers: 0x0 - rookMask : 0x102 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x500 - - 8 0 0 0 0 0 0 0 0 - 7 1 0 1 0 0 0 0 0 - 6 0 0 0 0 0 0 0 0 - 5 0 0 0 0 0 0 0 0 - 4 0 0 0 0 0 0 0 0 - 3 0 0 0 0 0 0 0 0 - 2 0 0 0 0 0 0 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x500 - Bitboard: 0b10100000000 - - bishopAttackers: 0x0 - rookMask : 0x205 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0xa00 - - 8 0 0 0 0 0 0 0 0 - 7 0 1 0 1 0 0 0 0 - 6 0 0 0 0 0 0 0 0 - 5 0 0 0 0 0 0 0 0 - 4 0 0 0 0 0 0 0 0 - 3 0 0 0 0 0 0 0 0 - 2 0 0 0 0 0 0 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0xa00 - Bitboard: 0b101000000000 - - bishopAttackers: 0x0 - rookMask : 0x40a - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x1400 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 1 0 1 0 0 0 - 6 0 0 0 0 0 0 0 0 - 5 0 0 0 0 0 0 0 0 - 4 0 0 0 0 0 0 0 0 - 3 0 0 0 0 0 0 0 0 - 2 0 0 0 0 0 0 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x1400 - Bitboard: 0b1010000000000 - - bishopAttackers: 0x0 - rookMask : 0x814 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x2800 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 1 0 1 0 0 - 6 0 0 0 0 0 0 0 0 - 5 0 0 0 0 0 0 0 0 - 4 0 0 0 0 0 0 0 0 - 3 0 0 0 0 0 0 0 0 - 2 0 0 0 0 0 0 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x2800 - Bitboard: 0b10100000000000 - - bishopAttackers: 0x0 - rookMask : 0x1028 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x5000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 1 0 1 0 - 6 0 0 0 0 0 0 0 0 - 5 0 0 0 0 0 0 0 0 - 4 0 0 0 0 0 0 0 0 - 3 0 0 0 0 0 0 0 0 - 2 0 0 0 0 0 0 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x5000 - Bitboard: 0b101000000000000 - - bishopAttackers: 0x0 - rookMask : 0x2050 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0xa000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 0 1 0 1 - 6 0 0 0 0 0 0 0 0 - 5 0 0 0 0 0 0 0 0 - 4 0 0 0 0 0 0 0 0 - 3 0 0 0 0 0 0 0 0 - 2 0 0 0 0 0 0 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0xa000 - Bitboard: 0b1010000000000000 - - bishopAttackers: 0x0 - rookMask : 0x40a0 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x4000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 0 0 1 0 - 6 0 0 0 0 0 0 0 0 - 5 0 0 0 0 0 0 0 0 - 4 0 0 0 0 0 0 0 0 - 3 0 0 0 0 0 0 0 0 - 2 0 0 0 0 0 0 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x4000 - Bitboard: 0b100000000000000 - - bishopAttackers: 0x0 - rookMask : 0x8040 - rookAttackers : 0x0 - combined attackers: 0x0 - . - 7 bishopMask : 0x20100804020002 - - 8 0 1 0 0 0 0 0 0 - 7 0 0 0 0 0 0 0 0 - 6 0 1 0 0 0 0 0 0 - 5 0 0 1 0 0 0 0 0 - 4 0 0 0 1 0 0 0 0 - 3 0 0 0 0 1 0 0 0 - 2 0 0 0 0 0 1 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x20100804020002 - Bitboard: 0b100000000100000000100000000100000000100000000000000010 - - bishopAttackers: 0x0 - rookMask : 0x1010101010201 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x40201008050005 - - 8 1 0 1 0 0 0 0 0 - 7 0 0 0 0 0 0 0 0 - 6 1 0 1 0 0 0 0 0 - 5 0 0 0 1 0 0 0 0 - 4 0 0 0 0 1 0 0 0 - 3 0 0 0 0 0 1 0 0 - 2 0 0 0 0 0 0 1 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x40201008050005 - Bitboard: 0b1000000001000000001000000001000000001010000000000000101 - - bishopAttackers: 0x0 - rookMask : 0x2020202020502 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x804020110a000a - - 8 0 1 0 1 0 0 0 0 - 7 0 0 0 0 0 0 0 0 - 6 0 1 0 1 0 0 0 0 - 5 1 0 0 0 1 0 0 0 - 4 0 0 0 0 0 1 0 0 - 3 0 0 0 0 0 0 1 0 - 2 0 0 0 0 0 0 0 1 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x804020110a000a - Bitboard: 0b10000000010000000010000000010001000010100000000000001010 - - bishopAttackers: 0x0 - rookMask : 0x4040404040a04 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x804122140014 - - 8 0 0 1 0 1 0 0 0 - 7 0 0 0 0 0 0 0 0 - 6 0 0 1 0 1 0 0 0 - 5 0 1 0 0 0 1 0 0 - 4 1 0 0 0 0 0 1 0 - 3 0 0 0 0 0 0 0 1 - 2 0 0 0 0 0 0 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x804122140014 - Bitboard: 0b100000000100000100100010000101000000000000010100 - - bishopAttackers: 0x0 - rookMask : 0x8080808081408 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x18244280028 - - 8 0 0 0 1 0 1 0 0 - 7 0 0 0 0 0 0 0 0 - 6 0 0 0 1 0 1 0 0 - 5 0 0 1 0 0 0 1 0 - 4 0 1 0 0 0 0 0 1 - 3 1 0 0 0 0 0 0 0 - 2 0 0 0 0 0 0 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x18244280028 - Bitboard: 0b11000001001000100001010000000000000101000 - - bishopAttackers: 0x0 - rookMask : 0x10101010102810 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x1020488500050 - - 8 0 0 0 0 1 0 1 0 - 7 0 0 0 0 0 0 0 0 - 6 0 0 0 0 1 0 1 0 - 5 0 0 0 1 0 0 0 1 - 4 0 0 1 0 0 0 0 0 - 3 0 1 0 0 0 0 0 0 - 2 1 0 0 0 0 0 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x1020488500050 - Bitboard: 0b1000000100000010010001000010100000000000001010000 - - bishopAttackers: 0x0 - rookMask : 0x20202020205020 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x2040810a000a0 - - 8 0 0 0 0 0 1 0 1 - 7 0 0 0 0 0 0 0 0 - 6 0 0 0 0 0 1 0 1 - 5 0 0 0 0 1 0 0 0 - 4 0 0 0 1 0 0 0 0 - 3 0 0 1 0 0 0 0 0 - 2 0 1 0 0 0 0 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x2040810a000a0 - Bitboard: 0b10000001000000100000010000101000000000000010100000 - - bishopAttackers: 0x0 - rookMask : 0x4040404040a040 - rookAttackers : 0x0 - combined attackers: 0x0 - . === BISHOP DEBUG for square 15 === - occ=0xffff00000000ffff - mask=0x4081020400000 - relevant=0x4000000000000 - magic=0x2082082000 - shift=59 - raw_idx=16 - idx=16 - result=0x2040810204080040 - direct=0x40810204080040 - match: false -=============================== - - bishopMask : 0x2040810204080040 - - 8 0 0 0 0 0 0 1 0 - 7 0 0 0 0 0 0 0 0 - 6 0 0 0 1 0 0 0 0 - 5 0 0 1 0 0 0 0 0 - 4 0 1 0 0 0 0 0 0 - 3 1 0 0 0 0 0 0 1 - 2 0 0 0 0 0 0 1 0 - 1 0 0 0 0 0 1 0 0 - - a b c d e f g h - - Bitboard: 0x2040810204080040 - Bitboard: 0b10000001000000100000010000001000000100000010000000000001000000 - - bishopAttackers: 0x2000000000000000 - rookMask : 0x80808080804080 - rookAttackers : 0x0 - combined attackers: 0x2000000000000000 - X - 6 bishopMask : 0x10080402000200 - - 8 0 0 0 0 0 0 0 0 - 7 0 1 0 0 0 0 0 0 - 6 0 0 0 0 0 0 0 0 - 5 0 1 0 0 0 0 0 0 - 4 0 0 1 0 0 0 0 0 - 3 0 0 0 1 0 0 0 0 - 2 0 0 0 0 1 0 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x10080402000200 - Bitboard: 0b10000000010000000010000000010000000000000001000000000 - - bishopAttackers: 0x0 - rookMask : 0x1010101fe0100 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x20100805000500 - - 8 0 0 0 0 0 0 0 0 - 7 1 0 1 0 0 0 0 0 - 6 0 0 0 0 0 0 0 0 - 5 1 0 1 0 0 0 0 0 - 4 0 0 0 1 0 0 0 0 - 3 0 0 0 0 1 0 0 0 - 2 0 0 0 0 0 1 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x20100805000500 - Bitboard: 0b100000000100000000100000000101000000000000010100000000 - - bishopAttackers: 0x0 - rookMask : 0x2020202fd0200 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x4020110a000a00 - - 8 0 0 0 0 0 0 0 0 - 7 0 1 0 1 0 0 0 0 - 6 0 0 0 0 0 0 0 0 - 5 0 1 0 1 0 0 0 0 - 4 1 0 0 0 1 0 0 0 - 3 0 0 0 0 0 1 0 0 - 2 0 0 0 0 0 0 1 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x4020110a000a00 - Bitboard: 0b1000000001000000001000100001010000000000000101000000000 - - bishopAttackers: 0x0 - rookMask : 0x4040404fb0400 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x80412214001400 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 1 0 1 0 0 0 - 6 0 0 0 0 0 0 0 0 - 5 0 0 1 0 1 0 0 0 - 4 0 1 0 0 0 1 0 0 - 3 1 0 0 0 0 0 1 0 - 2 0 0 0 0 0 0 0 1 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x80412214001400 - Bitboard: 0b10000000010000010010001000010100000000000001010000000000 - - bishopAttackers: 0x0 - rookMask : 0x8080808f70800 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x1824428002800 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 1 0 1 0 0 - 6 0 0 0 0 0 0 0 0 - 5 0 0 0 1 0 1 0 0 - 4 0 0 1 0 0 0 1 0 - 3 0 1 0 0 0 0 0 1 - 2 1 0 0 0 0 0 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x1824428002800 - Bitboard: 0b1100000100100010000101000000000000010100000000000 - - bishopAttackers: 0x0 - rookMask : 0x10101010ef1000 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x2048850005000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 1 0 1 0 - 6 0 0 0 0 0 0 0 0 - 5 0 0 0 0 1 0 1 0 - 4 0 0 0 1 0 0 0 1 - 3 0 0 1 0 0 0 0 0 - 2 0 1 0 0 0 0 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x2048850005000 - Bitboard: 0b10000001001000100001010000000000000101000000000000 - - bishopAttackers: 0x0 - rookMask : 0x20202020df2000 - rookAttackers : 0x0 - combined attackers: 0x0 - . === BISHOP DEBUG for square 22 === - occ=0xffff00000000ffff - mask=0x4081020002000 - relevant=0x4000000002000 - magic=0x400082082000 - shift=59 - raw_idx=17 - idx=17 - result=0x2040810284082000 - direct=0x40810284082000 - match: false -=============================== - - bishopMask : 0x2040810284082000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 0 1 0 0 - 6 0 0 0 1 0 0 0 0 - 5 0 0 1 0 0 0 0 1 - 4 0 1 0 0 0 0 0 0 - 3 1 0 0 0 0 0 0 1 - 2 0 0 0 0 0 0 1 0 - 1 0 0 0 0 0 1 0 0 - - a b c d e f g h - - Bitboard: 0x2040810284082000 - Bitboard: 0b10000001000000100000010000001010000100000010000010000000000000 - - bishopAttackers: 0x2000000000000000 - rookMask : 0x40404040bf4000 - rookAttackers : 0x0 - combined attackers: 0x2000000000000000 - X bishopMask : 0x4081020408004000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 0 0 1 0 - 6 0 0 0 0 0 0 0 0 - 5 0 0 0 1 0 0 0 0 - 4 0 0 1 0 0 0 0 0 - 3 0 1 0 0 0 0 0 0 - 2 1 0 0 0 0 0 0 1 - 1 0 0 0 0 0 0 1 0 - - a b c d e f g h - - Bitboard: 0x4081020408004000 - Bitboard: 0b100000010000001000000100000010000001000000000000100000000000000 - - bishopAttackers: 0x0 - rookMask : 0x808080807f8000 - rookAttackers : 0x0 - combined attackers: 0x0 - . - 5 bishopMask : 0x8040200020400 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 1 0 0 0 0 0 - 6 0 1 0 0 0 0 0 0 - 5 0 0 0 0 0 0 0 0 - 4 0 1 0 0 0 0 0 0 - 3 0 0 1 0 0 0 0 0 - 2 0 0 0 1 0 0 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x8040200020400 - Bitboard: 0b1000000001000000001000000000000000100000010000000000 - - bishopAttackers: 0x0 - rookMask : 0x10101fe010100 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x10080500050800 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 1 0 0 0 0 - 6 1 0 1 0 0 0 0 0 - 5 0 0 0 0 0 0 0 0 - 4 1 0 1 0 0 0 0 0 - 3 0 0 0 1 0 0 0 0 - 2 0 0 0 0 1 0 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x10080500050800 - Bitboard: 0b10000000010000000010100000000000001010000100000000000 - - bishopAttackers: 0x0 - rookMask : 0x20202fd020200 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x20110a000a1100 - - 8 0 0 0 0 0 0 0 0 - 7 1 0 0 0 1 0 0 0 - 6 0 1 0 1 0 0 0 0 - 5 0 0 0 0 0 0 0 0 - 4 0 1 0 1 0 0 0 0 - 3 1 0 0 0 1 0 0 0 - 2 0 0 0 0 0 1 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x20110a000a1100 - Bitboard: 0b100000000100010000101000000000000010100001000100000000 - - bishopAttackers: 0x0 - rookMask : 0x40404fb040400 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x41221400142200 - - 8 0 0 0 0 0 0 0 0 - 7 0 1 0 0 0 1 0 0 - 6 0 0 1 0 1 0 0 0 - 5 0 0 0 0 0 0 0 0 - 4 0 0 1 0 1 0 0 0 - 3 0 1 0 0 0 1 0 0 - 2 1 0 0 0 0 0 1 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x41221400142200 - Bitboard: 0b1000001001000100001010000000000000101000010001000000000 - - bishopAttackers: 0x0 - rookMask : 0x80808f7080800 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x82442800284400 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 1 0 0 0 1 0 - 6 0 0 0 1 0 1 0 0 - 5 0 0 0 0 0 0 0 0 - 4 0 0 0 1 0 1 0 0 - 3 0 0 1 0 0 0 1 0 - 2 0 1 0 0 0 0 0 1 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x82442800284400 - Bitboard: 0b10000010010001000010100000000000001010000100010000000000 - - bishopAttackers: 0x0 - rookMask : 0x101010ef101000 - rookAttackers : 0x0 - combined attackers: 0x0 - . === BISHOP DEBUG for square 29 === - occ=0xffff00000000ffff - mask=0x4085000500800 - relevant=0x4000000000800 - magic=0x404002011000 - shift=57 - raw_idx=33 - idx=33 - result=0x2040814204180800 - direct=0x40814204180800 - match: false -=============================== - - bishopMask : 0x2040814204180800 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 1 0 0 0 0 - 6 0 0 0 1 1 0 0 0 - 5 0 0 1 0 0 0 0 0 - 4 0 1 0 0 0 0 1 0 - 3 1 0 0 0 0 0 0 1 - 2 0 0 0 0 0 0 1 0 - 1 0 0 0 0 0 1 0 0 - - a b c d e f g h - - Bitboard: 0x2040814204180800 - Bitboard: 0b10000001000000100000010100001000000100000110000000100000000000 - - bishopAttackers: 0x2000000000000000 - rookMask : 0x202020df202000 - rookAttackers : 0x0 - combined attackers: 0x2000000000000000 - X bishopMask : 0x4081028408201000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 1 0 0 0 - 6 0 0 0 0 0 1 0 0 - 5 0 0 0 1 0 0 0 0 - 4 0 0 1 0 0 0 0 1 - 3 0 1 0 0 0 0 0 0 - 2 1 0 0 0 0 0 0 1 - 1 0 0 0 0 0 0 1 0 - - a b c d e f g h - - Bitboard: 0x4081028408201000 - Bitboard: 0b100000010000001000000101000010000001000001000000001000000000000 - - bishopAttackers: 0x0 - rookMask : 0x404040bf404000 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x8102040800402000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 0 1 0 0 - 6 0 0 0 0 0 0 1 0 - 5 0 0 0 0 0 0 0 0 - 4 0 0 0 1 0 0 0 0 - 3 0 0 1 0 0 0 0 0 - 2 0 1 0 0 0 0 0 0 - 1 1 0 0 0 0 0 0 1 - - a b c d e f g h - - Bitboard: 0x8102040800402000 - Bitboard: 0b1000000100000010000001000000100000000000010000000010000000000000 - - bishopAttackers: 0x0 - rookMask : 0x8080807f808000 - rookAttackers : 0x0 - combined attackers: 0x0 - . - 4 bishopMask : 0x4020002040800 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 1 0 0 0 0 - 6 0 0 1 0 0 0 0 0 - 5 0 1 0 0 0 0 0 0 - 4 0 0 0 0 0 0 0 0 - 3 0 1 0 0 0 0 0 0 - 2 0 0 1 0 0 0 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x4020002040800 - Bitboard: 0b100000000100000000000000010000001000000100000000000 - - bishopAttackers: 0x0 - rookMask : 0x101fe01010100 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x8050005081000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 1 0 0 0 - 6 0 0 0 1 0 0 0 0 - 5 1 0 1 0 0 0 0 0 - 4 0 0 0 0 0 0 0 0 - 3 1 0 1 0 0 0 0 0 - 2 0 0 0 1 0 0 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x8050005081000 - Bitboard: 0b1000000001010000000000000101000010000001000000000000 - - bishopAttackers: 0x0 - rookMask : 0x202fd02020200 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x110a000a112000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 0 1 0 0 - 6 1 0 0 0 1 0 0 0 - 5 0 1 0 1 0 0 0 0 - 4 0 0 0 0 0 0 0 0 - 3 0 1 0 1 0 0 0 0 - 2 1 0 0 0 1 0 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x110a000a112000 - Bitboard: 0b10001000010100000000000001010000100010010000000000000 - - bishopAttackers: 0x0 - rookMask : 0x404fb04040400 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x22140014224100 - - 8 0 0 0 0 0 0 0 0 - 7 1 0 0 0 0 0 1 0 - 6 0 1 0 0 0 1 0 0 - 5 0 0 1 0 1 0 0 0 - 4 0 0 0 0 0 0 0 0 - 3 0 0 1 0 1 0 0 0 - 2 0 1 0 0 0 1 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x22140014224100 - Bitboard: 0b100010000101000000000000010100001000100100000100000000 - - bishopAttackers: 0x0 - rookMask : 0x808f708080800 - rookAttackers : 0x0 - combined attackers: 0x0 - . === BISHOP DEBUG for square 36 === - occ=0xffff00000000ffff - mask=0x44280028440200 - relevant=0x44000000000200 - magic=0x404040040100 - shift=55 - raw_idx=137 - idx=137 - result=0x40a1020c0c0200 - direct=0x40a1020c0c0200 - match: true -=============================== - - bishopMask : 0x40a1020c0c0200 - - 8 0 0 0 0 0 0 0 0 - 7 0 1 0 0 0 0 0 0 - 6 0 0 1 1 0 0 0 0 - 5 0 0 1 1 0 0 0 0 - 4 0 1 0 0 0 0 0 0 - 3 1 0 0 0 0 1 0 1 - 2 0 0 0 0 0 0 1 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x40a1020c0c0200 - Bitboard: 0b1000000101000010000001000001100000011000000001000000000 - - bishopAttackers: 0x0 - rookMask : 0x1010ef10101000 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x4081420418080400 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 1 0 0 0 0 0 - 6 0 0 0 1 0 0 0 0 - 5 0 0 0 1 1 0 0 0 - 4 0 0 1 0 0 0 0 0 - 3 0 1 0 0 0 0 1 0 - 2 1 0 0 0 0 0 0 1 - 1 0 0 0 0 0 0 1 0 - - a b c d e f g h - - Bitboard: 0x4081420418080400 - Bitboard: 0b100000010000001010000100000010000011000000010000000010000000000 - - bishopAttackers: 0x0 - rookMask : 0x2020df20202000 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x8102840820100800 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 1 0 0 0 0 - 6 0 0 0 0 1 0 0 0 - 5 0 0 0 0 0 1 0 0 - 4 0 0 0 1 0 0 0 0 - 3 0 0 1 0 0 0 0 1 - 2 0 1 0 0 0 0 0 0 - 1 1 0 0 0 0 0 0 1 - - a b c d e f g h - - Bitboard: 0x8102840820100800 - Bitboard: 0b1000000100000010100001000000100000100000000100000000100000000000 - - bishopAttackers: 0x0 - rookMask : 0x4040bf40404000 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x20400040201000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 1 0 0 0 - 6 0 0 0 0 0 1 0 0 - 5 0 0 0 0 0 0 1 0 - 4 0 0 0 0 0 0 0 0 - 3 0 0 0 0 0 0 1 0 - 2 0 0 0 0 0 1 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x20400040201000 - Bitboard: 0b100000010000000000000001000000001000000001000000000000 - - bishopAttackers: 0x0 - rookMask : 0x80807f80808000 - rookAttackers : 0x0 - combined attackers: 0x0 - . - 3 bishopMask : 0x2000204081000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 1 0 0 0 - 6 0 0 0 1 0 0 0 0 - 5 0 0 1 0 0 0 0 0 - 4 0 1 0 0 0 0 0 0 - 3 0 0 0 0 0 0 0 0 - 2 0 1 0 0 0 0 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x2000204081000 - Bitboard: 0b10000000000000001000000100000010000001000000000000 - - bishopAttackers: 0x0 - rookMask : 0x1fe0101010100 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x5000508102000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 0 1 0 0 - 6 0 0 0 0 1 0 0 0 - 5 0 0 0 1 0 0 0 0 - 4 1 0 1 0 0 0 0 0 - 3 0 0 0 0 0 0 0 0 - 2 1 0 1 0 0 0 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x5000508102000 - Bitboard: 0b101000000000000010100001000000100000010000000000000 - - bishopAttackers: 0x0 - rookMask : 0x2fd0202020200 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0xa000a11204000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 0 0 1 0 - 6 0 0 0 0 0 1 0 0 - 5 1 0 0 0 1 0 0 0 - 4 0 1 0 1 0 0 0 0 - 3 0 0 0 0 0 0 0 0 - 2 0 1 0 1 0 0 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0xa000a11204000 - Bitboard: 0b1010000000000000101000010001001000000100000000000000 - - bishopAttackers: 0x0 - rookMask : 0x4fb0404040400 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x2050810606090000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 0 0 0 0 - 6 1 0 0 1 0 0 0 0 - 5 0 1 1 0 0 0 0 0 - 4 0 1 1 0 0 0 0 0 - 3 1 0 0 0 0 0 0 1 - 2 0 0 0 0 1 0 1 0 - 1 0 0 0 0 0 1 0 0 - - a b c d e f g h - - Bitboard: 0x2050810606090000 - Bitboard: 0b10000001010000100000010000011000000110000010010000000000000000 - - bishopAttackers: 0x2000000000000000 - rookMask : 0x8f70808080800 - rookAttackers : 0x0 - combined attackers: 0x2000000000000000 - X bishopMask : 0x40a1020c0c020100 - - 8 0 0 0 0 0 0 0 0 - 7 1 0 0 0 0 0 0 0 - 6 0 1 0 0 0 0 0 0 - 5 0 0 1 1 0 0 0 0 - 4 0 0 1 1 0 0 0 0 - 3 0 1 0 0 0 0 0 0 - 2 1 0 0 0 0 1 0 1 - 1 0 0 0 0 0 0 1 0 - - a b c d e f g h - - Bitboard: 0x40a1020c0c020100 - Bitboard: 0b100000010100001000000100000110000001100000000100000000100000000 - - bishopAttackers: 0x0 - rookMask : 0x10ef1010101000 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x8142041808040200 - - 8 0 0 0 0 0 0 0 0 - 7 0 1 0 0 0 0 0 0 - 6 0 0 1 0 0 0 0 0 - 5 0 0 0 1 0 0 0 0 - 4 0 0 0 1 1 0 0 0 - 3 0 0 1 0 0 0 0 0 - 2 0 1 0 0 0 0 1 0 - 1 1 0 0 0 0 0 0 1 - - a b c d e f g h - - Bitboard: 0x8142041808040200 - Bitboard: 0b1000000101000010000001000001100000001000000001000000001000000000 - - bishopAttackers: 0x0 - rookMask : 0x20df2020202000 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0xa000a010080400 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 1 0 0 0 0 0 - 6 0 0 0 1 0 0 0 0 - 5 0 0 0 0 1 0 0 0 - 4 0 0 0 0 0 1 0 1 - 3 0 0 0 0 0 0 0 0 - 2 0 0 0 0 0 1 0 1 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0xa000a010080400 - Bitboard: 0b10100000000000001010000000010000000010000000010000000000 - - bishopAttackers: 0x0 - rookMask : 0x40bf4040404000 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x40004020100800 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 1 0 0 0 0 - 6 0 0 0 0 1 0 0 0 - 5 0 0 0 0 0 1 0 0 - 4 0 0 0 0 0 0 1 0 - 3 0 0 0 0 0 0 0 0 - 2 0 0 0 0 0 0 1 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x40004020100800 - Bitboard: 0b1000000000000000100000000100000000100000000100000000000 - - bishopAttackers: 0x0 - rookMask : 0x807f8080808000 - rookAttackers : 0x0 - combined attackers: 0x0 - . - 2 bishopMask : 0x200020408102000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 0 1 0 0 - 6 0 0 0 0 1 0 0 0 - 5 0 0 0 1 0 0 0 0 - 4 0 0 1 0 0 0 0 0 - 3 0 1 0 0 0 0 0 0 - 2 0 0 0 0 0 0 0 0 - 1 0 1 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x200020408102000 - Bitboard: 0b1000000000000000100000010000001000000100000010000000000000 - - bishopAttackers: 0x0 - rookMask : 0x102010101010100 - rookAttackers : 0x100000000000000 - combined attackers: 0x100000000000000 - X bishopMask : 0x500050810204000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 0 0 1 0 - 6 0 0 0 0 0 1 0 0 - 5 0 0 0 0 1 0 0 0 - 4 0 0 0 1 0 0 0 0 - 3 1 0 1 0 0 0 0 0 - 2 0 0 0 0 0 0 0 0 - 1 1 0 1 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x500050810204000 - Bitboard: 0b10100000000000001010000100000010000001000000100000000000000 - - bishopAttackers: 0x400000000000000 - rookMask : 0x205020202020200 - rookAttackers : 0x0 - combined attackers: 0x400000000000000 - X bishopMask : 0x2840830304080000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 0 0 0 0 - 6 0 0 0 1 0 0 0 0 - 5 0 0 1 0 0 0 0 0 - 4 1 1 0 0 0 0 0 0 - 3 1 1 0 0 0 0 0 1 - 2 0 0 0 0 0 0 1 0 - 1 0 0 0 1 0 1 0 0 - - a b c d e f g h - - Bitboard: 0x2840830304080000 - Bitboard: 0b10100001000000100000110000001100000100000010000000000000000000 - - bishopAttackers: 0x2800000000000000 - rookMask : 0x40a040404040400 - rookAttackers : 0x0 - combined attackers: 0x2800000000000000 - X bishopMask : 0x5081060609000000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 0 0 0 0 - 6 0 0 0 0 0 0 0 0 - 5 1 0 0 1 0 0 0 0 - 4 0 1 1 0 0 0 0 0 - 3 0 1 1 0 0 0 0 0 - 2 1 0 0 0 0 0 0 1 - 1 0 0 0 0 1 0 1 0 - - a b c d e f g h - - Bitboard: 0x5081060609000000 - Bitboard: 0b101000010000001000001100000011000001001000000000000000000000000 - - bishopAttackers: 0x0 - rookMask : 0x814080808080800 - rookAttackers : 0x800000000000000 - combined attackers: 0x800000000000000 - X bishopMask : 0xa1020c0c02010000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 0 0 0 0 - 6 1 0 0 0 0 0 0 0 - 5 0 1 0 0 0 0 0 0 - 4 0 0 1 1 0 0 0 0 - 3 0 0 1 1 0 0 0 0 - 2 0 1 0 0 0 0 0 0 - 1 1 0 0 0 0 1 0 1 - - a b c d e f g h - - Bitboard: 0xa1020c0c02010000 - Bitboard: 0b1010000100000010000011000000110000000010000000010000000000000000 - - bishopAttackers: 0x2000000000000000 - rookMask : 0x1028101010101000 - rookAttackers : 0x0 - combined attackers: 0x2000000000000000 - X bishopMask : 0x5000508804020100 - - 8 0 0 0 0 0 0 0 0 - 7 1 0 0 0 0 0 0 0 - 6 0 1 0 0 0 0 0 0 - 5 0 0 1 0 0 0 0 0 - 4 0 0 0 1 0 0 0 1 - 3 0 0 0 0 1 0 1 0 - 2 0 0 0 0 0 0 0 0 - 1 0 0 0 0 1 0 1 0 - - a b c d e f g h - - Bitboard: 0x5000508804020100 - Bitboard: 0b101000000000000010100001000100000000100000000100000000100000000 - - bishopAttackers: 0x0 - rookMask : 0x2050202020202000 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0xa000a01008040200 - - 8 0 0 0 0 0 0 0 0 - 7 0 1 0 0 0 0 0 0 - 6 0 0 1 0 0 0 0 0 - 5 0 0 0 1 0 0 0 0 - 4 0 0 0 0 1 0 0 0 - 3 0 0 0 0 0 1 0 1 - 2 0 0 0 0 0 0 0 0 - 1 0 0 0 0 0 1 0 1 - - a b c d e f g h - - Bitboard: 0xa000a01008040200 - Bitboard: 0b1010000000000000101000000001000000001000000001000000001000000000 - - bishopAttackers: 0x2000000000000000 - rookMask : 0x40a0404040404000 - rookAttackers : 0x0 - combined attackers: 0x2000000000000000 - X bishopMask : 0x4000402010080400 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 1 0 0 0 0 0 - 6 0 0 0 1 0 0 0 0 - 5 0 0 0 0 1 0 0 0 - 4 0 0 0 0 0 1 0 0 - 3 0 0 0 0 0 0 1 0 - 2 0 0 0 0 0 0 0 0 - 1 0 0 0 0 0 0 1 0 - - a b c d e f g h - - Bitboard: 0x4000402010080400 - Bitboard: 0b100000000000000010000000010000000010000000010000000010000000000 - - bishopAttackers: 0x0 - rookMask : 0x8040808080808000 - rookAttackers : 0x8000000000000000 - combined attackers: 0x8000000000000000 - X - 1 bishopMask : 0x2000000000000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 0 0 0 0 - 6 0 0 0 0 0 0 0 0 - 5 0 0 0 0 0 0 0 0 - 4 0 0 0 0 0 0 0 0 - 3 0 0 0 0 0 0 0 0 - 2 0 1 0 0 0 0 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x2000000000000 - Bitboard: 0b10000000000000000000000000000000000000000000000000 - - bishopAttackers: 0x0 - rookMask : 0x201000000000000 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x2041810204080000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 0 0 0 0 - 6 0 0 0 1 0 0 0 0 - 5 0 0 1 0 0 0 0 0 - 4 0 1 0 0 0 0 0 0 - 3 1 0 0 0 0 0 0 1 - 2 1 0 0 0 0 0 1 0 - 1 0 0 0 0 0 1 0 0 - - a b c d e f g h - - Bitboard: 0x2041810204080000 - Bitboard: 0b10000001000001100000010000001000000100000010000000000000000000 - - bishopAttackers: 0x2000000000000000 - rookMask : 0x502000000000000 - rookAttackers : 0x100000000000000 - combined attackers: 0x2100000000000000 - X bishopMask : 0x4083020408000000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 0 0 0 0 - 6 0 0 0 0 0 0 0 0 - 5 0 0 0 1 0 0 0 0 - 4 0 0 1 0 0 0 0 0 - 3 0 1 0 0 0 0 0 0 - 2 1 1 0 0 0 0 0 1 - 1 0 0 0 0 0 0 1 0 - - a b c d e f g h - - Bitboard: 0x4083020408000000 - Bitboard: 0b100000010000011000000100000010000001000000000000000000000000000 - - bishopAttackers: 0x0 - rookMask : 0xa04000000000000 - rookAttackers : 0x800000000000000 - combined attackers: 0x800000000000000 - X bishopMask : 0x8106040800000000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 0 0 0 0 - 6 0 0 0 0 0 0 0 0 - 5 0 0 0 0 0 0 0 0 - 4 0 0 0 1 0 0 0 0 - 3 0 0 1 0 0 0 0 0 - 2 0 1 1 0 0 0 0 0 - 1 1 0 0 0 0 0 0 1 - - a b c d e f g h - - Bitboard: 0x8106040800000000 - Bitboard: 0b1000000100000110000001000000100000000000000000000000000000000000 - - bishopAttackers: 0x0 - rookMask : 0x1408000000000000 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0x28000000000000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 0 0 0 0 - 6 0 0 0 0 0 0 0 0 - 5 0 0 0 0 0 0 0 0 - 4 0 0 0 0 0 0 0 0 - 3 0 0 0 0 0 0 0 0 - 2 0 0 0 1 0 1 0 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x28000000000000 - Bitboard: 0b101000000000000000000000000000000000000000000000000000 - - bishopAttackers: 0x0 - rookMask : 0x2810000000000000 - rookAttackers : 0x800000000000000 - combined attackers: 0x800000000000000 - X bishopMask : 0x50000000000000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 0 0 0 0 - 6 0 0 0 0 0 0 0 0 - 5 0 0 0 0 0 0 0 0 - 4 0 0 0 0 0 0 0 0 - 3 0 0 0 0 0 0 0 0 - 2 0 0 0 0 1 0 1 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x50000000000000 - Bitboard: 0b1010000000000000000000000000000000000000000000000000000 - - bishopAttackers: 0x0 - rookMask : 0x5020000000000000 - rookAttackers : 0x0 - combined attackers: 0x0 - . bishopMask : 0xa0000000000000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 0 0 0 0 - 6 0 0 0 0 0 0 0 0 - 5 0 0 0 0 0 0 0 0 - 4 0 0 0 0 0 0 0 0 - 3 0 0 0 0 0 0 0 0 - 2 0 0 0 0 0 1 0 1 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0xa0000000000000 - Bitboard: 0b10100000000000000000000000000000000000000000000000000000 - - bishopAttackers: 0x0 - rookMask : 0xa040000000000000 - rookAttackers : 0x8000000000000000 - combined attackers: 0x8000000000000000 - X bishopMask : 0x40000000000000 - - 8 0 0 0 0 0 0 0 0 - 7 0 0 0 0 0 0 0 0 - 6 0 0 0 0 0 0 0 0 - 5 0 0 0 0 0 0 0 0 - 4 0 0 0 0 0 0 0 0 - 3 0 0 0 0 0 0 0 0 - 2 0 0 0 0 0 0 1 0 - 1 0 0 0 0 0 0 0 0 - - a b c d e f g h - - Bitboard: 0x40000000000000 - Bitboard: 0b1000000000000000000000000000000000000000000000000000000 - - bishopAttackers: 0x0 - rookMask : 0x4080000000000000 - rookAttackers : 0x0 - combined attackers: 0x0 - . - - a b c d e f g h - -=== end attacked squares === From 3c5a01f4f69073eea7376721aa7bc46ed9ab9db5 Mon Sep 17 00:00:00 2001 From: Jakob Date: Mon, 16 Jun 2025 15:12:44 +0200 Subject: [PATCH 7/8] Fix: rm board --- src/test.zig | 1 - src/types.zig | 1 - 2 files changed, 2 deletions(-) diff --git a/src/test.zig b/src/test.zig index ff1db05..7d4aa33 100644 --- a/src/test.zig +++ b/src/test.zig @@ -16,7 +16,6 @@ test "test print bitboard" { test "test print bitboard unicode" { var b: types.Board = .{ .pieces = [_]types.Bitboard{0} ** types.Board.PieceCount, - .board = undefined, .side = types.Color.Black, .enpassant = types.square.e3, .castle = @intFromEnum(types.Castle.WK) | @intFromEnum(types.Castle.WQ) | @intFromEnum(types.Castle.BK) | @intFromEnum(types.Castle.BQ), diff --git a/src/types.zig b/src/types.zig index 38a11b2..9bb3866 100644 --- a/src/types.zig +++ b/src/types.zig @@ -138,7 +138,6 @@ pub const Board = struct { pub const PieceCount = @intFromEnum(Piece.NO_PIECE) + 1; pieces: [PieceCount]Bitboard, - board: [64]Piece, side: Color, enpassant: square, castle: u8, // bitmask of Castle.* From a2f8d3cd28d9c7d65714002ee93dad229599003f Mon Sep 17 00:00:00 2001 From: Jakob Date: Mon, 16 Jun 2025 21:32:05 +0200 Subject: [PATCH 8/8] Chore: add tests --- README.md | 2 +- scripts/GetAttacks.py | 64 +++++++++++++++++++++++++++++++++++++++++++ src/test.zig | 52 +++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 scripts/GetAttacks.py diff --git a/README.md b/README.md index e2ee939..340c3ea 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This chess engine is still in development. When I have it in working order and w ## Strength -**TODO :** +**TODO:** - Update the strength table: diff --git a/scripts/GetAttacks.py b/scripts/GetAttacks.py new file mode 100644 index 0000000..86f4112 --- /dev/null +++ b/scripts/GetAttacks.py @@ -0,0 +1,64 @@ +import chess + +# A diverse set of FEN positions for testing +fen_positions = [ + "8/8/8/8/8/8/8/8 w - - ", + "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", + "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1", + "rnbqkb1r/pp1p1pPp/8/2p1pP2/1P1P4/3P3P/P1P1P3/RNBQKBNR w KQkq e6 0 1", + "r2q1rk1/ppp2ppp/2n1bn2/2b1p3/3pP3/3P1NPP/PPP1NPB1/R1BQ1RK1 b - - 0 9 ", + "r3k2r/8/8/8/3pPp2/8/8/R3K1RR b KQkq e3 0 1", + "r3k2r/Pppp1ppp/1b3nbN/nP6/BBP1P3/q4N2/Pp1P2PP/R2Q1RK1 w kq - 0 1", + "8/7p/p5pb/4k3/P1pPn3/8/P5PP/1rB2RK1 b - d3 0 28", + "8/3K4/2p5/p2b2r1/5k2/8/8/1q6 b - - 1 67", + "rnbqkb1r/ppppp1pp/7n/4Pp2/8/8/PPPP1PPP/RNBQKBNR w KQkq f6 0 3", + "n1n5/PPPk4/8/8/8/8/4Kppp/5N1N b - - 0 1", + "r3k2r/p6p/8/B7/1pp1p3/3b4/P6P/R3K2R w KQkq - 0 1", + "8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 1", + "r6r/1b2k1bq/8/8/7B/8/8/R3K2R b KQ - 3 2", + "8/8/8/2k5/2pP4/8/B7/4K3 b - d3 0 3", + "r1bqkbnr/pppppppp/n7/8/8/P7/1PPPPPPP/RNBQKBNR w KQkq - 2 2", + "r3k2r/p1pp1pb1/bn2Qnp1/2qPN3/1p2P3/2N5/PPPBBPPP/R3K2R b KQkq - 3 2", + "2kr3r/p1ppqpb1/bn2Qnp1/3PN3/1p2P3/2N5/PPPBBPPP/R3K2R b KQ - 3 2", + "rnb2k1r/pp1Pbppp/2p5/q7/2B5/8/PPPQNnPP/RNB1K2R w KQ - 3 9", +] + + +def to_zig_hex(bb: int) -> str: + """Converts a python-chess bitboard (big-endian) to a little-endian hex string for Zig.""" + raw_be = bb.to_bytes(8, byteorder="big") + raw_le = raw_be[::-1] + zig_int = int.from_bytes(raw_le, byteorder="big") + return f"0x{zig_int:016x}" + + +white_attacks_bb_arr = [] +black_attacks_bb_arr = [] + +for fen in fen_positions: + board = chess.Board(fen) + print(f"FEN: {fen}") + print(board) + + white_attacks_bb = 0 + black_attacks_bb = 0 + + # Iterate over all 64 squares to build the attack maps + for sq in chess.SQUARES: + # Check if the square is attacked by white + if board.is_attacked_by(chess.WHITE, sq): + white_attacks_bb |= 1 << sq + + # Check if the square is attacked by black + if board.is_attacked_by(chess.BLACK, sq): + black_attacks_bb |= 1 << sq + + white_attacks_bb_arr.append(white_attacks_bb) + black_attacks_bb_arr.append(black_attacks_bb) + + print(f"White Attacks: {to_zig_hex(white_attacks_bb)}") + print(f"Black Attacks: {to_zig_hex(black_attacks_bb)}") + print("-" * 40) + +print(f"White Attacks list: {white_attacks_bb_arr} \n") +print(f"Black Attacks list: {black_attacks_bb_arr} \n") diff --git a/src/test.zig b/src/test.zig index 7d4aa33..45ed7bc 100644 --- a/src/test.zig +++ b/src/test.zig @@ -375,3 +375,55 @@ test "test fen parsing" { ); } } + +test "is square attacked" { + attacks.init_attacks(); + + const AttackTestVector = struct { + fen: []const u8, + white_attacks: u64, + black_attacks: u64, + }; + + const test_vectors = [_]AttackTestVector{ + .{ .fen = "8/8/8/8/8/8/8/8 w - - ", .white_attacks = 0x0000000000000000, .black_attacks = 0x0000000000000000 }, + .{ .fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", .white_attacks = 9151313343305220096, .black_attacks = 16777086 }, + }; + + for (test_vectors) |vector| { + var board = types.Board.new(); + try bitboard.fan_pars(vector.fen, &board); + + var generated_white_attacks: u64 = 0; + var generated_black_attacks: u64 = 0; + + for (0..64) |sq_idx| { + const sq: u6 = @intCast(sq_idx); + if (bitboard.is_square_attacked(&board, sq, .White)) { + generated_white_attacks |= (@as(u64, 1) << sq); + } + if (bitboard.is_square_attacked(&board, sq, .Black)) { + generated_black_attacks |= (@as(u64, 1) << sq); + } + } + + // Use if-statements to provide more context on failure + if (vector.white_attacks != generated_white_attacks) { + std.debug.print("\n\nWhite attack mismatch for FEN: {s}\n", .{vector.fen}); + std.debug.print("Expected: 0x{x}\n", .{vector.white_attacks}); + bitboard.print_board(vector.white_attacks); + std.debug.print("Got: 0x{x}\n", .{generated_white_attacks}); + bitboard.print_board(generated_white_attacks); + } + try std.testing.expectEqual(vector.white_attacks, generated_white_attacks); + + if (vector.black_attacks != generated_black_attacks) { + std.debug.print("\n\nBlack attack mismatch for FEN: {s}\n", .{vector.fen}); + std.debug.print("Expected: 0x{x}\n", .{vector.black_attacks}); + bitboard.print_board(vector.black_attacks); + std.debug.print("Got: 0x{x}\n", .{generated_black_attacks}); + bitboard.print_board(generated_black_attacks); + } + try std.testing.expectEqual(vector.black_attacks, generated_black_attacks); + } +}