Skip to content

Instantly share code, notes, and snippets.

@sferik
Last active December 15, 2015 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sferik/5257881 to your computer and use it in GitHub Desktop.
Save sferik/5257881 to your computer and use it in GitHub Desktop.

WDI Homework - March 27, 2013

Tic-Tac-Toe

Create a two-player tic-tac-toe game in Ruby.

Requirements
  • Must define at least two classes
  • Must define at least one exception class
  • Must use at least one Array
  • Must use at least one Hash
  • Must announce the winner when one player wins (three Xs or Os in a row, up, down, or diagonal)
  • Must announce that the game ends in a tie if there are no available moves
Suggestions

Draw a game board using pipes (|) and dashes (-) that looks like this:

 1 | 2 | 3 
-----------
 4 | 5 | 6 
-----------
 7 | 8 | 9

Then prompt the player to use enter a number.

For example, if the first player enters 5, replace the 5 with an X. If the second player enters 9, replace the 9 with an O. If those are the first two moves, the board should look like this:

 1 | 2 | 3 
-----------
 4 | X | 6 
-----------
 7 | 8 | O
Bonus

If you finish early, try creating a one-player tic-tac-toe game that you can play against the computer. Try to make your artificial intelligence unbeatable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment