Class: Presenter::Board
- Inherits:
-
Object
- Object
- Presenter::Board
- Defined in:
- lib/tic_tac_toe/presenter/board.rb
Instance Method Summary collapse
- #computer_select_move(team) ⇒ Object
- #continue? ⇒ Boolean
- #current_team ⇒ Object
- #draw? ⇒ Boolean
-
#initialize(board, game_tree_klass) ⇒ Board
constructor
A new instance of Board.
- #invalid_tile_selection?(row, col) ⇒ Boolean
- #select_move(row, col, team) ⇒ Object
- #tile_collection ⇒ Object
- #winner? ⇒ Boolean
- #winning_team ⇒ Object
Constructor Details
#initialize(board, game_tree_klass) ⇒ Board
Returns a new instance of Board.
3 4 5 6 |
# 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 |
Instance Method Details
#computer_select_move(team) ⇒ Object
14 15 16 17 18 19 20 21 |
# 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? ⇒ Boolean
43 44 45 |
# File 'lib/tic_tac_toe/presenter/board.rb', line 43 def continue? !(draw? || winner?) end |
#current_team ⇒ Object
35 36 37 |
# File 'lib/tic_tac_toe/presenter/board.rb', line 35 def current_team @board.current_team end |
#draw? ⇒ Boolean
47 48 49 |
# File 'lib/tic_tac_toe/presenter/board.rb', line 47 def draw? @board.complete? && !winner? end |
#invalid_tile_selection?(row, col) ⇒ Boolean
23 24 25 |
# 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) ⇒ Object
8 9 10 11 12 |
# 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 ⇒ Object
27 28 29 |
# File 'lib/tic_tac_toe/presenter/board.rb', line 27 def tile_collection @board.tile_collection end |
#winner? ⇒ Boolean
39 40 41 |
# File 'lib/tic_tac_toe/presenter/board.rb', line 39 def winner? !winning_team.nil? end |
#winning_team ⇒ Object
31 32 33 |
# File 'lib/tic_tac_toe/presenter/board.rb', line 31 def winning_team @board.winner end |