improve manual agent code

This commit is contained in:
Simon Gardling 2025-02-04 15:49:06 -05:00
parent f63d8f4415
commit 7c74d45618
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D

View File

@ -16,21 +16,22 @@ impl Agent for ManualAgent {
fn next_move(&mut self, _: &Board) -> Option<(usize, usize)> {
let stdin = io::stdin();
let mut input = String::new();
let mut got: Option<(usize, usize)> = None;
while got.is_none() {
loop {
input.clear();
stdin.lock().read_line(&mut input).ok()?;
let numbers = input
let got = input
.split_whitespace()
.map(|i| i.parse::<usize>().ok())
.collect::<Option<Vec<usize>>>();
if let Some(numbers) = numbers {
if numbers.len() == 2 {
got = Some((numbers[0], numbers[1]));
}
.map(str::parse)
.map(Result::ok)
.collect::<Option<Vec<_>>>()
.and_then(|x| -> Option<[usize; 2]> { x.try_into().ok() })
.map(|x| (x[0], x[1]));
if got.is_some() {
return got;
}
}
got
}
fn name(&self) -> &'static str {