class Presenter::Board

Public Class Methods

new(board, game_tree_klass) click to toggle source
# File lib/tic_tac_toe/presenter/board.rb, line 3
def initialize(board, game_tree_klass)
  @board = board
  @game_tree_klass = game_tree_klass
end

Public Instance Methods

computer_select_move(team) click to toggle source
# File lib/tic_tac_toe/presenter/board.rb, line 14
def computer_select_move(team)
  move_strategy = team.move_strategy
  game_tree = @game_tree_klass.generate_game_tree(@board)
  move = move_strategy.select_move(game_tree)
  tile = move.tile

  select_move(tile.row, tile.col, team)
end
continue?() click to toggle source
# File lib/tic_tac_toe/presenter/board.rb, line 43
def continue?
  !(draw? || winner?)
end
current_team() click to toggle source
# File lib/tic_tac_toe/presenter/board.rb, line 35
def current_team
  @board.current_team
end
draw?() click to toggle source
# File lib/tic_tac_toe/presenter/board.rb, line 47
def draw?
  @board.complete? && !winner?
end
invalid_tile_selection?(row, col) click to toggle source
# File lib/tic_tac_toe/presenter/board.rb, line 23
def invalid_tile_selection?(row, col)
  row > @board.dimensions || col > @board.dimensions || !@board.tile_available?(row, col)
end
select_move(row, col, team) click to toggle source
# File lib/tic_tac_toe/presenter/board.rb, line 8
def select_move(row, col, team)
  @board.set_piece(row, col, team.selected_piece)

  @board.cycle_teams
end
tile_collection() click to toggle source
# File lib/tic_tac_toe/presenter/board.rb, line 27
def tile_collection
  @board.tile_collection
end
winner?() click to toggle source
# File lib/tic_tac_toe/presenter/board.rb, line 39
def winner?
  !winning_team.nil?
end
winning_team() click to toggle source
# File lib/tic_tac_toe/presenter/board.rb, line 31
def winning_team
  @board.winner
end