- my $nextcand = $maybe_elect[$nelect];
- my $nextc = $cands{$nextcand};
-
- # We certainly only consider those who meet quota
- last unless $nextc->{Total} >= $quota;
- last unless $nextc->{Total} > $quota && $nextel;
- # ... if equal we can do them one by one, since order
- # does not matter (SLGEO 49 talks about `two or more ... exceeds')
-
- last if $nelect &&
- (total_history_cmp $maybe_elect[0], $nextcand) > 0;
- # ... only interested in those who compare equal
- # according ot the history (SLGEO 49(2)); NB our history
- # includes the current round.
-
- $nelect++;
+ my $nextc = $maybe[$nequal];
+ last unless $nextc;
+
+ # Only interested in those who compare equal according to the
+ # history (SLGEO 49(2)); NB our history includes the current
+ # round.
+
+ last if $signum*($a = $maybe[0], $b = $nextc, total_history_cmp) > 0;
+ $nequal++;
+ }
+
+ if ($nequal > 1 && !$wanttiebreak->($maybe[0]{Total})) {
+ # ... if equal for election we can do them one by one, since
+ # order does not matter (SLGEO 49 talks about `two or more
+ # ... exceeds').
+ $nequal = 1;
+ }
+
+ my $selectcand;
+ if ($nequal > 1) {
+ my @all = map { $_->{Cand} } @maybe[0 .. $nequal-1];
+ my $tiekey = $signum > 0 ? 'Win' : 'Lose';
+ $selectcand = $tie{"@all"}{$tiekey};
+ die "need tie break, want $tiekey from @all"
+ unless defined $selectcand;
+ prf "$what %s due to tie break amongst %s\n",
+ $selectcand, "@all";
+ } else {
+ $selectcand = $maybe[0]{Cand};
+ prf "$what %s\n", $selectcand;