From c7c9d1f015051461714d69afedef00438d579414 Mon Sep 17 00:00:00 2001 From: Oriol Arcas Date: Thu, 28 Dec 2023 13:09:53 +0100 Subject: [PATCH] Pawn, knight and king attack tables (#5) * Add pawn, knight and king attack tables * Bump version to 0.9 --- Cargo.lock | 2 +- package-lock.json | 4 +- package.json | 2 +- between.py => scripts/in_between.py | 4 +- scripts/king.py | 55 ++++ scripts/knights.py | 55 ++++ scripts/pawns.py | 112 +++++++ src-tauri/Cargo.toml | 4 +- src-tauri/src/eval/bitboards.rs | 44 ++- src-tauri/src/eval/bitboards/attack.rs | 426 +++++++++++++++++++++++++ src-tauri/src/eval/check.rs | 34 +- src-tauri/tauri.conf.json | 2 +- 12 files changed, 687 insertions(+), 57 deletions(-) rename between.py => scripts/in_between.py (100%) create mode 100644 scripts/king.py create mode 100644 scripts/knights.py create mode 100644 scripts/pawns.py create mode 100644 src-tauri/src/eval/bitboards/attack.rs diff --git a/Cargo.lock b/Cargo.lock index c7f9f89..15279ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -484,7 +484,7 @@ dependencies = [ [[package]] name = "chusst" -version = "0.8.0" +version = "0.9.0" dependencies = [ "atty", "bencher", diff --git a/package-lock.json b/package-lock.json index 891670e..e672860 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "chusst", - "version": "0.8.0", + "version": "0.9.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "chusst", - "version": "0.8.0", + "version": "0.9.0", "dependencies": { "@tauri-apps/api": "^1.4.0", "@testing-library/jest-dom": "^5.17.0", diff --git a/package.json b/package.json index 38df91f..afdd3cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chusst", - "version": "0.8.0", + "version": "0.9.0", "private": true, "dependencies": { "@tauri-apps/api": "^1.4.0", diff --git a/between.py b/scripts/in_between.py similarity index 100% rename from between.py rename to scripts/in_between.py index 6ad1caf..297d432 100644 --- a/between.py +++ b/scripts/in_between.py @@ -1,10 +1,10 @@ -print("const IN_BETWEEN_TABLE: [[u64; 64]; 64] = [") - def index_to_rank_and_file(index): rank = index // 8 file = index % 8 return rank, file +print("const IN_BETWEEN_TABLE: [[u64; 64]; 64] = [") + for source_index in range(64): print(" [") for target_index in range(64): diff --git a/scripts/king.py b/scripts/king.py new file mode 100644 index 0000000..c7e06d2 --- /dev/null +++ b/scripts/king.py @@ -0,0 +1,55 @@ +def index_to_rank_and_file(index): + rank = index // 8 + file = index % 8 + return rank, file + +def rank_and_file_to_index(rank, file): + return rank * 8 + file + +def bitboard_from_bit(index): + return 1 << index + +def is_valid_position(rank, file): + return rank >= 0 and rank < 8 and file >= 0 and file < 8 + +def format_bitboard(bitboard): + print(" abcdefgh") + for rank_number, rank_byte in reversed(list(enumerate(bitboard.to_bytes(8, 'little')))): + print(f"{rank_number + 1} {rank_byte:08b}") + +print("pub const KING_ATTACK_TABLE: [u64; 64] = [") + +for source_index in range(64): + source_rank, source_file = index_to_rank_and_file(source_index) + + moves = [ + (-1, -1), + (-1, 0), + (-1, 1), + (0, -1), + (0, 1), + (1, -1), + (1, 0), + (1, 1), + ] + + bitboard = 0 + + for move_ranks, move_files in moves: + target_rank = source_rank + move_ranks + target_file = source_file + move_files + + if not is_valid_position(target_rank, target_file): + continue + + target_index = rank_and_file_to_index(target_rank, target_file) + bitboard |= bitboard_from_bit(target_index) + + if bitboard == 0: + print(" 0,") + else: + print(f" 0x{bitboard:016x},") + # print(f"{format_bitboard(bitboard | bitboard_from_bit(source_index))}") + + +print("];") diff --git a/scripts/knights.py b/scripts/knights.py new file mode 100644 index 0000000..3c282db --- /dev/null +++ b/scripts/knights.py @@ -0,0 +1,55 @@ +def index_to_rank_and_file(index): + rank = index // 8 + file = index % 8 + return rank, file + +def rank_and_file_to_index(rank, file): + return rank * 8 + file + +def bitboard_from_bit(index): + return 1 << index + +def is_valid_position(rank, file): + return rank >= 0 and rank < 8 and file >= 0 and file < 8 + +def format_bitboard(bitboard): + print(" abcdefgh") + for rank_number, rank_byte in reversed(list(enumerate(bitboard.to_bytes(8, 'little')))): + print(f"{rank_number + 1} {rank_byte:08b}") + +print("pub const KNIGHT_ATTACK_TABLE: [u64; 64] = [") + +for source_index in range(64): + source_rank, source_file = index_to_rank_and_file(source_index) + + moves = [ + (-1, -2), + (-1, 2), + (-2, -1), + (-2, 1), + (2, -1), + (2, 1), + (1, -2), + (1, 2), + ] + + bitboard = 0 + + for move_ranks, move_files in moves: + target_rank = source_rank + move_ranks + target_file = source_file + move_files + + if not is_valid_position(target_rank, target_file): + continue + + target_index = rank_and_file_to_index(target_rank, target_file) + bitboard |= bitboard_from_bit(target_index) + + if bitboard == 0: + print(" 0,") + else: + print(f" 0x{bitboard:016x},") + # print(f"{format_bitboard(bitboard | bitboard_from_bit(source_index))}") + + +print("];") diff --git a/scripts/pawns.py b/scripts/pawns.py new file mode 100644 index 0000000..b5cc08b --- /dev/null +++ b/scripts/pawns.py @@ -0,0 +1,112 @@ +def index_to_rank_and_file(index): + rank = index // 8 + file = index % 8 + return rank, file + +def rank_and_file_to_index(rank, file): + return rank * 8 + file + +def bitboard_from_bit(index): + return 1 << index + +# A pawn can never be below its starting rank (1 for white or 8 for black) +# Also when it arrives to the promotion rank, it promotes and cannot be a pawn anymore +# So no possible moves for ranks 1 and 8 + +print("pub const WHITE_PAWN_ATTACK_TABLE: [u64; 64] = [") + +for source_index in range(64): + source_rank, source_file = index_to_rank_and_file(source_index) + + # Possible captures, not including en passant + + if source_rank == 0 or source_rank == 7: + print(" 0,") + continue + + bitboard = 0 + if source_file > 0: + target_index = rank_and_file_to_index(source_rank + 1, source_file - 1) + bitboard |= bitboard_from_bit(target_index) + + if source_file < 7: + target_index = rank_and_file_to_index(source_rank + 1, source_file + 1) + bitboard |= bitboard_from_bit(target_index) + + print(f" 0x{bitboard:016x},") + +print("];") + +print() + +print("pub const BLACK_PAWN_ATTACK_TABLE: [u64; 64] = [") + +for source_index in range(64): + source_rank, source_file = index_to_rank_and_file(source_index) + + # Possible captures, not including en passant + + if source_rank == 0 or source_rank == 7: + print(" 0,") + continue + + bitboard = 0 + if source_file > 0: + target_index = rank_and_file_to_index(source_rank - 1, source_file - 1) + bitboard |= bitboard_from_bit(target_index) + + if source_file < 7: + target_index = rank_and_file_to_index(source_rank - 1, source_file + 1) + bitboard |= bitboard_from_bit(target_index) + + print(f" 0x{bitboard:016x},") + +print("];") + +print("pub const WHITE_ATTACKED_BY_PAWN_TABLE: [u64; 64] = [") + +for source_index in range(64): + source_rank, source_file = index_to_rank_and_file(source_index) + + # Possible captures, not including en passant + + if source_rank == 7: + print(" 0,") + continue + + bitboard = 0 + if source_file > 0: + target_index = rank_and_file_to_index(source_rank + 1, source_file - 1) + bitboard |= bitboard_from_bit(target_index) + + if source_file < 7: + target_index = rank_and_file_to_index(source_rank + 1, source_file + 1) + bitboard |= bitboard_from_bit(target_index) + + print(f" 0x{bitboard:016x},") + +print("];") + +print("pub const BLACK_ATTACKED_BY_PAWN_TABLE: [u64; 64] = [") + +for source_index in range(64): + source_rank, source_file = index_to_rank_and_file(source_index) + + # Possible captures, not including en passant + + if source_rank == 0: + print(" 0,") + continue + + bitboard = 0 + if source_file > 0: + target_index = rank_and_file_to_index(source_rank - 1, source_file - 1) + bitboard |= bitboard_from_bit(target_index) + + if source_file < 7: + target_index = rank_and_file_to_index(source_rank - 1, source_file + 1) + bitboard |= bitboard_from_bit(target_index) + + print(f" 0x{bitboard:016x},") + +print("];") \ No newline at end of file diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index abfb6a0..b72b45e 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "chusst" -version = "0.8.0" +version = "0.9.0" description = "A simple chess engine in Rust" authors = ["Oriol Arcas"] license = "" @@ -25,7 +25,7 @@ bencher = "0.1.5" [features] # default = ["compact-board"] # default = ["bitboards"] -# default = ["compact-board", "bitboards"] +default = ["compact-board", "bitboards"] # Use bitboards to evaluate valid moves bitboards = [] diff --git a/src-tauri/src/eval/bitboards.rs b/src-tauri/src/eval/bitboards.rs index d75dc72..855c871 100644 --- a/src-tauri/src/eval/bitboards.rs +++ b/src-tauri/src/eval/bitboards.rs @@ -1,3 +1,4 @@ +mod attack; mod in_between; use crate::board::{Board, ModifiableBoard, Piece, PieceType, Player, Position, Square}; @@ -88,27 +89,10 @@ impl PlayerBitboards { } } - pub fn in_between(source: &Position, target: &Position) -> Bitboard { - let source_index = position_to_bitboard_index(source); - let target_index = position_to_bitboard_index(target); - in_between::IN_BETWEEN_TABLE[source_index][target_index] - } - pub fn has_position(&self, position: &Position) -> bool { check_bitboard(self.combined(), position) } - pub fn has_piece(&self, position: &Position, piece: &PieceType) -> bool { - match piece { - PieceType::Pawn => check_bitboard(self.pawns, position), - PieceType::Knight => check_bitboard(self.knights, position), - PieceType::Bishop => check_bitboard(self.bishops, position), - PieceType::Rook => check_bitboard(self.rooks, position), - PieceType::Queen => check_bitboard(self.queens, position), - PieceType::King => check_bitboard(self.kings, position), - } - } - pub fn into_iter(bitboard: Bitboard) -> BitboardIter { BitboardIter { bitboard } } @@ -133,6 +117,32 @@ impl PlayerBitboards { PieceType::King => self.kings, } } + + // Tables + + pub fn in_between(source: &Position, target: &Position) -> Bitboard { + let source_index = position_to_bitboard_index(source); + let target_index = position_to_bitboard_index(target); + in_between::IN_BETWEEN_TABLE[source_index][target_index] + } + + pub fn pawn_can_attack(&self, target_position: &Position) -> bool { + let target_index = position_to_bitboard_index(target_position); + match self.player { + Player::White => self.pawns & attack::BLACK_ATTACKED_BY_PAWN_TABLE[target_index] != 0, + Player::Black => self.pawns & attack::WHITE_ATTACKED_BY_PAWN_TABLE[target_index] != 0, + } + } + + pub fn knight_can_attack(&self, target_position: &Position) -> bool { + let target_index = position_to_bitboard_index(target_position); + self.knights & attack::ATTACKED_BY_KNIGHT_TABLE[target_index] != 0 + } + + pub fn king_can_attack(&self, target_position: &Position) -> bool { + let target_index = position_to_bitboard_index(target_position); + self.kings & attack::ATTACKED_BY_KING_TABLE[target_index] != 0 + } } impl Index for PlayerBitboards { diff --git a/src-tauri/src/eval/bitboards/attack.rs b/src-tauri/src/eval/bitboards/attack.rs new file mode 100644 index 0000000..39dad22 --- /dev/null +++ b/src-tauri/src/eval/bitboards/attack.rs @@ -0,0 +1,426 @@ +use super::Bitboard; + +/* + * ---------------------------------------------------------------------------- + * Pawns + * ---------------------------------------------------------------------------- + */ + +#[allow(dead_code)] +pub const WHITE_PAWN_ATTACK_TABLE: [Bitboard; 64] = [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0x0000000000020000, + 0x0000000000050000, + 0x00000000000a0000, + 0x0000000000140000, + 0x0000000000280000, + 0x0000000000500000, + 0x0000000000a00000, + 0x0000000000400000, + 0x0000000002000000, + 0x0000000005000000, + 0x000000000a000000, + 0x0000000014000000, + 0x0000000028000000, + 0x0000000050000000, + 0x00000000a0000000, + 0x0000000040000000, + 0x0000000200000000, + 0x0000000500000000, + 0x0000000a00000000, + 0x0000001400000000, + 0x0000002800000000, + 0x0000005000000000, + 0x000000a000000000, + 0x0000004000000000, + 0x0000020000000000, + 0x0000050000000000, + 0x00000a0000000000, + 0x0000140000000000, + 0x0000280000000000, + 0x0000500000000000, + 0x0000a00000000000, + 0x0000400000000000, + 0x0002000000000000, + 0x0005000000000000, + 0x000a000000000000, + 0x0014000000000000, + 0x0028000000000000, + 0x0050000000000000, + 0x00a0000000000000, + 0x0040000000000000, + 0x0200000000000000, + 0x0500000000000000, + 0x0a00000000000000, + 0x1400000000000000, + 0x2800000000000000, + 0x5000000000000000, + 0xa000000000000000, + 0x4000000000000000, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +]; + +#[allow(dead_code)] +pub const BLACK_PAWN_ATTACK_TABLE: [u64; 64] = [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0x0000000000000002, + 0x0000000000000005, + 0x000000000000000a, + 0x0000000000000014, + 0x0000000000000028, + 0x0000000000000050, + 0x00000000000000a0, + 0x0000000000000040, + 0x0000000000000200, + 0x0000000000000500, + 0x0000000000000a00, + 0x0000000000001400, + 0x0000000000002800, + 0x0000000000005000, + 0x000000000000a000, + 0x0000000000004000, + 0x0000000000020000, + 0x0000000000050000, + 0x00000000000a0000, + 0x0000000000140000, + 0x0000000000280000, + 0x0000000000500000, + 0x0000000000a00000, + 0x0000000000400000, + 0x0000000002000000, + 0x0000000005000000, + 0x000000000a000000, + 0x0000000014000000, + 0x0000000028000000, + 0x0000000050000000, + 0x00000000a0000000, + 0x0000000040000000, + 0x0000000200000000, + 0x0000000500000000, + 0x0000000a00000000, + 0x0000001400000000, + 0x0000002800000000, + 0x0000005000000000, + 0x000000a000000000, + 0x0000004000000000, + 0x0000020000000000, + 0x0000050000000000, + 0x00000a0000000000, + 0x0000140000000000, + 0x0000280000000000, + 0x0000500000000000, + 0x0000a00000000000, + 0x0000400000000000, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +]; + +pub const WHITE_ATTACKED_BY_PAWN_TABLE: [u64; 64] = [ + 0x0000000000000200, + 0x0000000000000500, + 0x0000000000000a00, + 0x0000000000001400, + 0x0000000000002800, + 0x0000000000005000, + 0x000000000000a000, + 0x0000000000004000, + 0x0000000000020000, + 0x0000000000050000, + 0x00000000000a0000, + 0x0000000000140000, + 0x0000000000280000, + 0x0000000000500000, + 0x0000000000a00000, + 0x0000000000400000, + 0x0000000002000000, + 0x0000000005000000, + 0x000000000a000000, + 0x0000000014000000, + 0x0000000028000000, + 0x0000000050000000, + 0x00000000a0000000, + 0x0000000040000000, + 0x0000000200000000, + 0x0000000500000000, + 0x0000000a00000000, + 0x0000001400000000, + 0x0000002800000000, + 0x0000005000000000, + 0x000000a000000000, + 0x0000004000000000, + 0x0000020000000000, + 0x0000050000000000, + 0x00000a0000000000, + 0x0000140000000000, + 0x0000280000000000, + 0x0000500000000000, + 0x0000a00000000000, + 0x0000400000000000, + 0x0002000000000000, + 0x0005000000000000, + 0x000a000000000000, + 0x0014000000000000, + 0x0028000000000000, + 0x0050000000000000, + 0x00a0000000000000, + 0x0040000000000000, + 0x0200000000000000, + 0x0500000000000000, + 0x0a00000000000000, + 0x1400000000000000, + 0x2800000000000000, + 0x5000000000000000, + 0xa000000000000000, + 0x4000000000000000, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +]; +pub const BLACK_ATTACKED_BY_PAWN_TABLE: [u64; 64] = [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0x0000000000000002, + 0x0000000000000005, + 0x000000000000000a, + 0x0000000000000014, + 0x0000000000000028, + 0x0000000000000050, + 0x00000000000000a0, + 0x0000000000000040, + 0x0000000000000200, + 0x0000000000000500, + 0x0000000000000a00, + 0x0000000000001400, + 0x0000000000002800, + 0x0000000000005000, + 0x000000000000a000, + 0x0000000000004000, + 0x0000000000020000, + 0x0000000000050000, + 0x00000000000a0000, + 0x0000000000140000, + 0x0000000000280000, + 0x0000000000500000, + 0x0000000000a00000, + 0x0000000000400000, + 0x0000000002000000, + 0x0000000005000000, + 0x000000000a000000, + 0x0000000014000000, + 0x0000000028000000, + 0x0000000050000000, + 0x00000000a0000000, + 0x0000000040000000, + 0x0000000200000000, + 0x0000000500000000, + 0x0000000a00000000, + 0x0000001400000000, + 0x0000002800000000, + 0x0000005000000000, + 0x000000a000000000, + 0x0000004000000000, + 0x0000020000000000, + 0x0000050000000000, + 0x00000a0000000000, + 0x0000140000000000, + 0x0000280000000000, + 0x0000500000000000, + 0x0000a00000000000, + 0x0000400000000000, + 0x0002000000000000, + 0x0005000000000000, + 0x000a000000000000, + 0x0014000000000000, + 0x0028000000000000, + 0x0050000000000000, + 0x00a0000000000000, + 0x0040000000000000, +]; + +/* + * ---------------------------------------------------------------------------- + * Knights + * ---------------------------------------------------------------------------- + */ + +pub const KNIGHT_ATTACK_TABLE: [Bitboard; 64] = [ + 0x0000000000020400, + 0x0000000000050800, + 0x00000000000a1100, + 0x0000000000142200, + 0x0000000000284400, + 0x0000000000508800, + 0x0000000000a01000, + 0x0000000000402000, + 0x0000000002040004, + 0x0000000005080008, + 0x000000000a110011, + 0x0000000014220022, + 0x0000000028440044, + 0x0000000050880088, + 0x00000000a0100010, + 0x0000000040200020, + 0x0000000204000402, + 0x0000000508000805, + 0x0000000a1100110a, + 0x0000001422002214, + 0x0000002844004428, + 0x0000005088008850, + 0x000000a0100010a0, + 0x0000004020002040, + 0x0000020400040200, + 0x0000050800080500, + 0x00000a1100110a00, + 0x0000142200221400, + 0x0000284400442800, + 0x0000508800885000, + 0x0000a0100010a000, + 0x0000402000204000, + 0x0002040004020000, + 0x0005080008050000, + 0x000a1100110a0000, + 0x0014220022140000, + 0x0028440044280000, + 0x0050880088500000, + 0x00a0100010a00000, + 0x0040200020400000, + 0x0204000402000000, + 0x0508000805000000, + 0x0a1100110a000000, + 0x1422002214000000, + 0x2844004428000000, + 0x5088008850000000, + 0xa0100010a0000000, + 0x4020002040000000, + 0x0400040200000000, + 0x0800080500000000, + 0x1100110a00000000, + 0x2200221400000000, + 0x4400442800000000, + 0x8800885000000000, + 0x100010a000000000, + 0x2000204000000000, + 0x0004020000000000, + 0x0008050000000000, + 0x00110a0000000000, + 0x0022140000000000, + 0x0044280000000000, + 0x0088500000000000, + 0x0010a00000000000, + 0x0020400000000000, +]; + +pub const ATTACKED_BY_KNIGHT_TABLE: [Bitboard; 64] = KNIGHT_ATTACK_TABLE; + +/* + * ---------------------------------------------------------------------------- + * King + * ---------------------------------------------------------------------------- + */ + +pub const KING_ATTACK_TABLE: [u64; 64] = [ + 0x0000000000000302, + 0x0000000000000705, + 0x0000000000000e0a, + 0x0000000000001c14, + 0x0000000000003828, + 0x0000000000007050, + 0x000000000000e0a0, + 0x000000000000c040, + 0x0000000000030203, + 0x0000000000070507, + 0x00000000000e0a0e, + 0x00000000001c141c, + 0x0000000000382838, + 0x0000000000705070, + 0x0000000000e0a0e0, + 0x0000000000c040c0, + 0x0000000003020300, + 0x0000000007050700, + 0x000000000e0a0e00, + 0x000000001c141c00, + 0x0000000038283800, + 0x0000000070507000, + 0x00000000e0a0e000, + 0x00000000c040c000, + 0x0000000302030000, + 0x0000000705070000, + 0x0000000e0a0e0000, + 0x0000001c141c0000, + 0x0000003828380000, + 0x0000007050700000, + 0x000000e0a0e00000, + 0x000000c040c00000, + 0x0000030203000000, + 0x0000070507000000, + 0x00000e0a0e000000, + 0x00001c141c000000, + 0x0000382838000000, + 0x0000705070000000, + 0x0000e0a0e0000000, + 0x0000c040c0000000, + 0x0003020300000000, + 0x0007050700000000, + 0x000e0a0e00000000, + 0x001c141c00000000, + 0x0038283800000000, + 0x0070507000000000, + 0x00e0a0e000000000, + 0x00c040c000000000, + 0x0302030000000000, + 0x0705070000000000, + 0x0e0a0e0000000000, + 0x1c141c0000000000, + 0x3828380000000000, + 0x7050700000000000, + 0xe0a0e00000000000, + 0xc040c00000000000, + 0x0203000000000000, + 0x0507000000000000, + 0x0a0e000000000000, + 0x141c000000000000, + 0x2838000000000000, + 0x5070000000000000, + 0xa0e0000000000000, + 0x40c0000000000000, +]; + +pub const ATTACKED_BY_KING_TABLE: [Bitboard; 64] = KING_ATTACK_TABLE; diff --git a/src-tauri/src/eval/check.rs b/src-tauri/src/eval/check.rs index e7007b0..5467a1c 100644 --- a/src-tauri/src/eval/check.rs +++ b/src-tauri/src/eval/check.rs @@ -128,16 +128,9 @@ mod bitboards_search { player_bitboards: &PlayerBitboards, enemy_bitboards: &PlayerBitboards, position: &Position, - player: &Player, ) -> bool { - let enemy_player = enemy(&player); let all_pieces_bitboard = player_bitboards.combined() | enemy_bitboards.combined(); - let is_enemy_piece = |position: &Option, piece: &PieceType| match position { - Some(pos) => enemy_bitboards.has_piece(pos, piece), - None => false, - }; - let attacker_in_rank = |attacker_position: &Position| attacker_position.rank == position.rank; @@ -190,24 +183,12 @@ mod bitboards_search { }; // 1. Pawns - let pd = -Board::pawn_progress_direction(&enemy_player); - - if is_enemy_piece(&try_move(&position, &dir!(pd, -1)), &PieceType::Pawn) - || is_enemy_piece(&try_move(&position, &dir!(pd, 1)), &PieceType::Pawn) - { + if enemy_bitboards.pawn_can_attack(position) { return true; } // 2. Knights - if is_enemy_piece(&try_move(&position, &dir!(-1, -2)), &PieceType::Knight) - || is_enemy_piece(&try_move(&position, &dir!(-1, 2)), &PieceType::Knight) - || is_enemy_piece(&try_move(&position, &dir!(-2, -1)), &PieceType::Knight) - || is_enemy_piece(&try_move(&position, &dir!(-2, 1)), &PieceType::Knight) - || is_enemy_piece(&try_move(&position, &dir!(2, -1)), &PieceType::Knight) - || is_enemy_piece(&try_move(&position, &dir!(2, 1)), &PieceType::Knight) - || is_enemy_piece(&try_move(&position, &dir!(1, -2)), &PieceType::Knight) - || is_enemy_piece(&try_move(&position, &dir!(1, 2)), &PieceType::Knight) - { + if enemy_bitboards.knight_can_attack(position) { return true; } @@ -227,15 +208,7 @@ mod bitboards_search { } // 6. King - if is_enemy_piece(&try_move(&position, &dir!(-1, -1)), &PieceType::King) - || is_enemy_piece(&try_move(&position, &dir!(-1, 0)), &PieceType::King) - || is_enemy_piece(&try_move(&position, &dir!(-1, 1)), &PieceType::King) - || is_enemy_piece(&try_move(&position, &dir!(0, -1)), &PieceType::King) - || is_enemy_piece(&try_move(&position, &dir!(0, 1)), &PieceType::King) - || is_enemy_piece(&try_move(&position, &dir!(1, -1)), &PieceType::King) - || is_enemy_piece(&try_move(&position, &dir!(1, 0)), &PieceType::King) - || is_enemy_piece(&try_move(&position, &dir!(1, 1)), &PieceType::King) - { + if enemy_bitboards.king_can_attack(position) { return true; } @@ -250,7 +223,6 @@ fn position_is_unsafe(game: &SearchableGame, position: &Position, player: &Playe game.bitboards_by_player(player), game.bitboards_by_player(&enemy(player)), position, - player, ) } #[cfg(not(feature = "bitboards"))] diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 5ad1f2d..e4e8add 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -8,7 +8,7 @@ }, "package": { "productName": "chusst", - "version": "0.8.0" + "version": "0.9.0" }, "tauri": { "allowlist": {