From 0f260f3d622f00becab215877dba0e2e260603c5 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 1 Aug 2016 17:09:46 +0100 Subject: [PATCH] stv: fix ties --- stv | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/stv b/stv index ba89fce..dae5563 100755 --- a/stv +++ b/stv @@ -203,19 +203,29 @@ for (;;) { my $s = $sorted[0]; my $topvoters = $s->{Total}; my $surplus = $topvoters - $quota; - last unless $surplus > 0; + last unless $surplus >= 0; - printf "%7s %10s ***************\n", 'ELECTED', $s->{Cand}; - push @elected, $s->{Cand}; + my @elect = equalpiles 'elect?', @sorted; - foreach my $vote (@{ $s->{Votes} }) { - votelog $vote, "elected $s->{Cand}"; + if (@elect > $placesremain) { + # oh my god + @elect = historically_prefer +1, @elect; + printf "%7s %10s\n", 'tie!', $elect[0]{Cand}; } - $s->{Surplus} = $surplus; - push @newsurpluses, $s; - delete $sorted{ $s->{Cand} }; - delete $continuing{ $s->{Cand} }; + foreach $s (@elect) { + printf "%7s %10s ***************\n", 'ELECTED', $s->{Cand}; + push @elected, $s->{Cand}; + + foreach my $vote (@{ $s->{Votes} }) { + votelog $vote, "elected $s->{Cand}"; + } + + $s->{Surplus} = $surplus; + push @newsurpluses, $s; + delete $sorted{ $s->{Cand} }; + delete $continuing{ $s->{Cand} }; + } $things_update->(); } -- 2.30.2