Skip to content

Instantly share code, notes, and snippets.

@pumpkincouture
Created September 24, 2014 16:09
Show Gist options
  • Save pumpkincouture/b4473a5ed9c74059b887 to your computer and use it in GitHub Desktop.
Save pumpkincouture/b4473a5ed9c74059b887 to your computer and use it in GitHub Desktop.
class Board
include TTTConstants
attr_reader :cells
def initialize(user_interface, board_choice)
@ui = user_interface
@board_choice = board_choice
@cells = Array.new(board_choice * board_choice, [])
end
def invalid_key(answer)
answer.to_i == 0 || cells[answer.to_i - 1] == X_PIECE || cells[answer.to_i - 1] == O_PIECE
end
def valid_move(answer)
cells[answer.to_i - 1] = O_PIECE
@ui.human_choice(answer)
@ui.display_board(cells)
end
def computer_move(answer)
cells[answer] = X_PIECE
@ui.computer_choice(answer)
@ui.display_board(cells)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment