コード例 #1
0
ファイル: Pool.php プロジェクト: abienvenu/kyjoukan
 /**
  * Add games
  *
  * @param Game $game
  * @return Pool
  */
 public function addGame(Game $game)
 {
     $this->games[] = $game;
     $game->setPool($this);
     return $this;
 }
コード例 #2
0
 /**
  * Populate $newGame with the lazyiest teams in $pool
  *
  * @param Game $newGame
  * @param Pool $pool
  */
 private function setLazyiestTeams(Game $newGame, Pool $pool)
 {
     // Order the teams from the lazyiest to the busyiest
     $teams = $pool->getTeams()->toArray();
     usort($teams, function (Team $a, Team $b) use($pool) {
         return $pool->getTeamNbParticipations($a) > $pool->getTeamNbParticipations($b);
     });
     // Try to schedule the lazyiest team first
     foreach ($teams as $team1) {
         // Is the team already playing in this round ?
         if ($newGame->getRound()->hasTeam($team1)) {
             continue;
         }
         foreach ($teams as $team2) {
             if ($team1 == $team2 || $newGame->getRound()->hasTeam($team2)) {
                 continue;
             }
             if ($pool->hasGame($team1, $team2)) {
                 continue;
             }
             // We found a viable match!
             $newGame->setTeam1($team1);
             $newGame->setTeam2($team2);
             return;
         }
     }
 }