Conditions | 5 |
Paths | 12 |
Total Lines | 39 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
11 | public function generate() { |
||
12 | |||
13 | $this->allowSkip(); |
||
14 | |||
15 | $countTeams = count($this->getTeams()); |
||
16 | |||
17 | // CALCULATE BYES |
||
18 | $byes = 0; |
||
19 | if ( !\TournamentGenerator\isPowerOf2($countTeams) ) { |
||
20 | $nextPow = bindec(str_pad(1, strlen(decbin($countTeams))+1, 0, STR_PAD_RIGHT)); |
||
21 | $byes = $nextPow-$countTeams; |
||
22 | } |
||
23 | |||
24 | $roundsNum = log($countTeams+$byes, 2); // NUMBER OF ROUNDS |
||
25 | |||
26 | $startRound = $this->round('Start'); |
||
27 | |||
28 | $previousGroups = []; |
||
29 | |||
30 | for ($i=1; $i <= (($countTeams+$byes)/2); $i++) { |
||
31 | $g = $startRound->group('Round 1 '.$i)->setInGame(2)->setType(\TournamentGenerator\Constants::ROUND_TWO); |
||
32 | $previousGroups[] = $g; |
||
33 | } |
||
34 | |||
35 | $this->splitTeams(); |
||
36 | |||
37 | for ($r=2; $r <= $roundsNum; $r++) { |
||
38 | $groups = []; |
||
39 | $round = $this->round('Round '.$r); |
||
40 | for ($g=1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) { |
||
41 | $group = $round->group('Round '.$r.' - '.$g)->setInGame(2)->setType(\TournamentGenerator\Constants::ROUND_TWO); |
||
42 | $groups[] = $group; |
||
43 | array_shift($previousGroups)->progression($group, 0, 1); // PROGRESS FROM GROUP BEFORE |
||
44 | array_shift($previousGroups)->progression($group, 0, 1); // PROGREESS FROM GROUP BEFORE |
||
45 | } |
||
46 | $previousGroups = $groups; |
||
47 | } |
||
48 | |||
49 | return $this; |
||
50 | |||
54 |