lib/poll_game.rb
def calculate_matrix
    raise JugaMe::NoTieBreakerInPollException if tie_breaker.nil?
    raise JugaMe::IncompletePollPreferencesException if players_preferences.size != number_of_players
    combinations = moves
    (number_of_players-1).times do
      combinations = combinations.cart_product(moves)
    end
    combinations.each do |combination|
      modes = combination.modes
      winner = (modes.size == 1) ? modes.first : combination[tie_breaker-1]
      payoffs = []
      number_of_players.times do |i|
        payoffs << (players_preferences[i+1][winner] || 0)
      end
      set_payoff(combination,payoffs)
    end
  end
# Builds the payoff matrix, based on preferences
Builds the payoff matrix, based on preferences
Builds the payoff matrix based on preferences
def calculate_matrix
    raise JugaMe::NoTieBreakerInPollException if tie_breaker.nil?
    raise JugaMe::IncompletePollPreferencesException if players_preferences.size != number_of_players
    combinations = moves
    (number_of_players-1).times do
      combinations = combinations.cart_product(moves)
    end
    combinations.each do |combination|
      modes = combination.modes
      winner = (modes.size == 1) ? modes.first : combination[tie_breaker-1]
      payoffs = []
      number_of_players.times do |i|
        payoffs << (players_preferences[i+1][winner] || 0)
      end
      set_payoff(combination,payoffs)
    end
  end
def calculate_matrix raise JugaMe :: NoTieBreakerInPollException if tie_breaker . nil? raise JugaMe :: IncompletePollPreferencesException if players_preferences . size != number_of_players combinations = moves ( number_of_players - 1 ) . times do combinations = combinations . cart_product ( moves ) end combinations . each do | combination | modes = combination . modes winner = ( modes . size == 1 ) ? modes . first : combination [ tie_breaker - 1 ] payoffs = [ ] number_of_players . times do | i | payoffs << ( players_preferences [ i + 1 ] [ winner ] || 0 ) end set_payoff ( combination , payoffs ) end end
Builds the payoff matrix, based on preferences
Builds the payoff matrix based on preferences