From: Ian Jackson Date: Mon, 1 Aug 2016 16:09:46 +0000 (+0100) Subject: stv: fix ties X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=appendix-a6.git;a=commitdiff_plain;h=0f260f3d622f00becab215877dba0e2e260603c5;hp=2c0d1b163477f5472ca5f2495f5f436d5205889f stv: fix ties --- 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->(); }