@@ -18,7 +18,9 @@ discard block |
||
| 18 | 18 | $game->setResults($results); |
| 19 | 19 | } |
| 20 | 20 | $return = $group->sortTeams($filters); |
| 21 | - if (!$reset) return $return; |
|
| 21 | + if (!$reset) { |
|
| 22 | + return $return; |
|
| 23 | + } |
|
| 22 | 24 | foreach ($group->getGames() as $game) { |
| 23 | 25 | $game->resetResults(); |
| 24 | 26 | } |
@@ -27,14 +29,18 @@ discard block |
||
| 27 | 29 | |
| 28 | 30 | public static function simulateRound(\TournamentGenerator\Round $round) { |
| 29 | 31 | foreach ($round->getGroups() as $group) { |
| 30 | - if ($group->isPlayed()) continue; |
|
| 32 | + if ($group->isPlayed()) { |
|
| 33 | + continue; |
|
| 34 | + } |
|
| 31 | 35 | $group->simulate([], false); |
| 32 | 36 | } |
| 33 | 37 | return true; |
| 34 | 38 | } |
| 35 | 39 | |
| 36 | 40 | public static function simulateTournament(\TournamentGenerator\Tournament $tournament) { |
| 37 | - if (count($tournament->getCategories()) === 0 && count($tournament->getRounds()) === 0) throw new \Exception('There are no rounds or categories to simulate games from.'); |
|
| 41 | + if (count($tournament->getCategories()) === 0 && count($tournament->getRounds()) === 0) { |
|
| 42 | + throw new \Exception('There are no rounds or categories to simulate games from.'); |
|
| 43 | + } |
|
| 38 | 44 | |
| 39 | 45 | $games = []; |
| 40 | 46 | |
@@ -55,7 +61,9 @@ discard block |
||
| 55 | 61 | |
| 56 | 62 | public static function simulateTournamentReal(\TournamentGenerator\Tournament $tournament) { |
| 57 | 63 | $games = []; |
| 58 | - if (count($tournament->getCategories()) === 0 && count($tournament->getRounds()) === 0) throw new \Exception('There are no rounds or categories to simulate games from.'); |
|
| 64 | + if (count($tournament->getCategories()) === 0 && count($tournament->getRounds()) === 0) { |
|
| 65 | + throw new \Exception('There are no rounds or categories to simulate games from.'); |
|
| 66 | + } |
|
| 59 | 67 | |
| 60 | 68 | foreach ($tournament->getCategories() as $category) { |
| 61 | 69 | $games = array_merge($games, $category->genGamesSimulate()); |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | // CYCLE 6 |
| 71 | 71 | // FIRST AVAILABLE GAME |
| 72 | - $this->moveCalculatedGames(array_shift($games),$teams); |
|
| 72 | + $this->moveCalculatedGames(array_shift($games), $teams); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | return $this->games; |
@@ -79,8 +79,8 @@ discard block |
||
| 79 | 79 | private function cycle1(array &$games, array &$teams) { |
| 80 | 80 | $found = false; |
| 81 | 81 | foreach ($games as $key => $game) { |
| 82 | - if ($this->orderCheckTeamsVal($game, $teams, [4,5,6,7])) { |
|
| 83 | - $this->moveCalculatedGames($game,$teams); |
|
| 82 | + if ($this->orderCheckTeamsVal($game, $teams, [4, 5, 6, 7])) { |
|
| 83 | + $this->moveCalculatedGames($game, $teams); |
|
| 84 | 84 | unset($games[$key]); |
| 85 | 85 | $found = true; |
| 86 | 86 | break; |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | private function cycle2(array &$games, array &$teams) { |
| 93 | 93 | $found = false; |
| 94 | 94 | foreach ($games as $key => $game) { |
| 95 | - if ($this->orderCheckTeamsVal($game, $teams, [6,7])) { |
|
| 96 | - $this->moveCalculatedGames($game,$teams); |
|
| 95 | + if ($this->orderCheckTeamsVal($game, $teams, [6, 7])) { |
|
| 96 | + $this->moveCalculatedGames($game, $teams); |
|
| 97 | 97 | unset($games[$key]); |
| 98 | 98 | $found = true; |
| 99 | 99 | break; |
@@ -106,8 +106,8 @@ discard block |
||
| 106 | 106 | private function cycle3(array &$games, array &$teams) { |
| 107 | 107 | $found = false; |
| 108 | 108 | foreach ($games as $key => $game) { |
| 109 | - if ($this->orderCheckTeamsVal($game, $teams, [7], [1,2,3])) { |
|
| 110 | - $this->moveCalculatedGames($game,$teams); |
|
| 109 | + if ($this->orderCheckTeamsVal($game, $teams, [7], [1, 2, 3])) { |
|
| 110 | + $this->moveCalculatedGames($game, $teams); |
|
| 111 | 111 | unset($games[$key]); |
| 112 | 112 | $found = true; |
| 113 | 113 | break; |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | $found = false; |
| 121 | 121 | foreach ($games as $key => $game) { |
| 122 | 122 | if ($this->orderCheckTeamsVal($game, $teams, [7])) { |
| 123 | - $this->moveCalculatedGames($game,$teams); |
|
| 123 | + $this->moveCalculatedGames($game, $teams); |
|
| 124 | 124 | unset($games[$key]); |
| 125 | 125 | $found = true; |
| 126 | 126 | break; |
@@ -132,8 +132,8 @@ discard block |
||
| 132 | 132 | private function cycle5(array &$games, array &$teams) { |
| 133 | 133 | $found = false; |
| 134 | 134 | foreach ($games as $key => $game) { |
| 135 | - if ($this->orderCheckTeamsVal($game, $teams, [], [1,2,3])) { |
|
| 136 | - $this->moveCalculatedGames($game,$teams); |
|
| 135 | + if ($this->orderCheckTeamsVal($game, $teams, [], [1, 2, 3])) { |
|
| 136 | + $this->moveCalculatedGames($game, $teams); |
|
| 137 | 137 | unset($games[$key]); |
| 138 | 138 | $found = true; |
| 139 | 139 | break; |
@@ -36,7 +36,9 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | $games = $this->group->getGames(); |
| 38 | 38 | |
| 39 | - if (count($games) <= 4) return $games; |
|
| 39 | + if (count($games) <= 4) { |
|
| 40 | + return $games; |
|
| 41 | + } |
|
| 40 | 42 | |
| 41 | 43 | $this->games = []; |
| 42 | 44 | |
@@ -48,24 +50,34 @@ discard block |
||
| 48 | 50 | while (count($games) > 0) { |
| 49 | 51 | // CYCLE 1 |
| 50 | 52 | // TEAM WHICH DIDN'T PLAY IN LAST GAME (< 4) |
| 51 | - if ($this->cycle1($games, $teams)) continue; |
|
| 53 | + if ($this->cycle1($games, $teams)) { |
|
| 54 | + continue; |
|
| 55 | + } |
|
| 52 | 56 | |
| 53 | 57 | // CYCLE 2 |
| 54 | 58 | // NOT TEAM WHICH PLAYED IN LAST TWO GAMES (NOT 6 or 7) |
| 55 | - if ($this->cycle2($games, $teams)) continue; |
|
| 59 | + if ($this->cycle2($games, $teams)) { |
|
| 60 | + continue; |
|
| 61 | + } |
|
| 56 | 62 | |
| 57 | 63 | // CYCLE 3 |
| 58 | 64 | // NOT TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7) |
| 59 | 65 | // TEAMS THAT DIDN'T PLAY IN LAST GAME WILL PLAY THIS GAME (< 4) |
| 60 | - if ($this->cycle3($games, $teams)) continue; |
|
| 66 | + if ($this->cycle3($games, $teams)) { |
|
| 67 | + continue; |
|
| 68 | + } |
|
| 61 | 69 | |
| 62 | 70 | // CYCLE 4 |
| 63 | 71 | // NOT TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7) |
| 64 | - if ($this->cycle4($games, $teams)) continue; |
|
| 72 | + if ($this->cycle4($games, $teams)) { |
|
| 73 | + continue; |
|
| 74 | + } |
|
| 65 | 75 | |
| 66 | 76 | // CYCLE 5 |
| 67 | 77 | // TEAMS THAT DIDN'T PLAY IN LAST GAME WILL PLAY THIS GAME (< 4) |
| 68 | - if ($this->cycle5($games, $teams)) continue; |
|
| 78 | + if ($this->cycle5($games, $teams)) { |
|
| 79 | + continue; |
|
| 80 | + } |
|
| 69 | 81 | |
| 70 | 82 | // CYCLE 6 |
| 71 | 83 | // FIRST AVAILABLE GAME |
@@ -174,11 +186,17 @@ discard block |
||
| 174 | 186 | $requiredTeams = array_filter($teams, function($a) use ($required) { return in_array($a, $required); }); |
| 175 | 187 | |
| 176 | 188 | foreach ($game->getTeamsIds() as $tid) { |
| 177 | - if (in_array($teams[$tid], $checkVals)) return false; |
|
| 178 | - if (isset($requiredTeams[$tid])) unset($requiredTeams[$tid]); |
|
| 189 | + if (in_array($teams[$tid], $checkVals)) { |
|
| 190 | + return false; |
|
| 191 | + } |
|
| 192 | + if (isset($requiredTeams[$tid])) { |
|
| 193 | + unset($requiredTeams[$tid]); |
|
| 194 | + } |
|
| 179 | 195 | } |
| 180 | 196 | |
| 181 | - if (count($requiredTeams) > 0) return false; |
|
| 197 | + if (count($requiredTeams) > 0) { |
|
| 198 | + return false; |
|
| 199 | + } |
|
| 182 | 200 | |
| 183 | 201 | return true; |
| 184 | 202 | |
@@ -18,11 +18,11 @@ discard block |
||
| 18 | 18 | $this->group = $group; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | - public function allowSkip(){ |
|
| 21 | + public function allowSkip() { |
|
| 22 | 22 | $this->allowSkip = true; |
| 23 | 23 | return $this; |
| 24 | 24 | } |
| 25 | - public function disallowSkip(){ |
|
| 25 | + public function disallowSkip() { |
|
| 26 | 26 | $this->allowSkip = false; |
| 27 | 27 | return $this; |
| 28 | 28 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | public function setInGame(int $inGame) { |
| 48 | - if ($inGame < 2 || $inGame > 4) throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
| 48 | + if ($inGame < 2 || $inGame > 4) throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
| 49 | 49 | $this->inGame = $inGame; |
| 50 | 50 | return $this; |
| 51 | 51 | } |
@@ -120,11 +120,11 @@ discard block |
||
| 120 | 120 | $discard = []; |
| 121 | 121 | shuffle($teams); |
| 122 | 122 | $count = count($teams); |
| 123 | - while (count($teams) % $this->inGame !== 0) { $discard[] = array_shift($teams); } |
|
| 123 | + while (count($teams)%$this->inGame !== 0) { $discard[] = array_shift($teams); } |
|
| 124 | 124 | |
| 125 | 125 | while (count($teams) > 0) { |
| 126 | 126 | $tInGame = []; |
| 127 | - for ($i=0; $i < $this->inGame; $i++) { $tInGame[] = array_shift($teams); } |
|
| 127 | + for ($i = 0; $i < $this->inGame; $i++) { $tInGame[] = array_shift($teams); } |
|
| 128 | 128 | $this->group->game($tInGame); |
| 129 | 129 | } |
| 130 | 130 | |
@@ -165,11 +165,11 @@ discard block |
||
| 165 | 165 | public static function circle_genGames2(array $teams = [], \tournamentGenerator\Group $group) { |
| 166 | 166 | $bracket = []; // ARRAY OF GAMES |
| 167 | 167 | |
| 168 | - if (count($teams) % 2 != 0) $teams[] = \TournamentGenerator\Constants::DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
| 168 | + if (count($teams)%2 != 0) $teams[] = \TournamentGenerator\Constants::DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
| 169 | 169 | |
| 170 | 170 | shuffle($teams); // SHUFFLE TEAMS FOR MORE RANDOMNESS |
| 171 | 171 | |
| 172 | - for ($i=0; $i < count($teams)-1; $i++) { |
|
| 172 | + for ($i = 0; $i < count($teams)-1; $i++) { |
|
| 173 | 173 | $bracket = array_merge($bracket, Generator::circle_saveBracket($teams, $group)); // SAVE CURRENT ROUND |
| 174 | 174 | |
| 175 | 175 | $teams = Generator::circle_rotateBracket($teams); // ROTATE TEAMS IN BRACKET |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | |
| 184 | 184 | $bracket = []; |
| 185 | 185 | |
| 186 | - for ($i=0; $i < count($teams)/2; $i++) { // GO THROUGH HALF OF THE TEAMS |
|
| 186 | + for ($i = 0; $i < count($teams)/2; $i++) { // GO THROUGH HALF OF THE TEAMS |
|
| 187 | 187 | |
| 188 | 188 | $home = $teams[$i]; |
| 189 | 189 | $reverse = array_reverse($teams); |
@@ -36,8 +36,11 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | |
| 38 | 38 | public function setType(/** @scrutinizer ignore-all */ string $type = \TournamentGenerator\Constants::ROUND_ROBIN) { |
| 39 | - if (in_array($type, \TournamentGenerator\Constants::GroupTypes)) $this->type = $type; |
|
| 40 | - else throw new \Exception('Unknown group type: '.$type); |
|
| 39 | + if (in_array($type, \TournamentGenerator\Constants::GroupTypes)) { |
|
| 40 | + $this->type = $type; |
|
| 41 | + } else { |
|
| 42 | + throw new \Exception('Unknown group type: '.$type); |
|
| 43 | + } |
|
| 41 | 44 | return $this; |
| 42 | 45 | } |
| 43 | 46 | public function getType() { |
@@ -45,7 +48,9 @@ discard block |
||
| 45 | 48 | } |
| 46 | 49 | |
| 47 | 50 | public function setInGame(int $inGame) { |
| 48 | - if ($inGame < 2 || $inGame > 4) throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
| 51 | + if ($inGame < 2 || $inGame > 4) { |
|
| 52 | + throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
| 53 | + } |
|
| 49 | 54 | $this->inGame = $inGame; |
| 50 | 55 | return $this; |
| 51 | 56 | } |
@@ -54,7 +59,9 @@ discard block |
||
| 54 | 59 | } |
| 55 | 60 | |
| 56 | 61 | public function setMaxSize(int $maxSize) { |
| 57 | - if ($maxSize < 2) throw new \Exception('Max group size has to be at least 2, '.$maxSize.' given'); |
|
| 62 | + if ($maxSize < 2) { |
|
| 63 | + throw new \Exception('Max group size has to be at least 2, '.$maxSize.' given'); |
|
| 64 | + } |
|
| 58 | 65 | $this->maxSize = $maxSize; |
| 59 | 66 | return $this; |
| 60 | 67 | } |
@@ -78,7 +85,9 @@ discard block |
||
| 78 | 85 | } |
| 79 | 86 | private function r_rGames(array $teams = []) { |
| 80 | 87 | $games = []; |
| 81 | - if (count($teams) === 0) $teams = $this->group->getTeams(); |
|
| 88 | + if (count($teams) === 0) { |
|
| 89 | + $teams = $this->group->getTeams(); |
|
| 90 | + } |
|
| 82 | 91 | switch ($this->inGame) { |
| 83 | 92 | case 2: |
| 84 | 93 | $games = Generator::circle_genGames2($teams, $this->group); |
@@ -98,7 +107,9 @@ discard block |
||
| 98 | 107 | $lockedTeam = array_shift($teamsB); |
| 99 | 108 | $gamesTemp = Generator::circle_genGames2($teamsB, $this->group); |
| 100 | 109 | foreach ($gamesTemp as $game) { |
| 101 | - if (isset($lockedTeam1)) $game->addTeam($lockedTeam1); |
|
| 110 | + if (isset($lockedTeam1)) { |
|
| 111 | + $game->addTeam($lockedTeam1); |
|
| 112 | + } |
|
| 102 | 113 | $game->addTeam($lockedTeam); |
| 103 | 114 | } |
| 104 | 115 | $games = array_merge($games, $gamesTemp); |
@@ -116,7 +127,9 @@ discard block |
||
| 116 | 127 | return $games; |
| 117 | 128 | } |
| 118 | 129 | private function two_twoGames(array $teams = []) { |
| 119 | - if (count($teams) === 0) $teams = $this->group->getTeams(); |
|
| 130 | + if (count($teams) === 0) { |
|
| 131 | + $teams = $this->group->getTeams(); |
|
| 132 | + } |
|
| 120 | 133 | $discard = []; |
| 121 | 134 | shuffle($teams); |
| 122 | 135 | $count = count($teams); |
@@ -128,13 +141,17 @@ discard block |
||
| 128 | 141 | $this->group->game($tInGame); |
| 129 | 142 | } |
| 130 | 143 | |
| 131 | - if (count($discard) > 0 && !$this->allowSkip) throw new \Exception('Couldn\'t make games with all teams. Expected k*'.$this->inGame.' teams '.$count.' teams given - discarting '.count($discard).' teams ('.implode(', ', $discard).') in group '.$this->group.' - allow skip '.($this->allowSkip ? 'True' : 'False')); |
|
| 144 | + if (count($discard) > 0 && !$this->allowSkip) { |
|
| 145 | + throw new \Exception('Couldn\'t make games with all teams. Expected k*'.$this->inGame.' teams '.$count.' teams given - discarting '.count($discard).' teams ('.implode(', ', $discard).') in group '.$this->group.' - allow skip '.($this->allowSkip ? 'True' : 'False')); |
|
| 146 | + } |
|
| 132 | 147 | |
| 133 | 148 | return $this; |
| 134 | 149 | } |
| 135 | 150 | private function cond_splitGames(array $teams = []) { |
| 136 | 151 | $games = []; |
| 137 | - if (count($teams) === 0) $teams = $this->group->getTeams(); |
|
| 152 | + if (count($teams) === 0) { |
|
| 153 | + $teams = $this->group->getTeams(); |
|
| 154 | + } |
|
| 138 | 155 | |
| 139 | 156 | if (count($teams) > $this->maxSize) { |
| 140 | 157 | $groups = array_chunk($teams, /** @scrutinizer ignore-type */ ceil(count($teams)/ceil(count($teams)/$this->maxSize))); // SPLIT TEAMS INTO GROUP OF MAXIMUM SIZE OF $this->maxSize |
@@ -144,7 +161,9 @@ discard block |
||
| 144 | 161 | while ($g > 0) { |
| 145 | 162 | foreach ($games as $key => $group) { |
| 146 | 163 | $this->group->addGame(array_shift($games[$key])); |
| 147 | - if (count($games[$key]) === 0) unset($games[$key]); |
|
| 164 | + if (count($games[$key]) === 0) { |
|
| 165 | + unset($games[$key]); |
|
| 166 | + } |
|
| 148 | 167 | $g--; |
| 149 | 168 | } |
| 150 | 169 | } |
@@ -165,7 +184,10 @@ discard block |
||
| 165 | 184 | public static function circle_genGames2(array $teams = [], \tournamentGenerator\Group $group) { |
| 166 | 185 | $bracket = []; // ARRAY OF GAMES |
| 167 | 186 | |
| 168 | - if (count($teams) % 2 != 0) $teams[] = \TournamentGenerator\Constants::DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
| 187 | + if (count($teams) % 2 != 0) { |
|
| 188 | + $teams[] = \TournamentGenerator\Constants::DUMMY_TEAM; |
|
| 189 | + } |
|
| 190 | + // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
| 169 | 191 | |
| 170 | 192 | shuffle($teams); // SHUFFLE TEAMS FOR MORE RANDOMNESS |
| 171 | 193 | |
@@ -189,7 +211,10 @@ discard block |
||
| 189 | 211 | $reverse = array_reverse($teams); |
| 190 | 212 | $away = $reverse[$i]; |
| 191 | 213 | |
| 192 | - if (($home == \TournamentGenerator\Constants::DUMMY_TEAM || $away == \TournamentGenerator\Constants::DUMMY_TEAM)) continue; // SKIP WHEN DUMMY_TEAM IS PRESENT |
|
| 214 | + if (($home == \TournamentGenerator\Constants::DUMMY_TEAM || $away == \TournamentGenerator\Constants::DUMMY_TEAM)) { |
|
| 215 | + continue; |
|
| 216 | + } |
|
| 217 | + // SKIP WHEN DUMMY_TEAM IS PRESENT |
|
| 193 | 218 | |
| 194 | 219 | $bracket[] = new \TournamentGenerator\Game([$home, $away], $group); |
| 195 | 220 | |
@@ -16,20 +16,20 @@ |
||
| 16 | 16 | public $sumScore = 0; |
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | - * ARRAY WITH GROUPS AND IT'S RESULTS |
|
| 20 | - * array ( |
|
| 21 | - * * groupId => array ( |
|
| 22 | - * * * "group" => Group, # GROUP OBJECT |
|
| 23 | - * * * "points" => int 0, # NUMBER OF POINTS AQUIRED |
|
| 24 | - * * * "score" => int 0, # SUM OF SCORE AQUIRED |
|
| 25 | - * * * "wins" => int 0, # NUMBER OF WINS |
|
| 26 | - * * * "draws" => int 0, # NUMBER OF DRAWS |
|
| 27 | - * * * "losses" => int 0, # NUMBER OF LOSSES |
|
| 28 | - * * * "second" => int 0, # NUMBER OF TIMES BEING SECOND (ONLY FOR INGAME OPTION OF 3 OR 4) |
|
| 29 | - * * * "third" => int 0 # NUMBER OF TIMES BEING THIRD (ONLY FOR INGAME OPTION OF 4) |
|
| 30 | - * * ) |
|
| 31 | - *) |
|
| 32 | - */ |
|
| 19 | + * ARRAY WITH GROUPS AND IT'S RESULTS |
|
| 20 | + * array ( |
|
| 21 | + * * groupId => array ( |
|
| 22 | + * * * "group" => Group, # GROUP OBJECT |
|
| 23 | + * * * "points" => int 0, # NUMBER OF POINTS AQUIRED |
|
| 24 | + * * * "score" => int 0, # SUM OF SCORE AQUIRED |
|
| 25 | + * * * "wins" => int 0, # NUMBER OF WINS |
|
| 26 | + * * * "draws" => int 0, # NUMBER OF DRAWS |
|
| 27 | + * * * "losses" => int 0, # NUMBER OF LOSSES |
|
| 28 | + * * * "second" => int 0, # NUMBER OF TIMES BEING SECOND (ONLY FOR INGAME OPTION OF 3 OR 4) |
|
| 29 | + * * * "third" => int 0 # NUMBER OF TIMES BEING THIRD (ONLY FOR INGAME OPTION OF 4) |
|
| 30 | + * * ) |
|
| 31 | + *) |
|
| 32 | + */ |
|
| 33 | 33 | public $groupResults = []; |
| 34 | 34 | |
| 35 | 35 | function __construct(string $name = 'team', $id = null) { |
@@ -66,70 +66,70 @@ |
||
| 66 | 66 | return $this->sumScore; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - public function addWin(string $groupId = ''){ |
|
| 69 | + public function addWin(string $groupId = '') { |
|
| 70 | 70 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
| 71 | 71 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->winPoints; |
| 72 | 72 | $this->sumPoints += $this->groupResults[$groupId]['group']->winPoints; |
| 73 | 73 | $this->groupResults[$groupId]['wins']++; |
| 74 | 74 | return $this; |
| 75 | 75 | } |
| 76 | - public function removeWin(string $groupId = ''){ |
|
| 76 | + public function removeWin(string $groupId = '') { |
|
| 77 | 77 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
| 78 | 78 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->winPoints; |
| 79 | 79 | $this->sumPoints -= $this->groupResults[$groupId]['group']->winPoints; |
| 80 | 80 | $this->groupResults[$groupId]['wins']--; |
| 81 | 81 | return $this; |
| 82 | 82 | } |
| 83 | - public function addDraw(string $groupId = ''){ |
|
| 83 | + public function addDraw(string $groupId = '') { |
|
| 84 | 84 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
| 85 | 85 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->drawPoints; |
| 86 | 86 | $this->sumPoints += $this->groupResults[$groupId]['group']->drawPoints; |
| 87 | 87 | $this->groupResults[$groupId]['draws']++; |
| 88 | 88 | return $this; |
| 89 | 89 | } |
| 90 | - public function removeDraw(string $groupId = ''){ |
|
| 90 | + public function removeDraw(string $groupId = '') { |
|
| 91 | 91 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
| 92 | 92 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->drawPointsPoints; |
| 93 | 93 | $this->sumPoints -= $this->groupResults[$groupId]['group']->drawPoints; |
| 94 | 94 | $this->groupResults[$groupId]['draws']--; |
| 95 | 95 | return $this; |
| 96 | 96 | } |
| 97 | - public function addLoss(string $groupId = ''){ |
|
| 97 | + public function addLoss(string $groupId = '') { |
|
| 98 | 98 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
| 99 | 99 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->lostPoints; |
| 100 | 100 | $this->sumPoints += $this->groupResults[$groupId]['group']->lostPoints; |
| 101 | 101 | $this->groupResults[$groupId]['losses']++; |
| 102 | 102 | return $this; |
| 103 | 103 | } |
| 104 | - public function removeLoss(string $groupId = ''){ |
|
| 104 | + public function removeLoss(string $groupId = '') { |
|
| 105 | 105 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
| 106 | 106 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->lostPoints; |
| 107 | 107 | $this->sumPoints -= $this->groupResults[$groupId]['group']->lostPoints; |
| 108 | 108 | $this->groupResults[$groupId]['losses']--; |
| 109 | 109 | return $this; |
| 110 | 110 | } |
| 111 | - public function addSecond(string $groupId = ''){ |
|
| 111 | + public function addSecond(string $groupId = '') { |
|
| 112 | 112 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
| 113 | 113 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->secondPoints; |
| 114 | 114 | $this->sumPoints += $this->groupResults[$groupId]['group']->secondPoints; |
| 115 | 115 | $this->groupResults[$groupId]['second']++; |
| 116 | 116 | return $this; |
| 117 | 117 | } |
| 118 | - public function removeSecond(string $groupId = ''){ |
|
| 118 | + public function removeSecond(string $groupId = '') { |
|
| 119 | 119 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
| 120 | 120 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->secondPoints; |
| 121 | 121 | $this->sumPoints -= $this->groupResults[$groupId]['group']->secondPoints; |
| 122 | 122 | $this->groupResults[$groupId]['second']--; |
| 123 | 123 | return $this; |
| 124 | 124 | } |
| 125 | - public function addThird(string $groupId = ''){ |
|
| 125 | + public function addThird(string $groupId = '') { |
|
| 126 | 126 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
| 127 | 127 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->thirdPoints; |
| 128 | 128 | $this->sumPoints += $this->groupResults[$groupId]['group']->thirdPoints; |
| 129 | 129 | $this->groupResults[$groupId]['third']++; |
| 130 | 130 | return $this; |
| 131 | 131 | } |
| 132 | - public function removeThird(string $groupId = ''){ |
|
| 132 | + public function removeThird(string $groupId = '') { |
|
| 133 | 133 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
| 134 | 134 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->thirdPoints; |
| 135 | 135 | $this->sumPoints -= $this->groupResults[$groupId]['group']->thirdPoints; |
@@ -75,24 +75,32 @@ discard block |
||
| 75 | 75 | } |
| 76 | 76 | public function getGroupResults($groupId = null) { |
| 77 | 77 | if (isset($groupId)) { |
| 78 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Trying to get unexisting group results ('.$groupId.')'); |
|
| 78 | + if (!isset($this->groupResults[$groupId])) { |
|
| 79 | + throw new \Exception('Trying to get unexisting group results ('.$groupId.')'); |
|
| 80 | + } |
|
| 79 | 81 | return $this->groupResults[$groupId]; |
| 80 | 82 | } |
| 81 | 83 | return $this->groupResults; |
| 82 | 84 | } |
| 83 | 85 | |
| 84 | 86 | public function addGameWith(Team $team, Group $group) { |
| 85 | - if (!isset($this->gamesWith[$group->getId()][$team->getId()])) $this->gamesWith[$group->getId()][$team->getId()] = 0; |
|
| 87 | + if (!isset($this->gamesWith[$group->getId()][$team->getId()])) { |
|
| 88 | + $this->gamesWith[$group->getId()][$team->getId()] = 0; |
|
| 89 | + } |
|
| 86 | 90 | $this->gamesWith[$group->getId()][$team->getId()]++; |
| 87 | 91 | return $this; |
| 88 | 92 | } |
| 89 | 93 | public function addGroup(Group $group) { |
| 90 | - if (!isset($this->games[$group->getId()])) $this->games[$group->getId()] = []; |
|
| 94 | + if (!isset($this->games[$group->getId()])) { |
|
| 95 | + $this->games[$group->getId()] = []; |
|
| 96 | + } |
|
| 91 | 97 | return $this; |
| 92 | 98 | } |
| 93 | 99 | public function addGame(Game $game) { |
| 94 | 100 | $group = $game->getGroup(); |
| 95 | - if (!isset($this->games[$group->getId()])) $this->games[$group->getId()] = []; |
|
| 101 | + if (!isset($this->games[$group->getId()])) { |
|
| 102 | + $this->games[$group->getId()] = []; |
|
| 103 | + } |
|
| 96 | 104 | $this->games[$group->getId()][] = $game; |
| 97 | 105 | return $this; |
| 98 | 106 | } |
@@ -105,70 +113,90 @@ discard block |
||
| 105 | 113 | } |
| 106 | 114 | |
| 107 | 115 | public function addWin(string $groupId = ''){ |
| 108 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 116 | + if (!isset($this->groupResults[$groupId])) { |
|
| 117 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 118 | + } |
|
| 109 | 119 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->winPoints; |
| 110 | 120 | $this->sumPoints += $this->groupResults[$groupId]['group']->winPoints; |
| 111 | 121 | $this->groupResults[$groupId]['wins']++; |
| 112 | 122 | return $this; |
| 113 | 123 | } |
| 114 | 124 | public function removeWin(string $groupId = ''){ |
| 115 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 125 | + if (!isset($this->groupResults[$groupId])) { |
|
| 126 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 127 | + } |
|
| 116 | 128 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->winPoints; |
| 117 | 129 | $this->sumPoints -= $this->groupResults[$groupId]['group']->winPoints; |
| 118 | 130 | $this->groupResults[$groupId]['wins']--; |
| 119 | 131 | return $this; |
| 120 | 132 | } |
| 121 | 133 | public function addDraw(string $groupId = ''){ |
| 122 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 134 | + if (!isset($this->groupResults[$groupId])) { |
|
| 135 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 136 | + } |
|
| 123 | 137 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->drawPoints; |
| 124 | 138 | $this->sumPoints += $this->groupResults[$groupId]['group']->drawPoints; |
| 125 | 139 | $this->groupResults[$groupId]['draws']++; |
| 126 | 140 | return $this; |
| 127 | 141 | } |
| 128 | 142 | public function removeDraw(string $groupId = ''){ |
| 129 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 143 | + if (!isset($this->groupResults[$groupId])) { |
|
| 144 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 145 | + } |
|
| 130 | 146 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->drawPointsPoints; |
| 131 | 147 | $this->sumPoints -= $this->groupResults[$groupId]['group']->drawPoints; |
| 132 | 148 | $this->groupResults[$groupId]['draws']--; |
| 133 | 149 | return $this; |
| 134 | 150 | } |
| 135 | 151 | public function addLoss(string $groupId = ''){ |
| 136 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 152 | + if (!isset($this->groupResults[$groupId])) { |
|
| 153 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 154 | + } |
|
| 137 | 155 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->lostPoints; |
| 138 | 156 | $this->sumPoints += $this->groupResults[$groupId]['group']->lostPoints; |
| 139 | 157 | $this->groupResults[$groupId]['losses']++; |
| 140 | 158 | return $this; |
| 141 | 159 | } |
| 142 | 160 | public function removeLoss(string $groupId = ''){ |
| 143 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 161 | + if (!isset($this->groupResults[$groupId])) { |
|
| 162 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 163 | + } |
|
| 144 | 164 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->lostPoints; |
| 145 | 165 | $this->sumPoints -= $this->groupResults[$groupId]['group']->lostPoints; |
| 146 | 166 | $this->groupResults[$groupId]['losses']--; |
| 147 | 167 | return $this; |
| 148 | 168 | } |
| 149 | 169 | public function addSecond(string $groupId = ''){ |
| 150 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 170 | + if (!isset($this->groupResults[$groupId])) { |
|
| 171 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 172 | + } |
|
| 151 | 173 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->secondPoints; |
| 152 | 174 | $this->sumPoints += $this->groupResults[$groupId]['group']->secondPoints; |
| 153 | 175 | $this->groupResults[$groupId]['second']++; |
| 154 | 176 | return $this; |
| 155 | 177 | } |
| 156 | 178 | public function removeSecond(string $groupId = ''){ |
| 157 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 179 | + if (!isset($this->groupResults[$groupId])) { |
|
| 180 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 181 | + } |
|
| 158 | 182 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->secondPoints; |
| 159 | 183 | $this->sumPoints -= $this->groupResults[$groupId]['group']->secondPoints; |
| 160 | 184 | $this->groupResults[$groupId]['second']--; |
| 161 | 185 | return $this; |
| 162 | 186 | } |
| 163 | 187 | public function addThird(string $groupId = ''){ |
| 164 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 188 | + if (!isset($this->groupResults[$groupId])) { |
|
| 189 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 190 | + } |
|
| 165 | 191 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->thirdPoints; |
| 166 | 192 | $this->sumPoints += $this->groupResults[$groupId]['group']->thirdPoints; |
| 167 | 193 | $this->groupResults[$groupId]['third']++; |
| 168 | 194 | return $this; |
| 169 | 195 | } |
| 170 | 196 | public function removeThird(string $groupId = ''){ |
| 171 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 197 | + if (!isset($this->groupResults[$groupId])) { |
|
| 198 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 199 | + } |
|
| 172 | 200 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->thirdPoints; |
| 173 | 201 | $this->sumPoints -= $this->groupResults[$groupId]['group']->thirdPoints; |
| 174 | 202 | $this->groupResults[$groupId]['third']--; |
@@ -176,7 +204,9 @@ discard block |
||
| 176 | 204 | } |
| 177 | 205 | |
| 178 | 206 | public function sumPoints(array $groupIds = []) { |
| 179 | - if (count($groupIds) === 0) return $this->sumPoints; |
|
| 207 | + if (count($groupIds) === 0) { |
|
| 208 | + return $this->sumPoints; |
|
| 209 | + } |
|
| 180 | 210 | $sum = 0; |
| 181 | 211 | foreach ($groupIds as $gid) { |
| 182 | 212 | $sum += $this->groupResults[$gid]['points'] ?? 0; |
@@ -184,7 +214,9 @@ discard block |
||
| 184 | 214 | return $sum; |
| 185 | 215 | } |
| 186 | 216 | public function sumScore(array $groupIds = []) { |
| 187 | - if (count($groupIds) === 0) return $this->sumScore; |
|
| 217 | + if (count($groupIds) === 0) { |
|
| 218 | + return $this->sumScore; |
|
| 219 | + } |
|
| 188 | 220 | $sum = 0; |
| 189 | 221 | foreach ($groupIds as $gid) { |
| 190 | 222 | $sum += $this->groupResults[$gid]['score'] ?? 0; |
@@ -33,11 +33,17 @@ discard block |
||
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | public function progress(bool $blank = false) { |
| 36 | - if ($blank) $teams = $this->from->isPlayed() ? $this->from->sortTeams($this->filters) : $this->from->simulate($this->filters); |
|
| 37 | - else $teams = $this->from->sortTeams($this->filters); |
|
| 36 | + if ($blank) { |
|
| 37 | + $teams = $this->from->isPlayed() ? $this->from->sortTeams($this->filters) : $this->from->simulate($this->filters); |
|
| 38 | + } else { |
|
| 39 | + $teams = $this->from->sortTeams($this->filters); |
|
| 40 | + } |
|
| 38 | 41 | |
| 39 | - if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) $next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len)); |
|
| 40 | - else $next = $teams; |
|
| 42 | + if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) { |
|
| 43 | + $next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len)); |
|
| 44 | + } else { |
|
| 45 | + $next = $teams; |
|
| 46 | + } |
|
| 41 | 47 | |
| 42 | 48 | $i = 1; |
| 43 | 49 | |
@@ -45,12 +51,15 @@ discard block |
||
| 45 | 51 | if ($blank) { |
| 46 | 52 | $this->to->addTeam(new BlankTeam($this.' - '.$i, $team)); |
| 47 | 53 | $i++; |
| 54 | + } else { |
|
| 55 | + $team->sumPoints += $this->from->progressPoints; |
|
| 48 | 56 | } |
| 49 | - else $team->sumPoints += $this->from->progressPoints; |
|
| 50 | 57 | } |
| 51 | 58 | |
| 52 | 59 | $this->from->addProgressed($next); |
| 53 | - if (!$blank) $this->to->addTeam($next); |
|
| 60 | + if (!$blank) { |
|
| 61 | + $this->to->addTeam($next); |
|
| 62 | + } |
|
| 54 | 63 | return $this; |
| 55 | 64 | } |
| 56 | 65 | |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | $this->name = $name; |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | - public function addRound(Round ...$rounds){ |
|
| 22 | + public function addRound(Round ...$rounds) { |
|
| 23 | 23 | foreach ($rounds as $round) { |
| 24 | 24 | if ($round instanceof Round) $this->rounds[] = $round; |
| 25 | 25 | else throw new \Exception('Trying to add round which is not an instance of Round class.'); |
@@ -31,15 +31,15 @@ discard block |
||
| 31 | 31 | $this->rounds[] = $r->setSkip($this->allowSkip); |
| 32 | 32 | return $r; |
| 33 | 33 | } |
| 34 | - public function getRounds(){ |
|
| 34 | + public function getRounds() { |
|
| 35 | 35 | return $this->rounds; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - public function allowSkip(){ |
|
| 38 | + public function allowSkip() { |
|
| 39 | 39 | $this->allowSkip = true; |
| 40 | 40 | return $this; |
| 41 | 41 | } |
| 42 | - public function disallowSkip(){ |
|
| 42 | + public function disallowSkip() { |
|
| 43 | 43 | $this->allowSkip = false; |
| 44 | 44 | return $this; |
| 45 | 45 | } |
@@ -21,8 +21,11 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | public function addRound(Round ...$rounds){ |
| 23 | 23 | foreach ($rounds as $round) { |
| 24 | - if ($round instanceof Round) $this->rounds[] = $round; |
|
| 25 | - else throw new \Exception('Trying to add round which is not an instance of Round class.'); |
|
| 24 | + if ($round instanceof Round) { |
|
| 25 | + $this->rounds[] = $round; |
|
| 26 | + } else { |
|
| 27 | + throw new \Exception('Trying to add round which is not an instance of Round class.'); |
|
| 28 | + } |
|
| 26 | 29 | } |
| 27 | 30 | return $this; |
| 28 | 31 | } |
@@ -63,7 +66,9 @@ discard block |
||
| 63 | 66 | return $t; |
| 64 | 67 | } |
| 65 | 68 | public function getTeams() { |
| 66 | - if (count($this->teams) > 0) return $this->teams; |
|
| 69 | + if (count($this->teams) > 0) { |
|
| 70 | + return $this->teams; |
|
| 71 | + } |
|
| 67 | 72 | $teams = []; |
| 68 | 73 | foreach ($this->rounds as $round) { |
| 69 | 74 | $teams = array_merge($teams, $round->getTeams()); |
@@ -82,7 +87,9 @@ discard block |
||
| 82 | 87 | |
| 83 | 88 | public function splitTeams(...$rounds) { |
| 84 | 89 | |
| 85 | - if (count($rounds) === 0) $rounds = $this->getRounds(); |
|
| 90 | + if (count($rounds) === 0) { |
|
| 91 | + $rounds = $this->getRounds(); |
|
| 92 | + } |
|
| 86 | 93 | |
| 87 | 94 | $teams = $this->getTeams(); |
| 88 | 95 | shuffle($teams); |
@@ -102,7 +109,9 @@ discard block |
||
| 102 | 109 | |
| 103 | 110 | public function genGamesSimulate() { |
| 104 | 111 | $games = []; |
| 105 | - if (count($this->rounds) <= 0) throw new \Exception('There are no rounds to simulate games from.'); |
|
| 112 | + if (count($this->rounds) <= 0) { |
|
| 113 | + throw new \Exception('There are no rounds to simulate games from.'); |
|
| 114 | + } |
|
| 106 | 115 | foreach ($this->rounds as $round) { |
| 107 | 116 | $games = array_merge($games, $round->genGames()); |
| 108 | 117 | $round->simulate()->progress(true)->resetGames(); |
@@ -30,7 +30,7 @@ |
||
| 30 | 30 | |
| 31 | 31 | $this->splitTeams($round1); |
| 32 | 32 | |
| 33 | - if (count($this->getTeams()) % 4 == 2) { |
|
| 33 | + if (count($this->getTeams())%4 == 2) { |
|
| 34 | 34 | $group_top = $round2->group('TOP')->setType(\TournamentGenerator\Constants::ROUND_TWO); |
| 35 | 35 | |
| 36 | 36 | $filter_win_2 = new \TournamentGenerator\TeamFilter('wins', '=', 2, [$group_0_0, $group_top]); |
@@ -12,7 +12,9 @@ |
||
| 12 | 12 | |
| 13 | 13 | public function generate() { |
| 14 | 14 | |
| 15 | - if (count($this->getTeams()) === 0) throw new \Exception('Couldn\'t generate 2R2G tournament because there are no teams in the tournament.'); |
|
| 15 | + if (count($this->getTeams()) === 0) { |
|
| 16 | + throw new \Exception('Couldn\'t generate 2R2G tournament because there are no teams in the tournament.'); |
|
| 17 | + } |
|
| 16 | 18 | |
| 17 | 19 | |
| 18 | 20 | $round1 = $this->round('Round 1'); |
@@ -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,17 +27,17 @@ 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('Round 1 '.$i)->setInGame(2)->setType(\TournamentGenerator\Constants::ROUND_TWO); |
| 32 | 32 | $previousGroups[] = $g; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | $this->splitTeams(); |
| 36 | 36 | |
| 37 | - for ($r=2; $r <= $roundsNum; $r++) { |
|
| 37 | + for ($r = 2; $r <= $roundsNum; $r++) { |
|
| 38 | 38 | $groups = []; |
| 39 | 39 | $round = $this->round('Round '.$r); |
| 40 | - for ($g=1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) { |
|
| 40 | + for ($g = 1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) { |
|
| 41 | 41 | $group = $round->group('Round '.$r.' - '.$g)->setInGame(2)->setType(\TournamentGenerator\Constants::ROUND_TWO); |
| 42 | 42 | $groups[] = $group; |
| 43 | 43 | array_shift($previousGroups)->progression($group, 0, 1); // PROGRESS FROM GROUP BEFORE |
@@ -13,7 +13,9 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | $countTeams = count($this->getTeams()); |
| 15 | 15 | |
| 16 | - if ($countTeams < 3) throw new \Exception('Double elimination is possible for minimum of 3 teams - '.$countTeams.' teams given.'); |
|
| 16 | + if ($countTeams < 3) { |
|
| 17 | + throw new \Exception('Double elimination is possible for minimum of 3 teams - '.$countTeams.' teams given.'); |
|
| 18 | + } |
|
| 17 | 19 | |
| 18 | 20 | |
| 19 | 21 | // CALCULATE BYES |
@@ -131,15 +133,19 @@ discard block |
||
| 131 | 133 | if ($r === 2) { // FIRST LOSING ROUND |
| 132 | 134 | $previousGroups[2*($g-1)]->progression($group, 1, 1); // PROGRESS FROM STARTING GROUP |
| 133 | 135 | $previousGroups[(2*($g-1))+1]->progression($group, 1, 1); // PROGREESS FROM STARTING GROUP |
| 134 | - } |
|
| 135 | - elseif ($losingGroupTeamsCount >= 2) { |
|
| 136 | + } elseif ($losingGroupTeamsCount >= 2) { |
|
| 136 | 137 | $previousLosingGroups[$g-1]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE |
| 137 | - if (isset(array_reverse($previousGroups)[$g-1])) array_reverse($previousGroups)[$g-1]->progression($group, 1, 1); // PROGREESS FROM WINNING GROUP BEFORE |
|
| 138 | - else $previousLosingGroups[$g]->progression($group, 0, 1); // PROGRESS OTHER TEAM FROM LOSING GROUP BEEFORE |
|
| 138 | + if (isset(array_reverse($previousGroups)[$g-1])) { |
|
| 139 | + array_reverse($previousGroups)[$g-1]->progression($group, 1, 1); |
|
| 140 | + } |
|
| 141 | + // PROGREESS FROM WINNING GROUP BEFORE |
|
| 142 | + else { |
|
| 143 | + $previousLosingGroups[$g]->progression($group, 0, 1); |
|
| 144 | + } |
|
| 145 | + // PROGRESS OTHER TEAM FROM LOSING GROUP BEEFORE |
|
| 139 | 146 | } |
| 140 | 147 | } |
| 141 | - } |
|
| 142 | - else { // IF THE NUMBER OF TEAMS IS NOT A POWER OF 2, GENERATE GROUPS WITH BYES |
|
| 148 | + } else { // IF THE NUMBER OF TEAMS IS NOT A POWER OF 2, GENERATE GROUPS WITH BYES |
|
| 143 | 149 | // LOOK FOR THE CLOSEST LOWER POWER OF 2 |
| 144 | 150 | $losingByes = $losingGroupTeamsCount-bindec(str_pad(1, strlen(decbin($losingGroupTeamsCount)), 0, STR_PAD_RIGHT)); |
| 145 | 151 | $n = (floor(count($previousLosingGroups)/2)+$losingByes); |
@@ -163,10 +169,12 @@ discard block |
||
| 163 | 169 | if (in_array($g, $byesGroupsNums) && isset($previousGroups[$byesProgressed])) { // EMPTY GROUP FROM BYE |
| 164 | 170 | $previousGroups[$byesProgressed]->progression($group, 1, 1); // PROGRESS FROM WINNING GROUP BEFORE |
| 165 | 171 | $byesProgressed++; |
| 166 | - } |
|
| 167 | - else { |
|
| 172 | + } else { |
|
| 168 | 173 | $previousLosingGroups[$lastGroup]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE |
| 169 | - if (isset($previousLosingGroups[$lastGroup + 1])) $previousLosingGroups[$lastGroup + 1]->progression($group, 0, 1); // PROGREESS FROM LOSING GROUP BEFORE |
|
| 174 | + if (isset($previousLosingGroups[$lastGroup + 1])) { |
|
| 175 | + $previousLosingGroups[$lastGroup + 1]->progression($group, 0, 1); |
|
| 176 | + } |
|
| 177 | + // PROGREESS FROM LOSING GROUP BEFORE |
|
| 170 | 178 | $lastGroup += 2; |
| 171 | 179 | } |
| 172 | 180 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | $groupIds = []; |
| 32 | 32 | $allGroups = []; |
| 33 | 33 | |
| 34 | - for ($i=1; $i <= $startGroups; $i++) { |
|
| 34 | + for ($i = 1; $i <= $startGroups; $i++) { |
|
| 35 | 35 | $g = $startRound->group('Start group - '.$i)->setInGame(2)->setType(\TournamentGenerator\Constants::ROUND_TWO); |
| 36 | 36 | $allGroups[] = $g; |
| 37 | 37 | $groupIds[] = $g->getId(); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | // SPLIT TEAMS EVENLY |
| 42 | 42 | $this->splitTeams(); |
| 43 | 43 | |
| 44 | - for ($r=2; $r <= $roundsNum-1; $r++) { |
|
| 44 | + for ($r = 2; $r <= $roundsNum-1; $r++) { |
|
| 45 | 45 | $groups = []; |
| 46 | 46 | $losingGroups = []; |
| 47 | 47 | $round = $this->round('Round '.$r); |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | private function calcByes(int $countTeams, int &$nextPow) { |
| 76 | 76 | $byes = 0; |
| 77 | 77 | $nextPow = $countTeams; |
| 78 | - if ( !\TournamentGenerator\isPowerOf2($countTeams) ) { |
|
| 78 | + if (!\TournamentGenerator\isPowerOf2($countTeams)) { |
|
| 79 | 79 | $nextPow = bindec(str_pad(1, strlen(decbin($countTeams))+1, 0, STR_PAD_RIGHT)); |
| 80 | 80 | $byes = $nextPow-$countTeams; |
| 81 | 81 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | } |
| 84 | 84 | private function generateWinSide(int &$r, int &$byes, int &$countTeams, \TournamentGenerator\Round &$round, array &$allGroups, array &$groups, \TournamentGenerator\Group &$lastWinningGroup = null, array &$previousGroups = []) { |
| 85 | 85 | $order = 1; |
| 86 | - for ($g=1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) { |
|
| 86 | + for ($g = 1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) { |
|
| 87 | 87 | $group = $round->group('Round '.$r.' - win '.$g)->setInGame(2)->setType(\TournamentGenerator\Constants::ROUND_TWO)->setOrder($order); |
| 88 | 88 | $allGroups[] = $group; |
| 89 | 89 | $order += 2; |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | $losingGroupTeamsCount = count($previousLosingGroups)+count($previousGroups); |
| 99 | 99 | $order = 2; |
| 100 | 100 | if (\TournamentGenerator\isPowerOf2($losingGroupTeamsCount)) { // IF THE NUMBER OF TEAMS IS A POWER OF 2, GENERATE GROUPS WITHOUT BYES |
| 101 | - for ($g=1; $g <= $losingGroupTeamsCount/2; $g++) { |
|
| 101 | + for ($g = 1; $g <= $losingGroupTeamsCount/2; $g++) { |
|
| 102 | 102 | $group = $round->group('Round '.$r.' - loss '.$g)->setInGame(2)->setType(\TournamentGenerator\Constants::ROUND_TWO)->setOrder($order); |
| 103 | 103 | $allGroups[] = $group; |
| 104 | 104 | $order += 2; |
@@ -121,11 +121,11 @@ discard block |
||
| 121 | 121 | $n = (floor(count($previousLosingGroups)/2)+$losingByes); |
| 122 | 122 | $byesGroupsNums = []; |
| 123 | 123 | $byesProgressed = 0; |
| 124 | - for ($i=0; $i < $losingByes; $i++) { |
|
| 124 | + for ($i = 0; $i < $losingByes; $i++) { |
|
| 125 | 125 | $byesGroupsNums[] = $n-($i*2); |
| 126 | 126 | } |
| 127 | 127 | $lastGroup = 0; |
| 128 | - for ($g=1; $g <= ((count($previousLosingGroups)/2)+$losingByes); $g++) { |
|
| 128 | + for ($g = 1; $g <= ((count($previousLosingGroups)/2)+$losingByes); $g++) { |
|
| 129 | 129 | $group = $round->group('Round '.$r.' - loss '.$g)->setInGame(2)->setType(\TournamentGenerator\Constants::ROUND_TWO)->setOrder($order); |
| 130 | 130 | $allGroups[] = $group; |
| 131 | 131 | $order += 2; |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | } |
| 138 | 138 | else { |
| 139 | 139 | $previousLosingGroups[$lastGroup]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE |
| 140 | - if (isset($previousLosingGroups[$lastGroup + 1])) $previousLosingGroups[$lastGroup + 1]->progression($group, 0, 1); // PROGREESS FROM LOSING GROUP BEFORE |
|
| 140 | + if (isset($previousLosingGroups[$lastGroup+1])) $previousLosingGroups[$lastGroup+1]->progression($group, 0, 1); // PROGREESS FROM LOSING GROUP BEFORE |
|
| 141 | 141 | $lastGroup += 2; |
| 142 | 142 | } |
| 143 | 143 | } |