summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Henri Symoneaux <pierre-henri.symoneaux@nokia.com>2018-02-19 22:47:47 +0100
committerPierre-Henri Symoneaux <pierre-henri.symoneaux@nokia.com>2018-02-19 22:47:47 +0100
commitfd626c1d144d666a4f1e5c630fe9fdd1992d763e (patch)
tree6e08ea1272e489397938bb16d28f6fbb8b5b4f11
parent75eff50f57b322cdcdd3a39271666c6df06e68a7 (diff)
Updated copyright & fixed a warning
-rw-r--r--README.md2
-rw-r--r--examples/tictactoe.rs29
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 &copy; 2017 Pierre-Henri Symoneaux*
+*Copyright &copy; 2018 Pierre-Henri Symoneaux*
> THIS SOFTWARE IS DISTRIBUTED WITHOUT ANY WARRANTY <br>
> Check LICENSE.txt file for more information. <br>
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;
}