62 lines
1.5 KiB
Rust
62 lines
1.5 KiB
Rust
mod chess_api;
|
|
use chess_api::*;
|
|
|
|
mod render_bitmask;
|
|
use render_bitmask::*;
|
|
|
|
mod gaming;
|
|
use gaming::read_square;
|
|
|
|
fn main() {
|
|
|
|
let mut game = Breakthrough::new();
|
|
|
|
loop {
|
|
println!("---<>---");
|
|
|
|
let b = game.get_board();
|
|
|
|
render_board(
|
|
BoardColor::Checkerboard('•', ' '),
|
|
&[
|
|
(b.get_mask(Color::White, 0), '●'),
|
|
(b.get_mask(Color::Black, 0), '○'),
|
|
],
|
|
);
|
|
|
|
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();
|
|
}
|
|
}
|
|
|