improve manual agent code
This commit is contained in:
parent
f63d8f4415
commit
7c74d45618
21
src/agent.rs
21
src/agent.rs
@ -16,21 +16,22 @@ impl Agent for ManualAgent {
|
|||||||
fn next_move(&mut self, _: &Board) -> Option<(usize, usize)> {
|
fn next_move(&mut self, _: &Board) -> Option<(usize, usize)> {
|
||||||
let stdin = io::stdin();
|
let stdin = io::stdin();
|
||||||
let mut input = String::new();
|
let mut input = String::new();
|
||||||
let mut got: Option<(usize, usize)> = None;
|
loop {
|
||||||
while got.is_none() {
|
|
||||||
input.clear();
|
input.clear();
|
||||||
stdin.lock().read_line(&mut input).ok()?;
|
stdin.lock().read_line(&mut input).ok()?;
|
||||||
let numbers = input
|
|
||||||
|
let got = input
|
||||||
.split_whitespace()
|
.split_whitespace()
|
||||||
.map(|i| i.parse::<usize>().ok())
|
.map(str::parse)
|
||||||
.collect::<Option<Vec<usize>>>();
|
.map(Result::ok)
|
||||||
if let Some(numbers) = numbers {
|
.collect::<Option<Vec<_>>>()
|
||||||
if numbers.len() == 2 {
|
.and_then(|x| -> Option<[usize; 2]> { x.try_into().ok() })
|
||||||
got = Some((numbers[0], numbers[1]));
|
.map(|x| (x[0], x[1]));
|
||||||
}
|
|
||||||
|
if got.is_some() {
|
||||||
|
return got;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
got
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn name(&self) -> &'static str {
|
fn name(&self) -> &'static str {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user