From a81228576d9a5941a723aaa10b86f9753952045f Mon Sep 17 00:00:00 2001 From: koba-e964 <3303362+koba-e964@users.noreply.github.com> Date: Mon, 6 Jun 2022 23:08:10 +0900 Subject: [PATCH] normal_from_candidates invokes prelegality::normal_from_candidates --- shogi_legality_lite/src/lib.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/shogi_legality_lite/src/lib.rs b/shogi_legality_lite/src/lib.rs index ff80728..6de38cb 100644 --- a/shogi_legality_lite/src/lib.rs +++ b/shogi_legality_lite/src/lib.rs @@ -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