Compare commits

...

2 Commits
cvc ... master

Author SHA1 Message Date
d9740a28a4
build musl images
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2020-06-06 14:39:18 +02:00
419d3d7dcc
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
2019-11-16 18:18:19 +01:00
2 changed files with 15 additions and 3 deletions

View File

@ -3,11 +3,11 @@ name: default
steps: steps:
- name: test - name: test
image: rust:1.38.0 image: rust:1.38.0-alpine
commands: commands:
- cargo test - cargo test
- name: build_relase - name: build_relase
image: rust:1.38.0 image: rust:1.38.0-alpine
commands: commands:
- cargo install --path . --root . -f - cargo install --path . --root . -f
- strip bin/tictactoe - strip bin/tictactoe

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);