From fd626c1d144d666a4f1e5c630fe9fdd1992d763e Mon Sep 17 00:00:00 2001 From: Pierre-Henri Symoneaux Date: Mon, 19 Feb 2018 22:47:47 +0100 Subject: Updated copyright & fixed a warning --- README.md | 2 +- examples/tictactoe.rs | 29 +++++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 333da94..d247972 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ A formatted and aligned table printer library for [Rust](https://www.rust-lang.org). -*Copyright © 2017 Pierre-Henri Symoneaux* +*Copyright © 2018 Pierre-Henri Symoneaux* > THIS SOFTWARE IS DISTRIBUTED WITHOUT ANY WARRANTY
> Check LICENSE.txt file for more information.
diff --git a/examples/tictactoe.rs b/examples/tictactoe.rs index c8ffdc5..4409155 100644 --- a/examples/tictactoe.rs +++ b/examples/tictactoe.rs @@ -11,9 +11,11 @@ const EMPTY: &'static str = " "; const ROUND: &'static str = "O"; fn main() { - let mut table = table![[EMPTY, EMPTY, EMPTY], - [EMPTY, EMPTY, EMPTY], - [EMPTY, EMPTY, EMPTY]]; + let mut table = table![ + [EMPTY, EMPTY, EMPTY], + [EMPTY, EMPTY, EMPTY], + [EMPTY, EMPTY, EMPTY] + ]; table.printstd(); let stdin = io::stdin(); let mut stdout = io::stdout(); @@ -37,7 +39,7 @@ fn main() { let x = (i - 1) % 3; let y = (i - 1) / 3; { - let mut row = table.get_mut_row(y).unwrap(); + let row = table.get_mut_row(y).unwrap(); if row.get_cell(x).unwrap().to_string() != EMPTY { println!("There's already someone there"); continue; @@ -58,12 +60,10 @@ fn main() { fn get(table: &Table, x: usize, y: usize) -> String { match table.get_row(y) { - Some(r) => { - match r.get_cell(x) { - Some(c) => c.to_string(), - _ => EMPTY.to_string(), - } - } + Some(r) => match r.get_cell(x) { + Some(c) => c.to_string(), + _ => EMPTY.to_string(), + }, _ => EMPTY.to_string(), } } @@ -82,10 +82,11 @@ fn check(table: &Table) -> bool { } let current = get(table, x, y); let c = current.as_str(); - if is(table, c, x + 1, y) && is(table, c, x + 2, y) || - is(table, c, x + 1, y + 1) && is(table, c, x + 2, y + 2) || - x >= 2 && is(table, c, x - 1, y + 1) && is(table, c, x - 2, y + 2) || - is(table, c, x, y + 1) && is(table, c, x, y + 2) { + if is(table, c, x + 1, y) && is(table, c, x + 2, y) + || is(table, c, x + 1, y + 1) && is(table, c, x + 2, y + 2) + || x >= 2 && is(table, c, x - 1, y + 1) && is(table, c, x - 2, y + 2) + || is(table, c, x, y + 1) && is(table, c, x, y + 2) + { println!("Game is over. {} is the winner", current); return true; } -- cgit v1.2.3