This commit is contained in:
2025-02-12 21:24:35 -05:00
parent 2c241948f7
commit 351953450a
6 changed files with 36 additions and 78 deletions

View File

@@ -14,7 +14,7 @@ pub struct ManualAgent {
}
impl Agent for ManualAgent {
fn next_move(&mut self, _: &Board) -> Option<(usize, usize)> {
fn next_move(&mut self, board: &Board) -> Option<(usize, usize)> {
let stdin = io::stdin();
let mut input = String::new();
println!("Your turn! ('Skip' to skip)");
@@ -34,8 +34,12 @@ impl Agent for ManualAgent {
.and_then(|x| -> Option<[usize; 2]> { x.try_into().ok() })
.map(|x| (x[0], x[1]));
if got.is_some() {
return got;
if let Some(got) = got {
if board.possible_moves(self.color).all(|x| x != got) {
println!("Invalid move! Try again.");
continue;
}
return Some(got);
}
}
}