move input whitch predikt

This commit is contained in:
vova-rs committed 2026-10-15 20:51:29 +03:00
1 parent 2c2ccd6770
commit 27fd785034
3 files changed
+112 -25

No files matched your search

+48 -5
View File
@@ -4,15 +4,58 @@ use chess_api::*;
mod render_bitmask;
use render_bitmask::*;
mod gaming;
use gaming::read_square;
fn main() {
let mut game: Breakthrough = Breakthrough::new();
let mut game = Breakthrough::new();
let b = game.get_board();
loop {
println!("---<>---");
println!("move: {}", game.legal_moves().len());
let b = game.get_board();
render_board(BoardColor::Solid('~'), vec![(b.get_mask(Color::White, 0), 'W'), (0xff << 56, 'f')]);
render_board(
BoardColor::Checkerboard('•', ' '),
&[
(b.get_mask(Color::White, 0), '●'),
(b.get_mask(Color::Black, 0), '○'),
],
);
println!("move: {:?}", game.legal_moves());
let status = game.status();
println!("side: {:?}", game.side_to_move());
if status != GameStatus::Ongoing {
println!("game over: {:?}", status);
break;
}
let moves = game.legal_moves();
let to_input = read_square();
let candidates: Vec<Move> = moves.iter().filter(|m| to_input.matches(m.to)).copied().collect();
let chosen = match candidates.len() {
0 => {
println!("no legal move to that square");
continue;
}
1 => candidates[0],
_ => {
let from_input = read_square();
let exact: Vec<Move> = candidates.iter().filter(|m| from_input.matches(m.from)).copied().collect();
match exact.len() {
0 => {
println!("no legal move from that square");
continue;
}
_ => exact[0],
}
}
};
game.apply(chosen).unwrap();
}
}