Skip to content

Commit

Permalink
Remove no king safeguards
Browse files Browse the repository at this point in the history
  • Loading branch information
bdmendes committed Dec 25, 2024
1 parent 0fd3d2e commit b44b30a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
4 changes: 0 additions & 4 deletions src/core/fen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ impl TryFrom<Fen> for Position {
let white_king = (kings & position.occupancy_bb(Color::White)).next();
let black_king = (kings & position.occupancy_bb(Color::Black)).next();

if white_king.is_none() || black_king.is_none() {
return Err(());
}

let mut rights = CastlingRights::default();
for c in words.next().ok_or(())?.chars() {
match c {
Expand Down
17 changes: 10 additions & 7 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,19 +275,22 @@ impl Position {
let moves = generate_moves(self, MoveStage::All);
for m in moves {
if mov == m.to_string().as_str() {
return Some(self.make_move(m));
let new_position = self.make_move(m);
/*println!(
"hash after {}: {} {}",
mov,
new_position.hash().0,
new_position.hash_from_scratch().0
);*/
return Some(new_position);
}
}
None
}

pub fn is_check(&self) -> bool {
let king = self.pieces_color_bb(Piece::King, self.side_to_move()).lsb();
if let Some(king_square) = king {
!self.attackers(king_square, self.side_to_move().flipped()).is_empty()
} else {
true
}
let king = self.pieces_color_bb(Piece::King, self.side_to_move()).lsb().unwrap();
!self.attackers(king, self.side_to_move().flipped()).is_empty()
}

pub fn attackers(&self, square: Square, by_color: Color) -> Bitboard {
Expand Down
2 changes: 1 addition & 1 deletion src/evaluation/position/king.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn king_tropism(position: &Position, king_color: Color, king_square: Square) ->
let piece_cof = match position.piece_at(sq) {
Some(Piece::Queen) | Some(Piece::Rook) => 2,
Some(Piece::Bishop) | Some(Piece::Knight) => 1,
_ => 2,
_ => unreachable!(),
};
acc + ((14 - distance) * piece_cof) as ValueScore
});
Expand Down

0 comments on commit b44b30a

Please sign in to comment.