Sha256: 043afd44e23fe7675fba3c62e4490faa7f0c2e792b1f23c6e51779bbfa19fa93

Contents?: true

Size: 623 Bytes

Versions: 5

Compression:

Stored size: 623 Bytes

Contents

module FootballManager
  class TeamPicker
    def self.calculate_fair_teams(players)
      team_a, team_b  = FootballManager::Team.new, FootballManager::Team.new

      players_in_descending_order(players).each do |player|
        if team_a.empty? || team_a.points <= team_b.points
          team_a << player
        else
          team_b << player
        end
      end

      return [team_a, team_b]
    end

    private
      def self.players_in_descending_order(players)
        5.downto(1).collect do |i|
          players.select { |player| player.skill == i }.sort_by {rand}
        end.flatten!
      end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
football-manager-0.1.8 lib/football-manager/team_picker.rb
football-manager-0.1.7 lib/football-manager/team_picker.rb
football-manager-0.1.6 lib/football-manager/team_picker.rb
football-manager-0.1.5 lib/football-manager/team_picker.rb
football-manager-0.1.4 lib/football-manager/team_picker.rb