Compare commits

..

No commits in common. "master" and "0.4" have entirely different histories.
master ... 0.4

2 changed files with 8 additions and 17 deletions

View File

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

View File

@ -2,10 +2,8 @@ use std::env::args;
use std::fmt; use std::fmt;
use std::io; use std::io;
use std::io::Write; use std::io::Write;
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 {
@ -94,7 +92,11 @@ impl FromStr for Board {
impl Board { impl Board {
fn new(size: usize) -> Board { fn new(size: usize) -> Board {
Board(iter::repeat(State::N).take(size * size).collect()) let mut b = Vec::with_capacity(size * size);
for _ in 0..b.capacity() {
b.push(State::N);
}
Board(b)
} }
fn dimension(&self) -> usize { fn dimension(&self) -> usize {
@ -170,17 +172,6 @@ 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 {
@ -188,7 +179,7 @@ fn main() {
break winner; break winner;
} }
let mut input = String::new(); let mut input = String::new();
for s in players { for s in State::players() {
loop { loop {
let (x, y) = loop { let (x, y) = loop {
print!("{}, your move: (x y) ", s); print!("{}, your move: (x y) ", s);