You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Michele Sessa 067b3d6f42 docs(copy, tic_tac_toe): Improve code example and console output 2 years ago
..
README.md docs(copy, tic_tac_toe): Improve code example and console output 2 years ago

README.md

tic_tac_toe

Instructions

You must create some functions for a tic-tac-toe checker.

Create a function named tic_tac_toe, which receives a tic-tac-toe table. It should return the appropriate string: "player O won", "player X won" or "Tie".

Also create the following functions, which each accept a player and a table. These functions should return true if the player has completed one of the diagonals, rows or columns:

Expected functions

pub fn tic_tac_toe(table: Vec<Vec<&str>>) -> String {
}

pub fn diagonals(player: &str, table: &Vec<Vec<&str>>) -> bool {
}

pub fn horizontal(player: &str, table: &Vec<Vec<&str>>) -> bool {
}

pub fn vertical(player: &str, table: &Vec<Vec<&str>>) -> bool {
}

Usage

Here is a program to test your tic_tac_toe. You'll need to test the other functions yourself. But they'll probably be useful for implementing your tic_tac_toe checker.

use tic_tac_toe::*;

fn main() {
    println!(
        "{:?}",
        tic_tac_toe(vec![
            vec!["O", "X", "O"],
            vec!["O", "O", "X"],
            vec!["X", "#", "X"]
        ])
    );

    println!(
        "{:?}",
        tic_tac_toe(vec![
            vec!["X", "O", "O"],
            vec!["X", "O", "O"],
            vec!["#", "O", "X"]
        ])
    );

    let dig = vec![
            vec!["O", "O", "X"],
            vec!["O", "X", "O"],
            vec!["X", "#", "X"]
        ];

    println!("{:?}",tic_tac_toe(dig));
}

And its output

$ cargo run
"Tie"
"player O won"
"player X won"
$

Notions