Skip to content

Commit

Permalink
feat: fixed bihop move generation + is_in_check()
Browse files Browse the repository at this point in the history
  • Loading branch information
KrinjMaster committed Mar 18, 2024
1 parent 0e3ac4d commit cd6008c
Show file tree
Hide file tree
Showing 7 changed files with 5,068 additions and 5,096 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[package]
name = "krinj-mater"
name = "ravissant"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.5"

31 changes: 8 additions & 23 deletions src/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,12 @@ use crate::{
constants::{BOARD_SQUARES, FIFTH_RANK, FOURTH_RANK},
move_generation::{
generate_bishop_moves, generate_king_moves, generate_knight_moves, generate_pawn_moves,
generate_quen_moves, generate_rook_moves,
generate_queen_moves, generate_rook_moves,
},
piece_parsing::parse_bitboards,
utils::print_bitboard,
};

// board when encoded looks something like this
// 1 . . . . . . . .
// 2 . . . . . . . .
// 3 . . . . . . . .
// 4 . . . . . . . .
// 5 . . . . . . . .
// 6 . . . . . . . .
// 7 . . . . . . . .
// 8 . . . . . . . .
// h g f e d c b a

pub fn count_ones(bb: Bitboard) -> u8 {
bb.count_ones() as u8
}
Expand Down Expand Up @@ -67,15 +56,11 @@ impl BoardState {
};

let all_attacks = self
.generate_moves_by_color(&opposite_color)
.generate_moves_by_color(&self.to_move)
.iter()
.fold(0, |acc, cur| acc | cur.1);

if all_attacks & self.get_piece_bb(self.to_move, Piece::King) != 0 {
return true;
} else {
return false;
}
all_attacks & self.get_piece_bb(opposite_color, Piece::King) != 0
}

pub fn make_move(&mut self, color: &Color, piece: &Piece, piece_move: (Bitboard, Bitboard)) {
Expand Down Expand Up @@ -351,7 +336,7 @@ impl BoardState {
let bishops_moves = generate_bishop_moves(
parse_bitboards(*color, self.get_piece_bb(*color, Piece::Bishop)),
self.bb_colors[*color as usize],
self.get_color_bb(*color) | self.get_color_bb(*opposite_color),
self.bb_fullboard,
);

for piece_move in bishops_moves.iter() {
Expand All @@ -374,7 +359,7 @@ impl BoardState {
let rooks_moves = generate_rook_moves(
parse_bitboards(*color, self.get_piece_bb(*color, Piece::Rook)),
self.bb_colors[*color as usize],
self.get_color_bb(*color) | self.get_color_bb(*opposite_color),
self.bb_fullboard,
);

for piece_move in rooks_moves.iter() {
Expand All @@ -394,10 +379,10 @@ impl BoardState {
}
}

let queens_moves = generate_quen_moves(
parse_bitboards(*color, self.get_piece_bb(*color, Piece::Rook)),
let queens_moves = generate_queen_moves(
parse_bitboards(*color, self.get_piece_bb(*color, Piece::Queen)),
self.bb_fullboard,
self.bb_colors[*color as usize],
self.get_color_bb(*color) | self.get_color_bb(*opposite_color),
);

for piece_move in queens_moves.iter() {
Expand Down
Loading

0 comments on commit cd6008c

Please sign in to comment.