| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # Last Edit: 2016 Jan 01, 13:39:16 | ||||||||||||||||||||||||||||
| 4 | # $Id: /swiss/trunk/script_files/pair 1532 2007-10-27T03:38:38.615327Z greg $ | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | =head1 NAME | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | pair - Pair players for the next round of a swiss tournament | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =cut | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use YAML qw/LoadFile DumpFile Bless/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Games::Tournament::Swiss::Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | my $swiss = Games::Tournament::Swiss::Config->new; | |||||||||||||||||||||||||||
| 20 | 1 | my $league = LoadFile "../league.yaml"; | |||||||||||||||||||||||||||
| 21 | 1 | ▶ | die 'round.yaml already exists' if -e 'round.yaml'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | my $roles = $league->{roles} || [$swiss->roles]; | ||||||||||||||||||||||||||
|
Condition50%1/2
$league->{'roles'} || [$swiss->roles]
MC/DC0%0/1
$league->{'roles'} || [$swiss->roles]
$league->{'roles'}
Truth table50%1/2
A
A= $league->{'roles'}
| |||||||||||||||||||||||||||||
| 24 | my $scores = $league->{scores} || | ||||||||||||||||||||||||||||
| 25 | 1 | ▶ | { win => 1, loss => 0, draw => 0.5, absent => 0, bye => 1 }; | ||||||||||||||||||||||||||
|
Condition50%1/2
$league->{'scores'} || {'win', 1, 'loss', 0, 'draw', 0.5, 'absent', 0, 'bye', 1}
MC/DC0%0/1
$league->{'scores'} || {'win', 1, 'loss', 0, 'draw', 0.5, 'absent', 0, 'bye', 1}
$league->{'scores'}
Truth table50%1/2
A
A= $league->{'scores'}
| |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | my $firstround = $league->{firstround} || $swiss->firstround; | ||||||||||||||||||||||||||
|
Condition33%1/3
$league->{'firstround'} || $swiss->firstround
MC/DC0%0/2
$league->{'firstround'} || $swiss->firstround
$league->{'firstround'}
$swiss->firstround
Truth table33%1/3
A || B
A= $league->{'firstround'}B= $swiss->firstround
| |||||||||||||||||||||||||||||
| 27 | 1 | ▶ | my $algorithm = $league->{algorithm} || 'Games::Tournament::Swiss::Procedure::FIDE'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$league->{'algorithm'} || 'Games::Tournament::Swiss::Procedure::FIDE'
MC/DC0%0/1
$league->{'algorithm'} || 'Games::Tournament::Swiss::Procedure::FIDE'
$league->{'algorithm'}
Truth table50%1/2
A
A= $league->{'algorithm'}
| |||||||||||||||||||||||||||||
| 28 | my $abbrev = $league->{abbreviation} || | ||||||||||||||||||||||||||||
| 29 | 1 | ▶ | { W => 'White', B => 'Black', 1 => 'Win', 0 => 'Loss', | ||||||||||||||||||||||||||
|
Condition50%1/2
$league->{'abbreviation'} || {'W', 'White', 'B', 'Black', 1, 'Win', 0, 'Loss', 0.5, 'Draw', '=', 'Draw'}
MC/DC0%0/1
$league->{'abbreviation'} || {'W', 'White', 'B', 'Black', 1, 'Win', 0, 'Loss', 0.5, 'Draw', '=', 'Draw'}
$league->{'abbreviation'}
Truth table50%1/2
A
A= $league->{'abbreviation'}
| |||||||||||||||||||||||||||||
| 30 | 0.5 => 'Draw', '=' => 'Draw' }; | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 1 | $swiss->frisk($scores, $roles, $firstround, $algorithm, $abbrev); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 1 | $Games::Tournament::Swiss::Config::firstround = $firstround; | |||||||||||||||||||||||||||
| 35 | 1 | %Games::Tournament::Swiss::Config::scores = %$scores; | |||||||||||||||||||||||||||
| 36 | 1 | @Games::Tournament::Swiss::Config::roles = @$roles; | |||||||||||||||||||||||||||
| 37 | 1 | $Games::Tournament::Swiss::Config::algorithm = $algorithm; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 1 | require Games::Tournament::Swiss; | |||||||||||||||||||||||||||
| 40 | 1 | require Games::Tournament::Contestant::Swiss; | |||||||||||||||||||||||||||
| 41 | 1 | require Games::Tournament::Card; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 1 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 1 | ▶ | use File::Basename; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | 1 | my $directory = File::Spec->rel2abs( '.' ); | |||||||||||||||||||||||||||
| 46 | 1 | my $next = basename( $directory ); | |||||||||||||||||||||||||||
| 47 | 1 | ▶ | die "round $next directory name not a round number" unless | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | $next =~ m/^\d+$/; | ||||||||||||||||||||||||||||
| 49 | 1 | my $previous = $next-1; | |||||||||||||||||||||||||||
| 50 | 1 | my $round = $previous; | |||||||||||||||||||||||||||
| 51 | 1 | my $n = 0; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 1 | my $oldlist; | |||||||||||||||||||||||||||
| 54 | my $lineup; | ||||||||||||||||||||||||||||
| 55 | 0 | ▶ | my @absentees = @{ $league->{absent} } if $league->{absent}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 1 | for my $member ( @{ $league->{member} } ) { | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | next if grep {$member->{name} eq $_} @absentees; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 4 | push @$lineup, Games::Tournament::Contestant::Swiss->new( %$member ); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 1 | my $tourney = Games::Tournament::Swiss->new( | |||||||||||||||||||||||||||
| 62 | round => $round, | ||||||||||||||||||||||||||||
| 63 | entrants => $lineup ); | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 1 | my $lateEntries = $league->{late}; | |||||||||||||||||||||||||||
| 66 | 1 | for my $late ( @$lateEntries ) { | |||||||||||||||||||||||||||
| 67 | 0 | my $player = Games::Tournament::Contestant::Swiss->new( %$late ); | |||||||||||||||||||||||||||
| 68 | 0 | $tourney->enter($player); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | 1 | $tourney->assignPairingNumbers; | |||||||||||||||||||||||||||
| 71 | 1 | $tourney->initializePreferences; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 1 | my @ids = map { $_->{pairingNumber} } @$lineup; | |||||||||||||||||||||||||||
| 74 | 1 | my $pairingtable; | |||||||||||||||||||||||||||
| 75 | 1 | ▶ | if ( $round >= $firstround and -e "./pairtable.yaml" ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$round >= $firstround and -e "./pairtable.yaml"
MC/DC0%0/2
$round >= $firstround and -e "./pairtable.yaml"
$round >= $firstround
-e "./pairtable.yaml"
Truth table33%1/3
A and B
A= $round >= $firstroundB= -e "./pairtable.yaml"
| |||||||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||||||
| 77 | 0 | my $pairingtable = LoadFile "./pairtable.yaml"; | |||||||||||||||||||||||||||
| 78 | my ( $opponents, $roles, $floats, $score ) = | ||||||||||||||||||||||||||||
| 79 | 0 | @$pairingtable{qw/opponents roles floats score/}; | |||||||||||||||||||||||||||
| 80 | 0 | for my $player ( @$lineup ) | |||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||
| 82 | 0 | my $id = $player->id; | |||||||||||||||||||||||||||
| 83 | 0 | $player->score( $score->{$id} ); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | 0 | my $lastround = $round; | |||||||||||||||||||||||||||
| 86 | 0 | for my $round ( 1..$lastround ) | |||||||||||||||||||||||||||
| 87 | { | ||||||||||||||||||||||||||||
| 88 | 0 | my %opponents = map { $_ => $opponents->{$_}->[$round-1] } @ids; | |||||||||||||||||||||||||||
| 89 | 0 | my %roles = map { $_ => $roles->{$_}->[$round-1] } @ids; | |||||||||||||||||||||||||||
| 90 | my %floats = | ||||||||||||||||||||||||||||
| 91 | 0 | ▶ | map { $_ => $floats->{$_}->[$round-$lastround-1]||undef } @ids; | ||||||||||||||||||||||||||
|
Condition0%0/2
$floats->{$_}[$round - $lastround - 1] || undef
MC/DC0%0/1
$floats->{$_}[$round - $lastround - 1] || undef
$floats->{$_}[$round - $lastround - 1]
Truth table0%0/2
A
A= $floats->{$_}[$round - $lastround - 1]
| |||||||||||||||||||||||||||||
| 92 | 0 | my @games = $tourney->prepareCards( { | |||||||||||||||||||||||||||
| 93 | round => $round, opponents => \%opponents, | ||||||||||||||||||||||||||||
| 94 | roles => \%roles, floats => \%floats } ); | ||||||||||||||||||||||||||||
| 95 | 0 | $tourney->collectCards( @games ); | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 1 | my %brackets = $tourney->formBrackets; | |||||||||||||||||||||||||||
| 100 | 1 | my $pairing = $tourney->pairing( \%brackets ); | |||||||||||||||||||||||||||
| 101 | 1 | $pairing->loggingAll; | |||||||||||||||||||||||||||
| 102 | 1 | my $results = $pairing->matchPlayers; | |||||||||||||||||||||||||||
| 103 | 1 | my $log = $pairing->logreport; | |||||||||||||||||||||||||||
| 104 | 1 | ▶ | use IO::All; io('=')->print($log); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 105 | 1 | my $matches = $results->{matches}; | |||||||||||||||||||||||||||
| 106 | 1 | my @games; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 1 | my %number = map { $_ => $brackets{$_}->number } keys %brackets; | |||||||||||||||||||||||||||
| 109 | 0 | for my $bracket ( sort { $number{$a} cmp $number{$b} } keys %$matches ) | |||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||
| 111 | 1 | my $bracketmatches = $matches->{$bracket}; | |||||||||||||||||||||||||||
| 112 | 1 | push @games, grep { ref eq 'Games::Tournament::Card' } | |||||||||||||||||||||||||||
| 113 | @$bracketmatches; | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | 1 | $tourney->round($next); | |||||||||||||||||||||||||||
| 116 | 1 | $tourney->publishCards(@games); | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 1 | my ($schedule, $template); | |||||||||||||||||||||||||||
| 119 | $schedule->{Warning} = | ||||||||||||||||||||||||||||
| 120 | 1 | "# This file, $directory/round.yaml, was created for round $next by pair on " | |||||||||||||||||||||||||||
| 121 | . localtime() . '.'; | ||||||||||||||||||||||||||||
| 122 | 1 | ▶ | if ( -e '../assistants.yaml' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 0 | my $assistantFile = LoadFile '../assistants.yaml'; | |||||||||||||||||||||||||||
| 124 | 0 | $schedule->{assistant} = $assistantFile->{$next}; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | 1 | $n = 1; | |||||||||||||||||||||||||||
| 127 | 1 | for my $game (@games) { | |||||||||||||||||||||||||||
| 128 | 4 | my %group = map { $_ => $game->{contestants}->{$_}->{name} } | |||||||||||||||||||||||||||
| 129 | 2 | keys %{ $game->{contestants} }; | |||||||||||||||||||||||||||
| 130 | 2 | $schedule->{group}->{$n} = \%group; | |||||||||||||||||||||||||||
| 131 | 2 | $template->{$n} = { reverse %group }; | |||||||||||||||||||||||||||
| 132 | 2 | $n++; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 1 | ▶ | if ( $lateEntries ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 1 | DumpFile '../league.yaml.bak', $league; | |||||||||||||||||||||||||||
| 137 | $league->{member} = | ||||||||||||||||||||||||||||
| 138 | 4 | [ map { my $member = $_; | |||||||||||||||||||||||||||
| 139 | 4 | +{ map { $_ => $member->$_ } | |||||||||||||||||||||||||||
| 140 | qw/firstround id name pairingNumber rating title/ }; | ||||||||||||||||||||||||||||
| 141 | 1 | } @{ $tourney->entrants } | |||||||||||||||||||||||||||
| 142 | ]; | ||||||||||||||||||||||||||||
| 143 | 1 | $league->{late} = undef; | |||||||||||||||||||||||||||
| 144 | 1 | DumpFile '../league.yaml', $league; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 1 | $schedule->{firstround} = $swiss->firstround($firstround); | |||||||||||||||||||||||||||
| 149 | 1 | $schedule->{scores} = $swiss->scores($scores); | |||||||||||||||||||||||||||
| 150 | 1 | $schedule->{roles} = $swiss->roles($roles); | |||||||||||||||||||||||||||
| 151 | 1 | $schedule->{algorithm} = $swiss->algorithm($algorithm); | |||||||||||||||||||||||||||
| 152 | 1 | $schedule->{round} = $next; | |||||||||||||||||||||||||||
| 153 | 1 | $schedule->{week} = $next . ' perhaps. Change if wrong.'; | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 1 | DumpFile 'player.yaml', $tourney->entrants; | |||||||||||||||||||||||||||
| 156 | 1 | DumpFile 'tourney.yaml', $tourney; | |||||||||||||||||||||||||||
| 157 | 1 | DumpFile 'pairing.yaml', $pairing; | |||||||||||||||||||||||||||
| 158 | 1 | DumpFile 'matches.yaml', \@games; | |||||||||||||||||||||||||||
| 159 | 1 | DumpFile 'brackets.yaml', \%brackets; | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 1 | my @keys = sort {$a<=>$b} keys %{$schedule->{group}}; | |||||||||||||||||||||||||||
| 162 | 1 | Bless($schedule->{group})->keys( \@keys ); | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 1 | DumpFile 'round.yaml', $schedule; | |||||||||||||||||||||||||||
| 165 | 1 | DumpFile "$next.yaml", $template; | |||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | __END__ | ||||||||||||||||||||||||||||