improve manual agent code
This commit is contained in:
parent
f63d8f4415
commit
7c74d45618
21
src/agent.rs
21
src/agent.rs
@ -16,22 +16,23 @@ 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 {
|
||||
"Manual Agent"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user