Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
d9740a28a4 | |||
419d3d7dcc |
@ -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
|
||||||
|
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