Skip to content

Instantly share code, notes, and snippets.

@jedahan
Created December 24, 2010 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jedahan/754115 to your computer and use it in GitHub Desktop.
Save jedahan/754115 to your computer and use it in GitHub Desktop.
# Copyright 2010 Jonathan Dahan <jedahan@gmail.com>
# Distributed under the terms of the ISC license ( http://en.wikipedia.org/wiki/ISC_license )
require 'csv'
require 'pp'
# Dumb team class
class Team
attr_accessor :players, :score
def initialize( players = [], score = 0.00 )
@players = players
@score = score
end
end
# Read in k/d statistics, sort by score
scores = Hash.new
CSV.open('stats.txt').each do |row|
scores[row[0].to_f] = row[1].chop
end
scores = Hash[*scores.sort.reverse.flatten]
# As per PUGs / Captains games, picks are 1 2 2 1 2 1 2 ...
teams = Array.new
# Seed first three players
teams << Team.new([scores.values[0]], scores.keys[0])
teams << Team.new(scores.values[1..2], scores.keys[1] + scores.keys[2])
3.times do scores.shift end
# Alternate remaining players
scores.each_with_index do |k,i|
teams[i%2].score = teams[i%2].score + k[0]
teams[i%2].players << k[1]
end
# Convert raw score to k/d
teams[0].score = teams[0].score / teams[0].players.size
teams[1].score = teams[1].score / teams[1].players.size
pp teams
0.43,<BAD>Kuuki
3.15,<RAD>Keller
2.30,SnOwY
2.21,neverdie
2.51,pyro
0.55,<BAD>SAINT
2.00,DUO
1.61,abse
0.76,foolish
1.83,NSAKENMAN
0.50,tommorow
0.92,whitecloud
0.83,adams
0.38,hamstergorge
0.31,cooltwig
0.65,tototem
0.82,rockypatel
0.77,imoscar
2.73,whereareyouchristmas
1.27,shooter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment