chiark / gitweb /
stv: fix ties
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 1 Aug 2016 16:09:46 +0000 (17:09 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 1 Aug 2016 16:09:46 +0000 (17:09 +0100)
stv

diff --git a/stv b/stv
index ba89fce1bfd4dcd359d86f80fe0555820db25cd8..dae5563dd79bfd6a46474a7c3e08a61d0b385d51 100755 (executable)
--- 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->();
     }