Exemplo n.º 1
0
 public function start()
 {
     // Start tournament's first round
     $players = $this->get_players();
     // Copy array so we can shift it to create games
     $nbplayers = count($players);
     if ($nbplayers < 2) {
         return $this->end();
     }
     $theorical = Tournament::rounds_number($nbplayers);
     if (!is_numeric($this->data->rounds_number)) {
         $this->data->rounds_number = $theorical;
     } else {
         // Set at least the number of rounds implied by players
         $this->data->rounds_number = max($this->data->rounds_number, $theorical);
     }
     $this->commit('data');
     // Update tournament
     $this->set_status(5);
     $this->log('', 'start', '');
     // Start first round
     shuffle($players);
     $matches = array();
     while (count($players) > 1) {
         $creator = array_shift($players);
         $joiner = array_shift($players);
         $matches[] = array($creator, $joiner);
     }
     while (count($players) > 0) {
         $bye = array_shift($players);
         $matches[] = array($bye, null);
     }
     $this->start_games($matches);
 }