Git Product home page Git Product logo

tiktaktoe's Introduction

tiktaktoe

Just learning Rust writing bad code.

tiktaktoe's People

Contributors

ktzee avatar

Watchers

 avatar

tiktaktoe's Issues

General comments

// TODO: Maybe it should be an Option<XorO>

I think having XorO::Empty is fine and is less noisy than Option<XorO>, but in the end it's up to personal preference.

// TODO: Very ugly. There must be a better way to have default values

If you implement the trait Default for XorO docs by returning XorO::Empty, then you can derive Default on GameState by doing:

#[derive(Default)]
struct GameState {
    board: [XorO; 9],
}

And then you actually don't need the function GameState::new() but can call GameState::default() instead to create a new instance of GameState.

The functions print_cell and show_board can be substituted with a std::fmt::Display implementation. The print_cell could then look something like this (not tested):

impl std::fmt::Display for XorO {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            XorO::X => write!(f, "X"),
            XorO::O => write!(f, "O"),
            XorO::Empty => write!(f, "."),
        }
    }
}

You can then print out XorO by simply doing println!("{}", XorO::X)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.