class Game
Attributes
board[R]
players[R]
Public Class Methods
new(board, players)
click to toggle source
# File lib/game.rb, line 3 def initialize(board, players) @board = board @players = players end
Public Instance Methods
play()
click to toggle source
# File lib/game.rb, line 8 def play while game_in_progress? current_player = players[player_symbol] @board = board.make_move(current_player.choose_move(board), player_symbol) end board end
play_specific(move)
click to toggle source
# File lib/game.rb, line 16 def play_specific(move) @board = board.make_move(move, player_symbol) play end
Private Instance Methods
game_in_progress?()
click to toggle source
# File lib/game.rb, line 31 def game_in_progress? players[player_symbol].ready? && board.free_spaces? && !board.winning_combination? end
player_symbol()
click to toggle source
# File lib/game.rb, line 25 def player_symbol number_of_x = board.grid_for_display.flatten.count(PlayerSymbols::X) number_of_o = board.grid_for_display.flatten.count(PlayerSymbols::O) next_players_symbol = number_of_x > number_of_o ? PlayerSymbols::O : PlayerSymbols::X end