Add tiebreak analyzer
This commit is contained in:
parent
08fe4163bc
commit
d429c16a9e
1 changed files with 17 additions and 0 deletions
17
mj.rb
17
mj.rb
|
|
@ -65,6 +65,23 @@ class MajorityJudgment
|
|||
return MajorityJudgment.new(counta) <=> MajorityJudgment.new(countb)
|
||||
end
|
||||
|
||||
def break_tie(other)
|
||||
rounds = [ ]
|
||||
s = MajorityJudgment.new(self.count.dup)
|
||||
o = MajorityJudgment.new(other.count.dup)
|
||||
rounds << [s, o]
|
||||
while s.mj == o.mj and not s.mj == 0
|
||||
new_s_count = s.count.dup
|
||||
new_o_count = o.count.dup
|
||||
new_s_count[s.mj] = new_s_count[s.mj] - 1
|
||||
new_o_count[o.mj] = new_o_count[o.mj] - 1
|
||||
s = MajorityJudgment.new(new_s_count)
|
||||
o = MajorityJudgment.new(new_o_count)
|
||||
rounds << [s, o]
|
||||
end
|
||||
return rounds
|
||||
end
|
||||
|
||||
def to_s
|
||||
puts "#{@count}: {M=>#{self.mj}, P=>#{self.proponents}, O=>#{self.opponents}}"
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue