inplement .index() in Color

This commit is contained in:
vova-rs committed 2026-10-10 12:33:21 +03:00
1 parent 45e1843fba
commit a61395ca6a
3 files changed
+57 -24

No files matched your search

+32 -16
View File
@@ -27,26 +27,42 @@ impl ChessEngine for Breakthrough {
}
fn apply(&mut self, mv: Move) -> Result<(), MoveErrors> {
if let Some(ref h) = self.legal_moves {
todo!();
} else {
Err(MoveErrors::NoMove)
if self.status() != GameStatus::Ongoing {
return Err(MoveErrors::GameOver);
}
// 1. Достаём патч. Если хода нет в кэше — он нелегален.
let patch = match self.legal_moves.as_ref().and_then(|m| m.get(&mv)) {
Some(p) => p.clone(),
None => return Err(MoveErrors::InvalidMove),
};
// 2. Применяем патч к доске (детали зависят от Board API).
self.board.apply_patch(&patch);
// 3. Меняем сторону.
self.side = self.side.opposite();
// 4. Пересчитываем легальные ходы для новой стороны.
self.refresh_legal_moves();
Ok(())
}
fn status(&self) -> GameStatus {
if self.board.is_mask_zero(0, 0) {
return GameStatus::Won(Color::White);
}
if self.board.is_mask_zero(0, 1) {
return GameStatus::Won(Color::Black);
}
if !self.board.and_mask_is_zero(0, 1, WHITE_WON_ZONE){
return GameStatus::Won(Color::White);
}
if !self.board.and_mask_is_zero(0, 0, BLACK_WON_ZONE){
return GameStatus::Won(Color::Black);
}
todo!();
// if self.board.is_mask_zero(0, 0) {
// return GameStatus::Won(Color::White);
// }
// if self.board.is_mask_zero(0, 1) {
// return GameStatus::Won(Color::Black);
// }
// if !self.board.and_mask_is_zero(0, 1, WHITE_WON_ZONE){
// return GameStatus::Won(Color::White);
// }
// if !self.board.and_mask_is_zero(0, 0, BLACK_WON_ZONE){
// return GameStatus::Won(Color::Black);
// }
GameStatus::Ongoing
}