class Model::Board

Attributes

tile_collection[R]

Public Class Methods

new(args) click to toggle source
# File lib/tic_tac_toe/model/board.rb, line 5
def initialize(args)
  @tile_collection = args[:tile_collection]
  @team_collection = args[:team_collection]
  @game_state = args[:game_state]
end

Public Instance Methods

available_moves() click to toggle source
# File lib/tic_tac_toe/model/board.rb, line 29
def available_moves
  current_team.available_moves(self)
end
available_tiles() click to toggle source
# File lib/tic_tac_toe/model/board.rb, line 33
def available_tiles
  @tile_collection.available_tiles
end
clone() click to toggle source
# File lib/tic_tac_toe/model/board.rb, line 65
def clone
  self.class.new(tile_collection: @tile_collection.clone,
                 team_collection: @team_collection.clone,
                 game_state: @game_state.clone)
end
complete?() click to toggle source
# File lib/tic_tac_toe/model/board.rb, line 37
def complete?
  available_tiles.count.zero? || !winner.nil?
end
current_team() click to toggle source
# File lib/tic_tac_toe/model/board.rb, line 41
def current_team
  @team_collection.current
end
cycle_teams() click to toggle source
# File lib/tic_tac_toe/model/board.rb, line 45
def cycle_teams
  @team_collection.next
end
dimensions() click to toggle source
# File lib/tic_tac_toe/model/board.rb, line 11
def dimensions
  @tile_collection.dimensions
end
rating(team) click to toggle source
# File lib/tic_tac_toe/model/board.rb, line 53
def rating(team)
  rating = @game_state.rating(self, team)

  if rating.negative?
    rating -= available_tiles.count
  elsif rating.positive?
    rating += available_tiles.count
  end

  rating
end
set_piece(row, col, piece) click to toggle source
# File lib/tic_tac_toe/model/board.rb, line 15
def set_piece(row, col, piece)
  tile = @tile_collection.find_tile(row, col)

  tile.piece = piece

  tile
end
tile_available?(row, col) click to toggle source
# File lib/tic_tac_toe/model/board.rb, line 23
def tile_available?(row, col)
  tile = @tile_collection.find_tile(row, col)

  tile.piece.nil?
end
winner() click to toggle source
# File lib/tic_tac_toe/model/board.rb, line 49
def winner
  @game_state.winner(self)
end