#TicTacToe

4 messages · Page 1 of 1 (latest)

dusky haven
#

Hey, I'm a Node/TS dev trying to learn Rust. I read the book and watched some tutorial and started building projects for the first time this week. I built a TicTacToe CLI game to learn the basics here: https://github.com/JuiceDrinker/tictactoe and would love to get some feedback on how to make this more idiomatic Rust code and improve code style/error handling etc.

Thank you!

GitHub

Tic-Tac-Toe implemented in Rust to learn the language - GitHub - JuiceDrinker/tictactoe: Tic-Tac-Toe implemented in Rust to learn the language

glad locust
#

you could just use a standard Option<Player> enum instead of TileOccupancy. also, since you only repeat the game loop while result is none, print the result after the while loop instead of checking for a result every loop.
Something like:

while game.result.is_none() {
  // make moves
}
game.result.and_then(|result| println!("{result}"))

using Game::make_move(self, args) is valid, but why not just use game.make_move(args)?

tawdry tiger
#

@dusky haven It's a really clean code I would say congrats !
Just some comments I have :

  • make_move doesn't need to return &mut Self (you don't event use its result)
  • It's not really idiomatic to do -> () for function return (used by set_tile) you can just omit it
  • Maybe is_game_drawn should only return a bool as you only use it via self.is_game_drawn().is_some()
  • You should not call something Result as it already something in the std
dusky haven