@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | |
17 | 17 | // CALCULATE BYES |
18 | 18 | $byes = 0; |
19 | - if ( !\TournamentGenerator\isPowerOf2($countTeams) ) { |
|
19 | + if (!\TournamentGenerator\isPowerOf2($countTeams)) { |
|
20 | 20 | $nextPow = bindec(str_pad(1, strlen(decbin($countTeams))+1, 0, STR_PAD_RIGHT)); |
21 | 21 | $byes = $nextPow-$countTeams; |
22 | 22 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | |
28 | 28 | $previousGroups = []; |
29 | 29 | |
30 | - for ($i=1; $i <= (($countTeams+$byes)/2); $i++) { |
|
30 | + for ($i = 1; $i <= (($countTeams+$byes)/2); $i++) { |
|
31 | 31 | $g = $startRound->group([ |
32 | 32 | 'name' => 'Round 1 - '.$i, |
33 | 33 | 'inGame' => 2, |
@@ -38,10 +38,10 @@ discard block |
||
38 | 38 | |
39 | 39 | $this->splitTeams(); |
40 | 40 | |
41 | - for ($r=2; $r <= $roundsNum; $r++) { |
|
41 | + for ($r = 2; $r <= $roundsNum; $r++) { |
|
42 | 42 | $groups = []; |
43 | 43 | $round = $this->round('Round '.$r); |
44 | - for ($g=1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) { |
|
44 | + for ($g = 1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) { |
|
45 | 45 | $group = $round->group([ |
46 | 46 | 'name' => 'Round '.$r.' - '.$g, |
47 | 47 | 'inGame' => 2, |
@@ -50,7 +50,7 @@ |
||
50 | 50 | |
51 | 51 | $this->splitTeams($round1); |
52 | 52 | |
53 | - if (count($this->getTeams()) % 4 == 2) { |
|
53 | + if (count($this->getTeams())%4 == 2) { |
|
54 | 54 | $group_top = $round2->group([ |
55 | 55 | 'name' => 'TOP', |
56 | 56 | 'type' => TWO_TWO |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | // CALCULATE BYES |
20 | 20 | $byes = 0; |
21 | 21 | $nextPow = $countTeams; |
22 | - if ( !\TournamentGenerator\isPowerOf2($countTeams) ) { |
|
22 | + if (!\TournamentGenerator\isPowerOf2($countTeams)) { |
|
23 | 23 | $nextPow = bindec(str_pad(1, strlen(decbin($countTeams))+1, 0, STR_PAD_RIGHT)); |
24 | 24 | $byes = $nextPow-$countTeams; |
25 | 25 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | $groupIds = []; |
39 | 39 | $allGroups = []; |
40 | 40 | |
41 | - for ($i=1; $i <= $startGroups; $i++) { |
|
41 | + for ($i = 1; $i <= $startGroups; $i++) { |
|
42 | 42 | $g = $startRound->group([ |
43 | 43 | 'name' => 'Start group - '.$i, |
44 | 44 | 'inGame' => 2, |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | // SPLIT TEAMS EVENLY |
53 | 53 | $this->splitTeams(); |
54 | 54 | |
55 | - for ($r=2; $r <= $roundsNum-1; $r++) { |
|
55 | + for ($r = 2; $r <= $roundsNum-1; $r++) { |
|
56 | 56 | $groups = []; |
57 | 57 | $losingGroups = []; |
58 | 58 | $round = $this->round('Round '.$r); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | $losingGroupTeamsCount = count($previousLosingGroups)+count($previousGroups); |
64 | 64 | $order = 2; |
65 | 65 | if (\TournamentGenerator\isPowerOf2($losingGroupTeamsCount)) { // IF THE NUMBER OF TEAMS IS A POWER OF 2, GENERATE GROUPS WITHOUT BYES |
66 | - for ($g=1; $g <= $losingGroupTeamsCount/2; $g++) { |
|
66 | + for ($g = 1; $g <= $losingGroupTeamsCount/2; $g++) { |
|
67 | 67 | $group = $round->group([ |
68 | 68 | 'name' => 'Round '.$r.' - loss '.$g, |
69 | 69 | 'inGame' => 2, |
@@ -91,11 +91,11 @@ discard block |
||
91 | 91 | $n = (floor(count($previousLosingGroups)/2)+$losingByes); |
92 | 92 | $byesGroupsNums = []; |
93 | 93 | $byesProgressed = 0; |
94 | - for ($i=0; $i < $losingByes; $i++) { |
|
94 | + for ($i = 0; $i < $losingByes; $i++) { |
|
95 | 95 | $byesGroupsNums[] = $n-($i*2); |
96 | 96 | } |
97 | 97 | $lastGroup = 0; |
98 | - for ($g=1; $g <= ((count($previousLosingGroups)/2)+$losingByes); $g++) { |
|
98 | + for ($g = 1; $g <= ((count($previousLosingGroups)/2)+$losingByes); $g++) { |
|
99 | 99 | $group = $round->group([ |
100 | 100 | 'name' => 'Round '.$r.' - loss '.$g, |
101 | 101 | 'inGame' => 2, |
@@ -112,14 +112,14 @@ discard block |
||
112 | 112 | } |
113 | 113 | else { |
114 | 114 | $previousLosingGroups[$lastGroup]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE |
115 | - if (isset($previousLosingGroups[$lastGroup + 1])) $previousLosingGroups[$lastGroup + 1]->progression($group, 0, 1); // PROGREESS FROM LOSING GROUP BEFORE |
|
115 | + if (isset($previousLosingGroups[$lastGroup+1])) $previousLosingGroups[$lastGroup+1]->progression($group, 0, 1); // PROGREESS FROM LOSING GROUP BEFORE |
|
116 | 116 | $lastGroup += 2; |
117 | 117 | } |
118 | 118 | } |
119 | 119 | } |
120 | 120 | // WINNING SIDE LIKE SINGLE ELIMINATION |
121 | 121 | $order = 1; |
122 | - for ($g=1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) { |
|
122 | + for ($g = 1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) { |
|
123 | 123 | $group = $round->group([ |
124 | 124 | 'name' => 'Round '.$r.' - win '.$g, |
125 | 125 | 'inGame' => 2, |
@@ -22,11 +22,11 @@ discard block |
||
22 | 22 | function circle_genGames2(array $teams = [], Group $group = null) { |
23 | 23 | $bracket = []; // ARRAY OF GAMES |
24 | 24 | |
25 | - if (count($teams) % 2 != 0) $teams[] = DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
25 | + if (count($teams)%2 != 0) $teams[] = DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
26 | 26 | |
27 | 27 | shuffle($teams); // SHUFFLE TEAMS FOR MORE RANDOMNESS |
28 | 28 | |
29 | - for ($i=0; $i < count($teams)-1; $i++) { |
|
29 | + for ($i = 0; $i < count($teams)-1; $i++) { |
|
30 | 30 | $bracket = array_merge($bracket, circle_saveBracket($teams, $group)); // SAVE CURRENT ROUND |
31 | 31 | |
32 | 32 | $teams = circle_rotateBracket($teams); // ROTATE TEAMS IN BRACKET |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | |
42 | 42 | $bracket = []; |
43 | 43 | |
44 | - for ($i=0; $i < count($teams)/2; $i++) { // GO THROUGH HALF OF THE TEAMS |
|
44 | + for ($i = 0; $i < count($teams)/2; $i++) { // GO THROUGH HALF OF THE TEAMS |
|
45 | 45 | |
46 | 46 | $home = $teams[$i]; |
47 | 47 | $reverse = array_reverse($teams); |
@@ -68,11 +68,11 @@ discard block |
||
68 | 68 | return 'Group '.$this->name; |
69 | 69 | } |
70 | 70 | |
71 | - public function allowSkip(){ |
|
71 | + public function allowSkip() { |
|
72 | 72 | $this->allowSkip = true; |
73 | 73 | return $this; |
74 | 74 | } |
75 | - public function disallowSkip(){ |
|
75 | + public function disallowSkip() { |
|
76 | 76 | $this->allowSkip = false; |
77 | 77 | return $this; |
78 | 78 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | |
87 | 87 | public function addTeam(...$teams) { |
88 | 88 | foreach ($teams as $team) { |
89 | - if ($team instanceof Team) { |
|
89 | + if ($team instanceof Team) { |
|
90 | 90 | $this->teams[] = $team; |
91 | 91 | $team->groupResults[$this->id] = [ |
92 | 92 | 'group' => $this, |
@@ -243,13 +243,13 @@ discard block |
||
243 | 243 | if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"]) return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
244 | 244 | return ($a->groupResults[$this->id]["points"] > $b->groupResults[$this->id]["points"] ? -1 : 1); |
245 | 245 | }); |
246 | - break;} |
|
246 | + break; } |
|
247 | 247 | case SCORE:{ |
248 | 248 | usort($this->teams, function($a, $b) { |
249 | 249 | if ($a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) return 0; |
250 | 250 | return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
251 | 251 | }); |
252 | - break;} |
|
252 | + break; } |
|
253 | 253 | } |
254 | 254 | return $this->getTeams($filters); |
255 | 255 | } |
@@ -314,19 +314,19 @@ discard block |
||
314 | 314 | switch ($this->type) { |
315 | 315 | case R_R:{ |
316 | 316 | $this->games = $this->r_rGames(); |
317 | - break;} |
|
317 | + break; } |
|
318 | 318 | case TWO_TWO: |
319 | 319 | $teams = $this->teams; |
320 | 320 | $discard = []; |
321 | 321 | shuffle($teams); |
322 | 322 | $count = count($teams); |
323 | - while (count($teams) % $this->inGame !== 0) { |
|
323 | + while (count($teams)%$this->inGame !== 0) { |
|
324 | 324 | $discard[] = array_shift($teams); |
325 | 325 | } |
326 | 326 | |
327 | 327 | while (count($teams) > 0) { |
328 | 328 | $tInGame = []; |
329 | - for ($i=0; $i < $this->inGame; $i++) { |
|
329 | + for ($i = 0; $i < $this->inGame; $i++) { |
|
330 | 330 | $tInGame[] = array_shift($teams); |
331 | 331 | } |
332 | 332 | $this->game($tInGame); |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | $this->games[] = $g; |
366 | 366 | return $g; |
367 | 367 | } |
368 | - public function addGame(Game ...$games){ |
|
368 | + public function addGame(Game ...$games) { |
|
369 | 369 | foreach ($games as $game) { |
370 | 370 | if ($game instanceof Game) $this->games[] = $game; |
371 | 371 | else throw new \Exception('Trying to add game which is not instance of Game object.'); |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | foreach ($games as $key => $game) { |
462 | 462 | $gTeams = $game->getTeamsIds(); |
463 | 463 | $suitable = true; |
464 | - $requiredTeams = array_filter($teams, function($a){ |
|
464 | + $requiredTeams = array_filter($teams, function($a) { |
|
465 | 465 | return $a < 4; |
466 | 466 | }); |
467 | 467 | foreach ($gTeams as $tid) { |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | foreach ($games as $key => $game) { |
513 | 513 | $gTeams = $game->getTeamsIds(); |
514 | 514 | $suitable = false; |
515 | - $requiredTeams = array_filter($teams, function($a){ |
|
515 | + $requiredTeams = array_filter($teams, function($a) { |
|
516 | 516 | return $a < 4; |
517 | 517 | }); |
518 | 518 | foreach ($gTeams as $tid) { |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | $games = array_merge($games, $games); |
558 | 558 | } |
559 | 559 | // $this->orderGames(); |
560 | - break;} |
|
560 | + break; } |
|
561 | 561 | case 4:{ |
562 | 562 | $teamsB = $teams; |
563 | 563 | $lockedTeam1 = array_shift($teamsB); |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | } |
576 | 576 | $games[] = new Game(array_merge([$lockedTeam1], $teamsB), $this); |
577 | 577 | // $this->orderGames(); |
578 | - break;} |
|
578 | + break; } |
|
579 | 579 | } |
580 | 580 | return $games; |
581 | 581 | } |
@@ -601,7 +601,7 @@ discard block |
||
601 | 601 | } |
602 | 602 | return $this; |
603 | 603 | } |
604 | - public function isPlayed(){ |
|
604 | + public function isPlayed() { |
|
605 | 605 | foreach ($this->games as $game) { |
606 | 606 | if ((isset($game) || !$this->getSkip()) && !$game->isPlayed()) return false; |
607 | 607 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | return $this->name; |
26 | 26 | } |
27 | 27 | |
28 | - public function addGroup(Group ...$groups){ |
|
28 | + public function addGroup(Group ...$groups) { |
|
29 | 29 | foreach ($groups as $group) { |
30 | 30 | if ($group instanceof Group) $this->groups[] = $group; |
31 | 31 | else throw new \Exception('Trying to add group which is not an instance of Group class.'); |
@@ -37,21 +37,21 @@ discard block |
||
37 | 37 | $this->groups[] = $g->setSkip($this->allowSkip); |
38 | 38 | return $g; |
39 | 39 | } |
40 | - public function getGroups(){ |
|
40 | + public function getGroups() { |
|
41 | 41 | $this->orderGroups(); |
42 | 42 | return $this->groups; |
43 | 43 | } |
44 | 44 | public function orderGroups() { |
45 | - usort($this->groups, function($a, $b){ |
|
46 | - return $a->order - $b->order; |
|
45 | + usort($this->groups, function($a, $b) { |
|
46 | + return $a->order-$b->order; |
|
47 | 47 | }); |
48 | 48 | } |
49 | 49 | |
50 | - public function allowSkip(){ |
|
50 | + public function allowSkip() { |
|
51 | 51 | $this->allowSkip = true; |
52 | 52 | return $this; |
53 | 53 | } |
54 | - public function disallowSkip(){ |
|
54 | + public function disallowSkip() { |
|
55 | 55 | $this->allowSkip = false; |
56 | 56 | return $this; |
57 | 57 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | return $this->allowSkip; |
64 | 64 | } |
65 | 65 | |
66 | - public function genGames(){ |
|
66 | + public function genGames() { |
|
67 | 67 | $games = []; |
68 | 68 | $g = 0; |
69 | 69 | foreach ($this->groups as $group) { |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | public function getGames() { |
88 | 88 | return $this->games; |
89 | 89 | } |
90 | - public function isPlayed(){ |
|
90 | + public function isPlayed() { |
|
91 | 91 | foreach ($this->groups as $group) { |
92 | 92 | if (!$group->isPlayed()) return false; |
93 | 93 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | |
97 | 97 | public function addTeam(...$teams) { |
98 | 98 | foreach ($teams as $team) { |
99 | - if ($team instanceof Team) { |
|
99 | + if ($team instanceof Team) { |
|
100 | 100 | $this->teams[] = $team; |
101 | 101 | } |
102 | 102 | elseif (gettype($team) === 'array') { |
@@ -157,14 +157,14 @@ discard block |
||
157 | 157 | return $this; |
158 | 158 | } |
159 | 159 | |
160 | - public function progress(){ |
|
160 | + public function progress() { |
|
161 | 161 | foreach ($this->groups as $group) { |
162 | 162 | $group->progress(); |
163 | 163 | } |
164 | 164 | return $this; |
165 | 165 | } |
166 | 166 | |
167 | - public function progressBlank(){ |
|
167 | + public function progressBlank() { |
|
168 | 168 | if (!$this->isPlayed()) $this->simulate(); |
169 | 169 | foreach ($this->groups as $group) { |
170 | 170 | $group->progressBlank(); |
@@ -45,12 +45,12 @@ |
||
45 | 45 | |
46 | 46 | private $groups = []; |
47 | 47 | |
48 | - function __construct(string $what = 'points', string $how = '>', $val = 0, $groups = []){ |
|
48 | + function __construct(string $what = 'points', string $how = '>', $val = 0, $groups = []) { |
|
49 | 49 | if (in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) $this->what = strtolower($what); |
50 | 50 | if (in_array($how, ['>', '<', '>=', '<=', '=', '!='])) $this->how = $how; |
51 | 51 | if ((gettype($val) === 'integer' && strtolower($what) !== 'team') || ($val instanceof Team && strtolower($what) === 'team')) $this->val = $val; |
52 | 52 | foreach ($groups as $group) { |
53 | - if ($group instanceof Group) $this->groups[] = $group->id; |
|
53 | + if ($group instanceof Group) $this->groups[] = $group->id; |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | public function __toString() { |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | $this->name = $name; |
22 | 22 | } |
23 | 23 | |
24 | - public function addRound(Round ...$rounds){ |
|
24 | + public function addRound(Round ...$rounds) { |
|
25 | 25 | foreach ($rounds as $round) { |
26 | 26 | if ($round instanceof Round) $this->rounds[] = $round; |
27 | 27 | else throw new \Exception('Trying to add round which is not an instance of Round class.'); |
@@ -33,15 +33,15 @@ discard block |
||
33 | 33 | $this->rounds[] = $r->setSkip($this->allowSkip); |
34 | 34 | return $r; |
35 | 35 | } |
36 | - public function getRounds(){ |
|
36 | + public function getRounds() { |
|
37 | 37 | return $this->rounds; |
38 | 38 | } |
39 | 39 | |
40 | - public function allowSkip(){ |
|
40 | + public function allowSkip() { |
|
41 | 41 | $this->allowSkip = true; |
42 | 42 | return $this; |
43 | 43 | } |
44 | - public function disallowSkip(){ |
|
44 | + public function disallowSkip() { |
|
45 | 45 | $this->allowSkip = false; |
46 | 46 | return $this; |
47 | 47 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | public function addTeam(...$teams) { |
57 | 57 | foreach ($teams as $team) { |
58 | - if ($team instanceof Team) { |
|
58 | + if ($team instanceof Team) { |
|
59 | 59 | $this->teams[] = $team; |
60 | 60 | } |
61 | 61 | elseif (gettype($team) === 'array') { |
@@ -78,10 +78,10 @@ discard block |
||
78 | 78 | if (count($error) > 0) throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); |
79 | 79 | return $this; |
80 | 80 | } |
81 | - public function getTeams(){ |
|
81 | + public function getTeams() { |
|
82 | 82 | return $this->teams; |
83 | 83 | } |
84 | - public function getTeamsIds(){ |
|
84 | + public function getTeamsIds() { |
|
85 | 85 | $ids = []; |
86 | 86 | foreach ($this->teams as $team) { |
87 | 87 | $ids[] = $team->id; |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | $team->addLoss($this->group->id); |
129 | 129 | $this->results[$team->id] += ['points' => $this->group->lostPoints, 'type' => 'loss']; |
130 | 130 | } |
131 | - break;} |
|
131 | + break; } |
|
132 | 132 | case 3:{ |
133 | 133 | switch ($i) { |
134 | 134 | case 1: |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | $this->results[$team->id] += ['points' => $this->group->lostPoints, 'type' => 'loss']; |
148 | 148 | break; |
149 | 149 | } |
150 | - break;} |
|
150 | + break; } |
|
151 | 151 | case 4:{ |
152 | 152 | switch ($i) { |
153 | 153 | case 1: |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | $this->results[$team->id] += ['points' => $this->group->lostPoints, 'type' => 'loss']; |
172 | 172 | break; |
173 | 173 | } |
174 | - break;} |
|
174 | + break; } |
|
175 | 175 | } |
176 | 176 | $team->groupResults[$this->group->id]['score'] += $score; |
177 | 177 | $i++; |