Skip to content

Commit

Permalink
normal_from_candidates invokes prelegality::normal_from_candidates
Browse files Browse the repository at this point in the history
  • Loading branch information
koba-e964 committed Jun 6, 2022
1 parent 5085c3f commit a812285
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions shogi_legality_lite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,24 @@ impl LegalityChecker for LiteLegalityChecker {

fn normal_from_candidates(&self, position: &PartialPosition, from: Square) -> Bitboard {
let mut result = Bitboard::empty();
for to in Square::all() {
for promote in [true, false] {
let side = position.side_to_move();
let my_bb = position.player_bitboard(side);
if !my_bb.contains(from) {
return Bitboard::empty();
}
let to_candidates = prelegality::normal_from_candidates(position, from);
for (index, to_candidates) in to_candidates.into_iter().enumerate() {
let promote = index == 1;
for to in to_candidates {
let mv = Move::Normal { from, to, promote };
if self.is_legal_partial_lite(position, mv) {
result |= to;
let mut next = position.clone();
if next.make_move(mv).is_none() {
continue;
}
if prelegality::will_king_be_captured(&next) == Some(true) {
continue;
}
result |= to;
}
}
result
Expand Down

0 comments on commit a812285

Please sign in to comment.