diff --git a/src/attack.rs b/src/attack.rs index f12d1b4..0fd655b 100644 --- a/src/attack.rs +++ b/src/attack.rs @@ -213,7 +213,7 @@ pub fn set_occupancy(index: u64, relevant_bits: usize, mut attack_mask: Bitboard occupancy } -pub fn get_pawn_attacks(square: usize, color: Color) -> Bitboard { +pub fn fetch_pawn_attacks(square: usize, color: Color) -> Bitboard { unsafe { match color { Color::White => PAWN_ATTACKS[square][0], @@ -222,17 +222,17 @@ pub fn get_pawn_attacks(square: usize, color: Color) -> Bitboard { } } -pub fn get_knight_attacks(square: usize) -> Bitboard { +pub fn fetch_knight_attacks(square: usize) -> Bitboard { unsafe { KNIGHT_ATTACKS[square] } } -pub fn get_king_attacks(square: usize) -> Bitboard { +pub fn fetch_king_attacks(square: usize) -> Bitboard { unsafe { KING_ATTACKS[square] } } use crate::magic::{BISHOP_MAGIC, ROOK_MAGIC}; -pub fn get_bishop_attacks(mut occupancy: Bitboard, square: usize) -> Bitboard { +pub fn fetch_bishop_attacks(mut occupancy: Bitboard, square: usize) -> Bitboard { unsafe { occupancy &= mask_bishop_attacks(square_to_bitboard_wrapping(square)); occupancy = occupancy.wrapping_mul(BISHOP_MAGIC[square]); @@ -241,7 +241,7 @@ pub fn get_bishop_attacks(mut occupancy: Bitboard, square: usize) -> Bitboard { } } -pub fn get_rook_attacks(mut occupancy: Bitboard, square: usize) -> Bitboard { +pub fn fetch_rook_attacks(mut occupancy: Bitboard, square: usize) -> Bitboard { unsafe { occupancy &= mask_rook_attacks(square_to_bitboard_wrapping(square)); occupancy = occupancy.wrapping_mul(ROOK_MAGIC[square]); @@ -250,8 +250,8 @@ pub fn get_rook_attacks(mut occupancy: Bitboard, square: usize) -> Bitboard { } } -pub fn get_queen_attacks(occupancy: Bitboard, square: usize) -> Bitboard { - get_rook_attacks(occupancy, square) | get_bishop_attacks(occupancy, square) +pub fn fetch_queen_attacks(occupancy: Bitboard, square: usize) -> Bitboard { + fetch_rook_attacks(occupancy, square) | fetch_bishop_attacks(occupancy, square) } pub fn init_pawn_attacks() { @@ -449,7 +449,7 @@ mod tests { init_bishop_attacks(); let bishop_d3_square = 0x80000_u64.trailing_zeros() as usize; let blockers = 0x602000020; - let attacks = get_bishop_attacks(blockers, bishop_d3_square); + let attacks = fetch_bishop_attacks(blockers, bishop_d3_square); assert_eq!(attacks, 0x80402214001422); Ok(()) @@ -460,7 +460,7 @@ mod tests { init_rook_attacks(); let rook_d3_square = 0x80000_u64.trailing_zeros() as usize; let blockers = 0x800000000600800; - let attacks = get_rook_attacks(blockers, rook_d3_square); + let attacks = fetch_rook_attacks(blockers, rook_d3_square); assert_eq!(attacks, 0x808080808370800); Ok(()) @@ -473,7 +473,7 @@ mod tests { let queen_d3_square = 0x80000_u64.trailing_zeros() as usize; let blockers = 0x800000602600820; - let queen_attacks = get_queen_attacks(blockers, queen_d3_square); + let queen_attacks = fetch_queen_attacks(blockers, queen_d3_square); assert_eq!(queen_attacks, 0x888482a1c371c22); Ok(()) diff --git a/src/board.rs b/src/board.rs index 3212217..f513c65 100644 --- a/src/board.rs +++ b/src/board.rs @@ -1,8 +1,8 @@ use u64 as Bitboard; use crate::attack::{ - get_bishop_attacks, get_king_attacks, get_knight_attacks, get_pawn_attacks, get_queen_attacks, - get_rook_attacks, + fetch_bishop_attacks, fetch_king_attacks, fetch_knight_attacks, fetch_pawn_attacks, + fetch_queen_attacks, fetch_rook_attacks, }; use crate::bitboard::{have_common_bit, lsb, square_to_bitboard}; use crate::movegen::{ @@ -76,42 +76,44 @@ impl Board { self.state = state; } - pub fn get_white_occupancies(&self) -> Bitboard { + pub fn white_occupancies(&self) -> Bitboard { self.white_pieces.iter().fold(0, |acc, p| p.bitboard | acc) } - pub fn get_black_occupancies(&self) -> Bitboard { + pub fn black_occupancies(&self) -> Bitboard { self.black_pieces.iter().fold(0, |acc, p| p.bitboard | acc) } - pub fn get_all_occupancies(&self) -> Bitboard { - self.get_white_occupancies() | self.get_black_occupancies() + pub fn all_occupancies(&self) -> Bitboard { + self.white_occupancies() | self.black_occupancies() } - pub fn is_attacked(&self, sq: usize, opponent_color: Color) -> bool { - let all_occupancies = self.get_all_occupancies(); - let (enemy, own_color) = match opponent_color { + pub fn is_attacked(&self, square: usize, opponent_color: Color) -> bool { + let all_occupancies = self.all_occupancies(); + let (opponent, own_color) = match opponent_color { Color::Black => (&self.black_pieces, Color::White), Color::White => (&self.white_pieces, Color::Black), }; have_common_bit( - enemy[Kind::Pawn.idx()].bitboard, - get_pawn_attacks(sq, own_color), - ) || have_common_bit(enemy[Kind::Knight.idx()].bitboard, get_knight_attacks(sq)) - || have_common_bit( - enemy[Kind::Bishop.idx()].bitboard, - get_bishop_attacks(all_occupancies, sq), - ) - || have_common_bit( - enemy[Kind::Rook.idx()].bitboard, - get_rook_attacks(all_occupancies, sq), - ) - || have_common_bit( - enemy[Kind::Queen.idx()].bitboard, - get_queen_attacks(all_occupancies, sq), - ) - || have_common_bit(enemy[Kind::King.idx()].bitboard, get_king_attacks(sq)) + opponent[Kind::Pawn.idx()].bitboard, + fetch_pawn_attacks(square, own_color), + ) || have_common_bit( + opponent[Kind::Knight.idx()].bitboard, + fetch_knight_attacks(square), + ) || have_common_bit( + opponent[Kind::Bishop.idx()].bitboard, + fetch_bishop_attacks(all_occupancies, square), + ) || have_common_bit( + opponent[Kind::Rook.idx()].bitboard, + fetch_rook_attacks(all_occupancies, square), + ) || have_common_bit( + opponent[Kind::Queen.idx()].bitboard, + fetch_queen_attacks(all_occupancies, square), + ) || have_common_bit( + opponent[Kind::King.idx()].bitboard, + fetch_king_attacks(square), + ) } pub fn is_move_legit(&self, square: usize, opponent_color: Color) -> bool { @@ -129,17 +131,17 @@ impl Board { moves } pub fn pseudo_moves(&self, color: Color, kind: Kind) -> Vec { - let all_occupancies = self.get_all_occupancies(); - let (pieces, enemy_occupancies, own_occupancies) = match color { + let all_occupancies = self.all_occupancies(); + let (pieces, opponent_occupancies, own_occupancies) = match color { Color::White => ( self.white_pieces[kind.idx()].bitboard, - self.get_black_occupancies(), - self.get_white_occupancies(), + self.black_occupancies(), + self.white_occupancies(), ), Color::Black => ( self.black_pieces[kind.idx()].bitboard, - self.get_white_occupancies(), - self.get_black_occupancies(), + self.white_occupancies(), + self.black_occupancies(), ), }; @@ -147,8 +149,8 @@ impl Board { Kind::Pawn => pawn_pseudo_moves( pieces, all_occupancies, - enemy_occupancies, - self.state.get_en_passant_target_square(), + opponent_occupancies, + self.state.en_passant_target_square(), color, ), Kind::Knight => knight_pseudo_moves(pieces, all_occupancies, own_occupancies), @@ -175,9 +177,9 @@ impl Board { Color::Black => &self.black_pieces, }; - self.state.update_castling_state_quiet(mv.source, color); + self.state.update_castling_state_quiet(mv.src, color); self.state - .update_castling_state_capture(mv.target, Color::opponent_color(color)); + .update_castling_state_capture(mv.dst, Color::opponent_color(color)); self.state.change_side(); let own_king_square = lsb(pieces[Kind::King.idx()].bitboard); @@ -192,52 +194,52 @@ impl Board { match &mv.move_type { MoveType::Quiet => { - Self::move_piece(mv.source, mv.target, own_pieces); + Self::move_piece(mv.src, mv.dst, own_pieces); self.state.set_en_passant_target_square(None); } MoveType::Capture => { - Self::move_piece(mv.source, mv.target, own_pieces); - Self::remove_piece(mv.target, opponent_pieces); + Self::move_piece(mv.src, mv.dst, own_pieces); + Self::remove_piece(mv.dst, opponent_pieces); self.state.set_en_passant_target_square(None); } MoveType::EnPassant => { - Self::move_piece(mv.source, mv.target, own_pieces); - Self::remove_pawn_enpassant(mv.target, opponent_pieces, color); + Self::move_piece(mv.src, mv.dst, own_pieces); + Self::remove_pawn_enpassant(mv.dst, opponent_pieces, color); self.state.set_en_passant_target_square(None); } MoveType::DoublePush => { - Self::move_piece(mv.source, mv.target, own_pieces); + Self::move_piece(mv.src, mv.dst, own_pieces); let en_passant = match color { - Color::White => Some(mv.source + 8), - Color::Black => Some(mv.source - 8), + Color::White => Some(mv.src + 8), + Color::Black => Some(mv.src - 8), }; self.state.set_en_passant_target_square(en_passant); } MoveType::Promotion(promote) => { - Self::remove_piece(mv.source, own_pieces); - Self::promote_piece(mv.target, own_pieces, *promote); + Self::remove_piece(mv.src, own_pieces); + Self::promote_piece(mv.dst, own_pieces, *promote); self.state.set_en_passant_target_square(None); } MoveType::PromotionCapture(promote) => { - Self::remove_piece(mv.source, own_pieces); - Self::remove_piece(mv.target, opponent_pieces); - Self::promote_piece(mv.target, own_pieces, *promote); + Self::remove_piece(mv.src, own_pieces); + Self::remove_piece(mv.dst, opponent_pieces); + Self::promote_piece(mv.dst, own_pieces, *promote); self.state.set_en_passant_target_square(None); } MoveType::Castle => { - Self::move_piece(mv.source, mv.target, own_pieces); - Self::move_rook_castle(mv.target, own_pieces); + Self::move_piece(mv.src, mv.dst, own_pieces); + Self::move_rook_castle(mv.dst, own_pieces); self.state.set_en_passant_target_square(None); self.state.set_castling_ability(color, Castle::None) } } } - fn move_piece(source: usize, target: usize, pieces: &mut [Piece; 6]) { + fn move_piece(src: usize, dst: usize, pieces: &mut [Piece; 6]) { for p in pieces.iter_mut() { - if have_common_bit(p.bitboard, square_to_bitboard(source)) { - p.bitboard &= !square_to_bitboard(source); - p.bitboard |= square_to_bitboard(target); + if have_common_bit(p.bitboard, square_to_bitboard(src)) { + p.bitboard &= !square_to_bitboard(src); + p.bitboard |= square_to_bitboard(dst); break; } } @@ -277,12 +279,7 @@ impl Board { Color::Black => square + 8, }; - for p in pieces.iter_mut() { - if have_common_bit(p.bitboard, square_to_bitboard(piece_to_remove)) { - p.bitboard &= !(square_to_bitboard(piece_to_remove)); - break; - } - } + Self::remove_piece(piece_to_remove, pieces); } } @@ -349,11 +346,11 @@ mod tests { const FEN_EXAMPLE: [&str; 1] = ["8/6P1/4n2b/1p6/1Kp5/6n1/4b3/1k6 w - - 0 1"]; #[test] - fn test_get_occupancies() -> Result<(), String> { + fn test_occupancies() -> Result<(), String> { let new_game = from_fen(FEN_EXAMPLE[0])?; - assert_eq!(new_game.board.get_white_occupancies(), 0x40000002000000); - assert_eq!(new_game.board.get_black_occupancies(), 0x900204401002); - assert_eq!(new_game.board.get_all_occupancies(), 0x40900206401002); + assert_eq!(new_game.board.white_occupancies(), 0x40000002000000); + assert_eq!(new_game.board.black_occupancies(), 0x900204401002); + assert_eq!(new_game.board.all_occupancies(), 0x40900206401002); Ok(()) } diff --git a/src/move.rs b/src/move.rs index 5c839f2..bbb2820 100644 --- a/src/move.rs +++ b/src/move.rs @@ -19,24 +19,24 @@ pub enum MoveType { #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)] pub struct Move { - pub source: usize, - pub target: usize, + pub src: usize, + pub dst: usize, pub move_type: MoveType, } impl Move { - pub const fn new(source: usize, target: usize) -> Self { + pub const fn new(src: usize, dst: usize) -> Self { Self { - source, - target, + src, + dst, move_type: MoveType::Quiet, } } - pub const fn new_with_type(source: usize, target: usize, move_type: MoveType) -> Self { + pub const fn new_with_type(src: usize, dst: usize, move_type: MoveType) -> Self { Self { - source, - target, + src, + dst, move_type, } } diff --git a/src/movegen.rs b/src/movegen.rs index ecd2cde..5cb8dde 100644 --- a/src/movegen.rs +++ b/src/movegen.rs @@ -1,6 +1,6 @@ use crate::attack::{ - get_bishop_attacks, get_king_attacks, get_knight_attacks, get_pawn_attacks, get_queen_attacks, - get_rook_attacks, + fetch_bishop_attacks, fetch_king_attacks, fetch_knight_attacks, fetch_pawn_attacks, + fetch_queen_attacks, fetch_rook_attacks, }; use crate::bitboard::{ have_common_bit, lsb, square_to_bitboard, NOT_FILE_A, NOT_FILE_H, RANK_1, RANK_2, RANK_4, @@ -14,7 +14,7 @@ use u64 as Bitboard; pub fn pawn_pseudo_moves( pawns: Bitboard, all_occupancies: Bitboard, - enemy_occupancies: Bitboard, + opponent_occupancies: Bitboard, en_passant_square: Option, color: Color, ) -> Vec { @@ -24,7 +24,7 @@ pub fn pawn_pseudo_moves( moves.extend(white_pawn_quiet_moves(pawns, all_occupancies)); moves.extend(white_pawn_capture_moves( pawns, - enemy_occupancies, + opponent_occupancies, en_passant_square, )); } @@ -32,7 +32,7 @@ pub fn pawn_pseudo_moves( moves.extend(black_pawn_quiet_moves(pawns, all_occupancies)); moves.extend(black_pawn_capture_moves( pawns, - enemy_occupancies, + opponent_occupancies, en_passant_square, )); } @@ -44,9 +44,9 @@ fn white_pawn_quiet_moves(pawns: Bitboard, occupancies: Bitboard) -> Vec { let mut moves = vec![]; let empty = !occupancies; - let mut single_push_targets = (pawns << 8) & empty; - while single_push_targets != 0 { - let to = lsb(single_push_targets); + let mut single_push = (pawns << 8) & empty; + while single_push != 0 { + let to = lsb(single_push); let from = to - 8; if have_common_bit(square_to_bitboard(from), RANK_7) { @@ -59,16 +59,16 @@ fn white_pawn_quiet_moves(pawns: Bitboard, occupancies: Bitboard) -> Vec { } else { moves.push(Move::new(from, to)); } - single_push_targets &= single_push_targets - 1; + single_push &= single_push - 1; } - let single_push_targets = (pawns << 8) & empty; - let mut double_push_targets = (single_push_targets << 8) & empty & RANK_4; - while double_push_targets != 0 { - let to = lsb(double_push_targets); + let single_push = (pawns << 8) & empty; + let mut double_push = (single_push << 8) & empty & RANK_4; + while double_push != 0 { + let to = lsb(double_push); let from = to - 16; moves.push(Move::new_with_type(from, to, MoveType::DoublePush)); - double_push_targets &= double_push_targets - 1; + double_push &= double_push - 1; } moves } @@ -77,9 +77,9 @@ fn black_pawn_quiet_moves(pawns: Bitboard, occupancies: Bitboard) -> Vec { let mut moves = vec![]; let empty = !occupancies; - let mut single_push_targets = (pawns >> 8) & empty; - while single_push_targets != 0 { - let to = lsb(single_push_targets); + let mut single_push = (pawns >> 8) & empty; + while single_push != 0 { + let to = lsb(single_push); let from = to + 8; if have_common_bit(square_to_bitboard(from), RANK_2) { @@ -92,28 +92,28 @@ fn black_pawn_quiet_moves(pawns: Bitboard, occupancies: Bitboard) -> Vec { } else { moves.push(Move::new(from, to)); } - single_push_targets &= single_push_targets - 1; + single_push &= single_push - 1; } - let single_push_targets = (pawns >> 8) & empty; - let mut double_push_targets = (single_push_targets >> 8) & empty & RANK_5; - while double_push_targets != 0 { - let to = lsb(double_push_targets); + let single_push = (pawns >> 8) & empty; + let mut double_push = (single_push >> 8) & empty & RANK_5; + while double_push != 0 { + let to = lsb(double_push); let from = to + 16; moves.push(Move::new_with_type(from, to, MoveType::DoublePush)); - double_push_targets &= double_push_targets - 1; + double_push &= double_push - 1; } moves } fn white_pawn_capture_moves( pawns: Bitboard, - enemy_occupancies: Bitboard, + opponent_occupancies: Bitboard, en_passant_square: Option, ) -> Vec { let mut moves = vec![]; - let mut w_pawns_capture_east = pawns & ((enemy_occupancies >> 9) & NOT_FILE_H); - let mut w_pawns_capture_west = pawns & ((enemy_occupancies >> 7) & NOT_FILE_A); + let mut w_pawns_capture_east = pawns & ((opponent_occupancies >> 9) & NOT_FILE_H); + let mut w_pawns_capture_west = pawns & ((opponent_occupancies >> 7) & NOT_FILE_A); while w_pawns_capture_east != 0 { let from = lsb(w_pawns_capture_east); @@ -148,13 +148,13 @@ fn white_pawn_capture_moves( w_pawns_capture_west &= w_pawns_capture_west - 1; } - if let Some(en_passant_square) = en_passant_square { - let attacked_from = get_pawn_attacks(en_passant_square, Color::Black); + if let Some(en_passant_sq) = en_passant_square { + let attacked_from = fetch_pawn_attacks(en_passant_sq, Color::Black); let mut result = attacked_from & pawns; while result != 0 { moves.push(Move::new_with_type( lsb(result), - en_passant_square, + en_passant_sq, MoveType::EnPassant, )); result &= result - 1; @@ -165,12 +165,12 @@ fn white_pawn_capture_moves( fn black_pawn_capture_moves( pawns: Bitboard, - enemy_occupancies: Bitboard, + opponent_occupancies: Bitboard, en_passant_square: Option, ) -> Vec { let mut moves = vec![]; - let mut b_pawns_capture_east = pawns & ((enemy_occupancies << 7) & NOT_FILE_H); - let mut b_pawns_capture_west = pawns & ((enemy_occupancies << 9) & NOT_FILE_A); + let mut b_pawns_capture_east = pawns & ((opponent_occupancies << 7) & NOT_FILE_H); + let mut b_pawns_capture_west = pawns & ((opponent_occupancies << 9) & NOT_FILE_A); while b_pawns_capture_east != 0 { let from = lsb(b_pawns_capture_east); @@ -206,7 +206,7 @@ fn black_pawn_capture_moves( } if let Some(en_passant_square) = en_passant_square { - let attacked_from = get_pawn_attacks(en_passant_square, Color::White); + let attacked_from = fetch_pawn_attacks(en_passant_square, Color::White); let mut result = attacked_from & pawns; while result != 0 { moves.push(Move::new_with_type( @@ -226,16 +226,16 @@ pub fn knight_pseudo_moves( own_occupancies: Bitboard, ) -> Vec { let mut moves = vec![]; - let enemy_occupancies = all_occupancies ^ own_occupancies; + let opponent_occupancies = all_occupancies ^ own_occupancies; while knights != 0 { let knight_square = lsb(knights); let from = knight_square; - let mut attacks = get_knight_attacks(knight_square) & !own_occupancies; + let mut attacks = fetch_knight_attacks(knight_square) & !own_occupancies; while attacks != 0 { let attack_sq = lsb(attacks); - if have_common_bit(square_to_bitboard(attack_sq), enemy_occupancies) { + if have_common_bit(square_to_bitboard(attack_sq), opponent_occupancies) { moves.push(Move::new_with_type(from, attack_sq, MoveType::Capture)); } else { moves.push(Move::new(from, attack_sq)); @@ -253,16 +253,16 @@ pub fn bishop_pseudo_moves( own_occupancies: Bitboard, ) -> Vec { let mut moves = vec![]; - let enemy_occupancies = all_occupancies ^ own_occupancies; + let opponent_occupancies = all_occupancies ^ own_occupancies; while bishops != 0 { let bishop_square = lsb(bishops); let from = bishop_square; - let mut attacks = get_bishop_attacks(all_occupancies, bishop_square) & !own_occupancies; + let mut attacks = fetch_bishop_attacks(all_occupancies, bishop_square) & !own_occupancies; while attacks != 0 { let attack_sq = lsb(attacks); - if have_common_bit(square_to_bitboard(attack_sq), enemy_occupancies) { + if have_common_bit(square_to_bitboard(attack_sq), opponent_occupancies) { moves.push(Move::new_with_type(from, attack_sq, MoveType::Capture)); } else { moves.push(Move::new(from, attack_sq)); @@ -280,16 +280,16 @@ pub fn rook_pseudo_moves( own_occupancies: Bitboard, ) -> Vec { let mut moves = vec![]; - let enemy_occupancies = all_occupancies ^ own_occupancies; + let opponent_occupancies = all_occupancies ^ own_occupancies; while rooks != 0 { let rook_square = lsb(rooks); let from = rook_square; - let mut attacks = get_rook_attacks(all_occupancies, rook_square) & !own_occupancies; + let mut attacks = fetch_rook_attacks(all_occupancies, rook_square) & !own_occupancies; while attacks != 0 { let attack_sq = lsb(attacks); - if have_common_bit(square_to_bitboard(attack_sq), enemy_occupancies) { + if have_common_bit(square_to_bitboard(attack_sq), opponent_occupancies) { moves.push(Move::new_with_type(from, attack_sq, MoveType::Capture)); } else { moves.push(Move::new(from, attack_sq)); @@ -307,16 +307,16 @@ pub fn queen_pseudo_moves( own_occupancies: Bitboard, ) -> Vec { let mut moves = vec![]; - let enemy_occupancies = all_occupancies ^ own_occupancies; + let opponent_occupancies = all_occupancies ^ own_occupancies; while queens != 0 { let queen_square = lsb(queens); let from = queen_square; - let mut attacks = get_queen_attacks(all_occupancies, queen_square) & !own_occupancies; + let mut attacks = fetch_queen_attacks(all_occupancies, queen_square) & !own_occupancies; while attacks != 0 { let attack_sq = lsb(attacks); - if have_common_bit(square_to_bitboard(attack_sq), enemy_occupancies) { + if have_common_bit(square_to_bitboard(attack_sq), opponent_occupancies) { moves.push(Move::new_with_type(from, attack_sq, MoveType::Capture)); } else { moves.push(Move::new(from, attack_sq)); @@ -338,12 +338,12 @@ pub fn king_pseudo_moves( let mut moves = vec![]; let king_square = lsb(king); let from = king_square; - let mut attacks = get_king_attacks(king_square) & !own_occupancies; - let enemy_occupancies = all_occupancies ^ own_occupancies; + let mut attacks = fetch_king_attacks(king_square) & !own_occupancies; + let opponent_occupancies = all_occupancies ^ own_occupancies; while attacks != 0 { let attack_sq = lsb(attacks); - if have_common_bit(square_to_bitboard(attack_sq), enemy_occupancies) { + if have_common_bit(square_to_bitboard(attack_sq), opponent_occupancies) { moves.push(Move::new_with_type(from, attack_sq, MoveType::Capture)); } else { moves.push(Move::new(from, attack_sq)); @@ -369,7 +369,7 @@ fn king_castling_moves(board: &Board, color: Color, all_occupancies: Bitboard) - }; match ( - board.state.get_castling_ability(color), + board.state.castling_ability(color), king_and_adj_square_safety(board, color), ) { (Castle::Both, Castle::Both) => { diff --git a/src/square.rs b/src/square.rs index a30d6f6..d95bec7 100644 --- a/src/square.rs +++ b/src/square.rs @@ -81,7 +81,7 @@ pub const fn coords_to_square(rank: usize, file: usize) -> usize { } impl Square { - pub const fn to_bitboard(sq: usize) -> Bitboard { - 1_u64 << sq + pub const fn to_bitboard(square: usize) -> Bitboard { + 1_u64 << square } } diff --git a/src/state.rs b/src/state.rs index 0cd924a..6db59b0 100644 --- a/src/state.rs +++ b/src/state.rs @@ -36,7 +36,7 @@ impl State { } } - pub const fn get_en_passant_target_square(&self) -> Option { + pub const fn en_passant_target_square(&self) -> Option { self.en_passant_target_square } @@ -47,10 +47,10 @@ impl State { } } - pub fn update_castling_state_quiet(&mut self, source: usize, color: Color) { - self.update_castling_state_capture(source, color); + pub fn update_castling_state_quiet(&mut self, src: usize, color: Color) { + self.update_castling_state_capture(src, color); - match (source, color) { + match (src, color) { (4, Color::White) => self.set_castling_ability(color, Castle::None), (60, Color::Black) => self.set_castling_ability(color, Castle::None), _ => (), @@ -64,7 +64,7 @@ impl State { }; if target == short_square { - match self.get_castling_ability(color) { + match self.castling_ability(color) { Castle::Both => self.set_castling_ability(color, Castle::Long), Castle::Short => self.set_castling_ability(color, Castle::None), _ => (), @@ -72,7 +72,7 @@ impl State { } if target == long_square { - match self.get_castling_ability(color) { + match self.castling_ability(color) { Castle::Both => self.set_castling_ability(color, Castle::Short), Castle::Long => self.set_castling_ability(color, Castle::None), _ => (), @@ -91,11 +91,11 @@ impl State { self.side_to_move } - pub fn set_en_passant_target_square(&mut self, sq: Option) { - self.en_passant_target_square = sq; + pub fn set_en_passant_target_square(&mut self, square: Option) { + self.en_passant_target_square = square; } - pub const fn get_castling_ability(&self, color: Color) -> Castle { + pub const fn castling_ability(&self, color: Color) -> Castle { match color { Color::White => self.castling_ability[0], Color::Black => self.castling_ability[1],