use podch::{Game};
fn input2<T: std::str::FromStr>() -> Option<(T, T)> {
let mut s = String::new();
std::io::stdin().read_line(&mut s).ok()?;
let mut list = s.trim().split(' ').map(|x| x.parse());
let res = Some((list.next()?.ok()?, list.next()?.ok()?));
if list.next().is_none() { res } else { None }
}
fn main() {
use std::io::Write;
let mut size = (0usize, 0usize);
while size.0 == 0 || size.1 == 0 {
print!("Board height and width (e.g. 2 3): ");
std::io::stdout().flush().unwrap();
match input2() {
Some(p) => size = p,
None => println!("Size does not match format"),
}
}
let mut game = podch::SimpleGame::<podch::BinBoard>::new(size.0, size.1);
while !game.is_over() {
println!("{}", podch::BoardDisplay::from(game.board()));
loop {
print!("Move of {:?} (e.g. 0 1): ", game.current_player());
std::io::stdout().flush().unwrap();
match input2() {
None => { println!("Move does not match format") }
Some((x, y)) => {
match game.make_move(x, y) {
Ok(_) => { break; }
Err(e) => { println!("{}", e); }
}
}
}
}
}
println!("{}", podch::BoardDisplay::from(game.board()));
println!("Game over, {:?} wins!", game.winner().unwrap());
}