class Model::Team

Attributes

move_strategy[R]
name[R]
pieces[R]

Public Class Methods

new(args) click to toggle source
# File lib/tic_tac_toe/model/team.rb, line 5
def initialize(args)
  raise ArgumentError, 'empty pieces array' if args[:pieces].empty?

  @name = args[:name]
  @move_strategy = args[:move_strategy]
  @pieces = args[:pieces]

  @pieces.each { |p| p.team = self }
end

Public Instance Methods

available_moves(board) click to toggle source
# File lib/tic_tac_toe/model/team.rb, line 23
def available_moves(board)
  @pieces.each_with_object([]) do |piece, moves|
    moves.concat(piece.moves(board))
  end
end
computer?() click to toggle source
# File lib/tic_tac_toe/model/team.rb, line 19
def computer?
  !@move_strategy.nil?
end
selected_piece() click to toggle source
# File lib/tic_tac_toe/model/team.rb, line 15
def selected_piece
  @pieces[0]
end