Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ edition = "2024"
[lib]
name = "mouse"

[dependencies]
getset = "0.1.6"

[build]
rustflags = ["-C", "target-cpu=native"]

Expand Down
10 changes: 5 additions & 5 deletions src/backend/movegen/check_decider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use crate::backend::state::piece::{ALL_PIECES, Piece, Side};
use crate::backend::state::square::Square;

pub fn is_in_check_on_square(game_state: &State, color: Side, king_square: Square) -> bool {
let friendly_bb = game_state.bb_manager().get_all_pieces_bb_off(color);
let friendly_bb = game_state.bb_manager.get_all_pieces_bb_off(color);
let enemy_bb = game_state
.bb_manager()
.bb_manager
.get_all_pieces_bb_off(color.opposite());

// Iterate over all pieces. Let`s assume we are checking for knights.
Expand All @@ -24,7 +24,7 @@ pub fn is_in_check_on_square(game_state: &State, color: Side, king_square: Squar
);

// Get the bitboard that marks where enemy knights are standing.
let enemy_piece_bitboard = game_state.bb_manager().get_piece_bb(piece_type) & enemy_bb;
let enemy_piece_bitboard = game_state.bb_manager.get_piece_bb(piece_type) & enemy_bb;

// Check if at least one of the places we could move to contains an enemy knight.
let resulting_bitboard = attack_bitboard & enemy_piece_bitboard;
Expand Down Expand Up @@ -72,8 +72,8 @@ pub fn is_in_check(game_state: &State, color: Side) -> bool {

/// Returns the square where the king of the respective side is located.
fn get_kings_square(game_state: &State, color: Side) -> Square {
let king_bitboard = game_state.bb_manager().get_piece_bb(Piece::King);
let side_bb = game_state.bb_manager().get_all_pieces_bb_off(color);
let king_bitboard = game_state.bb_manager.get_piece_bb(Piece::King);
let side_bb = game_state.bb_manager.get_all_pieces_bb_off(color);
let mut bb = king_bitboard & side_bb;
bb.next().unwrap()
}
Expand Down
12 changes: 4 additions & 8 deletions src/backend/movegen/moove.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::backend::state::piece::Piece;
use crate::backend::state::piece::Piece::{Bishop, Knight, Queen, Rook};
use crate::backend::state::square::Square;
use getset::{CloneGetters, Setters};
use std::fmt::{Display, Formatter};

#[derive(Copy, Clone)]
Expand Down Expand Up @@ -30,14 +29,11 @@ impl CastleType {
///
/// Alternatively, each Move could store a bitboard, with one bit set where we currently are and one where we are going to.
/// To "make" this move we then would only need to xor it with the bitboard for the piece.
#[derive(Copy, Clone, Debug, CloneGetters, Setters, Ord, Eq, PartialEq, PartialOrd)]
#[derive(Copy, Clone, Debug, Ord, Eq, PartialEq, PartialOrd)]
pub struct Moove {
#[getset(get_clone = "pub", set = "pub")]
from: Square,
#[getset(get_clone = "pub", set = "pub")]
to: Square,
#[getset(get_clone = "pub", set = "pub")]
promotion_type: Option<Piece>,
pub from: Square,
pub to: Square,
pub promotion_type: Option<Piece>,
}

impl Moove {
Expand Down
8 changes: 4 additions & 4 deletions src/backend/movegen/move_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ use crate::backend::state::square::Square;
/// * A `Vec<Moove>` containing all the computed pseudo legal moves for the current player's
/// pieces.
pub fn get_pseudo_legal_moves(game_state: &State) -> Vec<Moove> {
let bitboard_manager = game_state.bb_manager();
let bitboard_manager = &game_state.bb_manager;
// Bitboard containing all pieces of the active color. These block moves.
let friendly_pieces_bb = bitboard_manager.get_all_pieces_bb_off(game_state.active_color());
let friendly_pieces_bb = bitboard_manager.get_all_pieces_bb_off(game_state.active_color);
// Bitboard containing all pieces of the opponent color. These are relevant for sliders and pawn captures.
let enemy_pieces_bb =
bitboard_manager.get_all_pieces_bb_off(game_state.active_color().opposite());
bitboard_manager.get_all_pieces_bb_off(game_state.active_color.opposite());

let mut all_pseudo_legal_moves = Vec::new();
let active_color = game_state.active_color();
let active_color = game_state.active_color;

// Move gen for king and knight (excluding castles)
for trivial_type in TRIVIAL_PIECES {
Expand Down
6 changes: 3 additions & 3 deletions src/backend/movegen/move_gen_king_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ pub fn gen_castles(
game_state: &State,
combined_bb: BitBoard,
) {
let irreversible_data = game_state.irreversible_data();
let irreversible_data = &game_state.irreversible_data;

for castle_type in CastleType::get_all_types() {
let (castling_rights, squares_the_king_moves_through, between_king_rook_bb, moove) =
get_needed_constants(irreversible_data, &castle_type, game_state.active_color());
get_needed_constants(irreversible_data, &castle_type, game_state.active_color);

gen_castle(
all_pseudo_legal_moves,
Expand Down Expand Up @@ -62,7 +62,7 @@ fn gen_castle(
// are we moving through checks?
for square in squares_the_king_moves_through.iter() {
// if so -> stop
if is_in_check_on_square(game_state, game_state.active_color(), *square) {
if is_in_check_on_square(game_state, game_state.active_color, *square) {
return;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/backend/movegen/move_gen_pawn_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub fn get_double_pawn_push_moves(
pub fn create_pawn_capture_mask(game_state: &State, enemy_pieces_bitboard: BitBoard) -> BitBoard {
// Capture pawn moves
let mut pawn_capture_mask = enemy_pieces_bitboard;
match game_state.irreversible_data().en_passant_square() {
match game_state.irreversible_data.en_passant_square {
None => {}
Some(ep_square) => {
pawn_capture_mask.fill_square(ep_square);
Expand All @@ -103,14 +103,14 @@ pub fn promotion_logic(moves: &mut Vec<Moove>) {
}
for index in (0..moves.len()).rev() {
let moove = moves[index];
if moove.to().is_on_promotion_rank() {
if moove.to.is_on_promotion_rank() {
for piece_type in PROMOTABLE_PIECES {
if piece_type == Queen {
moves[index].set_promotion_type(Some(Queen));
moves[index].promotion_type = Some(Queen);
continue;
}
let mut moove = moove;
moove.set_promotion_type(Some(piece_type));
moove.promotion_type = Some(piece_type);
moves.push(moove);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/perft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn perft(state: &State, depth: u8) -> u64 {
for chess_move in moves {
let next_state = state.make_move(chess_move);
// If we are in check after making the move -> skip.
if is_in_check(&next_state, next_state.active_color().opposite()) {
if is_in_check(&next_state, next_state.active_color.opposite()) {
continue;
}

Expand Down
24 changes: 12 additions & 12 deletions src/backend/state/game/fen_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,45 +45,45 @@ pub fn parse_fen(

fn parse_en_passant(irreversible_data: &mut IrreversibleData, en_passant_file_string: &str) {
if en_passant_file_string == "-" {
irreversible_data.set_en_passant_square(None);
irreversible_data.en_passant_square = None;
return;
}

let mut en_passant_square = Square::new(0, 0);
for char in en_passant_file_string.chars() {
match char {
'a'..='h' => {
en_passant_square.set_file(char.to_digit(36).unwrap() as i8 - 10);
en_passant_square.file = char.to_digit(36).unwrap() as i8 - 10;
}
'3' | '6' => {
en_passant_square.set_rank(char.to_digit(10).unwrap() as i8 - 1);
en_passant_square.rank = char.to_digit(10).unwrap() as i8 - 1;
}
_ => panic!("Invalid character in FEN string"),
}
}
irreversible_data.set_en_passant_square(Some(en_passant_square));
irreversible_data.en_passant_square = Some(en_passant_square);
}

fn parse_castling_rights(irreversible_data: &mut IrreversibleData, castling_rights_string: &str) {
for char in castling_rights_string.chars() {
match char {
'-' => {
irreversible_data.set_white_long_castle_rights(false);
irreversible_data.set_white_short_castle_rights(false);
irreversible_data.set_black_long_castle_rights(false);
irreversible_data.set_black_short_castle_rights(false);
irreversible_data.white_long_castle_rights = false;
irreversible_data.white_short_castle_rights = false;
irreversible_data.black_long_castle_rights = false;
irreversible_data.black_short_castle_rights = false;
}
'K' => {
irreversible_data.set_white_short_castle_rights(true);
irreversible_data.white_short_castle_rights = true;
}
'k' => {
irreversible_data.set_black_short_castle_rights(true);
irreversible_data.black_short_castle_rights = true;
}
'Q' => {
irreversible_data.set_white_long_castle_rights(true);
irreversible_data.white_long_castle_rights = true;
}
'q' => {
irreversible_data.set_black_long_castle_rights(true);
irreversible_data.black_long_castle_rights = true;
}
_ => panic!("Invalid character in FEN string"),
}
Expand Down
21 changes: 7 additions & 14 deletions src/backend/state/game/irreversible_data.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
use crate::backend::movegen::moove::CastleType;
use crate::backend::state::piece::{Piece, Side};
use crate::backend::state::square::Square;
use getset::{CloneGetters, Setters};

/// The `IrreversibleData` struct stores data that is irreversible.
/// For example, this remembers what kind of piece was captured for `unmake_move()`.
#[derive(CloneGetters, Setters, Debug, Clone)]
#[derive(Debug, Clone)]
pub struct IrreversibleData {
#[getset(get_clone = "pub", set = "pub")]
captured_piece: Option<Piece>,
#[getset(get_clone = "pub", set = "pub")]
en_passant_square: Option<Square>,
#[getset(get_clone = "pub", set = "pub")]
white_long_castle_rights: bool,
#[getset(get_clone = "pub", set = "pub")]
white_short_castle_rights: bool,
#[getset(get_clone = "pub", set = "pub")]
black_long_castle_rights: bool,
#[getset(get_clone = "pub", set = "pub")]
black_short_castle_rights: bool,
pub captured_piece: Option<Piece>,
pub en_passant_square: Option<Square>,
pub white_long_castle_rights: bool,
pub white_short_castle_rights: bool,
pub black_long_castle_rights: bool,
pub black_short_castle_rights: bool,
}

impl IrreversibleData {
Expand Down
Loading