Skip to content

Instantly share code, notes, and snippets.

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 angelxmoreno/dd779ecc060463242739f7c35eb91a63 to your computer and use it in GitHub Desktop.
Save angelxmoreno/dd779ecc060463242739f7c35eb91a63 to your computer and use it in GitHub Desktop.
By adding this gem to our project we will be able to use methods of the Tic_Tac_Toe class (these methods are listed below)
.new - makes a new Tic Tac Toe object
.initBoard(board) - makes a cell block from the dimensions of board object
.winningRows(board) - checks the board object to see if a row contains 3 of the same symbol
.winningCols(board) - checks the board object to see if a col contains 3 of the same symbol
.winningDiagonals(board) - checks the board object to see if a diagonal contains 3 of the same symbol
.displayBoard(board) - displays board object in the terminal
.fullBoard(board) - checks to see if the board object is full
.turnPlayed(board,player,player_choice) - checks to see if a valid move was played by checking the board object, player symbol and location that the player picked
Note: board is simply an 2-D array object
Here is an example of how we make a new Tic Tac Toe object and can call the initBoard method
game = Tic_Tac_Toe.new
board = Array.new(3) {Array.new(3)}
game.initBoard(board)
Student Practice:
In order to use a gem, we need to install it first. Tell the student to use the terminal to type:
gem install tic_tac_toe_cn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment