Sha256: 94e17677f0c84ce0a8e2679dad407fd37e9ec638826cf820be492bfc565d9b98

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

module Model
  class Board
    attr_reader :tile_collection

    def initialize(args)
      @tile_collection = args[:tile_collection]
      @team_collection = args[:team_collection]
      @game_state = args[:game_state]
    end

    def dimensions
      @tile_collection.dimensions
    end

    def set_piece(row, col, piece)
      tile = @tile_collection.find_tile(row, col)

      tile.piece = piece

      tile
    end

    def tile_available?(row, col)
      tile = @tile_collection.find_tile(row, col)

      tile.piece.nil?
    end

    def available_moves
      current_team.available_moves(self)
    end

    def available_tiles
      @tile_collection.available_tiles
    end

    def complete?
      available_tiles.count.zero? || !winner.nil?
    end

    def current_team
      @team_collection.current
    end

    def cycle_teams
      @team_collection.next
    end

    def winner
      @game_state.winner(self)
    end

    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

    def clone
      self.class.new(tile_collection: @tile_collection.clone,
                     team_collection: @team_collection.clone,
                     game_state: @game_state.clone)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sams_tic_tac_toe-0.0.1 lib/tic_tac_toe/model/board.rb