pick whoever makes the first move at random
This commit is contained in:
parent
6af10ba53d
commit
419d3d7dcc
14
src/main.rs
14
src/main.rs
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user