Created
August 2, 2012 03:46
-
-
Save bigwheel/3233153 to your computer and use it in GitHub Desktop.
ランダムに2チームへ分けるスクリプト 超人パワー編
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
srand(Time.local(2012, 8, 2).to_i) | |
class Member | |
attr_reader :name, :power | |
def initialize(name) | |
@name = name | |
@power = rand | |
end | |
end | |
members = ARGF.map do |name| | |
Member.new(name.chomp) | |
end | |
def members.choose! | |
delete_at(rand(count)) | |
end | |
a_team = [] | |
b_team = [] | |
teams = [a_team, b_team] | |
while members.count != 0 | |
if members.count == 1 | |
teams[rand(2)] << members.choose! | |
break | |
end | |
red = members.choose! | |
blue = members.choose! | |
if red.power > blue.power | |
a_team << red | |
b_team << blue | |
else | |
a_team << blue | |
b_team << red | |
end | |
end | |
puts "A: #{a_team.map {|member| member.name }.join(' ')}" | |
puts "B: #{b_team.map {|member| member.name }.join(' ')}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment