pick whoever makes the first move at random
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
shimun 2019-11-16 18:18:19 +01:00
parent 6af10ba53d
commit 419d3d7dcc
Signed by: shimun
GPG Key ID: E81D8382DC2F971B

View File

@ -5,6 +5,7 @@ use std::io::Write;
use std::iter; use std::iter;
use std::ops::{Index, IndexMut}; use std::ops::{Index, IndexMut};
use std::str::FromStr; use std::str::FromStr;
use std::time::SystemTime;
#[derive(Copy, Clone, Debug, PartialEq)] #[derive(Copy, Clone, Debug, PartialEq)]
enum State { enum State {
@ -169,6 +170,17 @@ fn main() {
let dim = board.dimension(); let dim = board.dimension();
(board, criteria.unwrap_or(dim)) (board, criteria.unwrap_or(dim))
}; };
let players_rev = State::players().iter().rev().cloned().collect::<Vec<_>>();
let players: &[State] = if SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.map(|d| d.as_millis() % 2 == 0)
.unwrap_or(false)
{
State::players()
} else {
&players_rev[..]
};
let stdin = std::io::stdin(); let stdin = std::io::stdin();
println!("{}", &board); println!("{}", &board);
let winner = loop { let winner = loop {
@ -176,7 +188,7 @@ fn main() {
break winner; break winner;
} }
let mut input = String::new(); let mut input = String::new();
for s in State::players() { for s in players {
loop { loop {
let (x, y) = loop { let (x, y) = loop {
print!("{}, your move: (x y) ", s); print!("{}, your move: (x y) ", s);