/**
  * create round gears for each round in tournament
  *
  * @param Tournament $tournament
  *
  * @return RoundGearsInterface[]
  */
 public function initializeGears(Tournament $tournament)
 {
     $gears = array();
     $setup = $tournament->getSetup();
     $roundNumber = 0;
     $seedGears = $this->roundGearsFactory->create($tournament, $roundNumber, $setup->getSeed());
     $gears[] = $seedGears;
     $previous = $seedGears;
     foreach ($setup->getRounds() as $roundSetup) {
         $roundGears = $this->roundGearsFactory->create($tournament, ++$roundNumber, $roundSetup);
         $roundGears->setPreviousRoundGears($previous);
         $gears[] = $roundGears;
         $previous = $roundGears;
     }
     $this->entityManager->flush();
     return $gears;
 }
Example #2
0
 /**
  * @param Tournament          $tournament
  * @param int                 $roundNumber
  * @param RoundSetupInterface $roundSetup
  *
  * @return RoundGearsInterface
  */
 public function create(Tournament $tournament, $roundNumber, RoundSetupInterface $roundSetup)
 {
     $round = $tournament->getRoundByNumber($roundNumber);
     if (null === $round) {
         $round = new Round($tournament, $roundNumber);
         $this->entityManager->persist($round);
     }
     if ($roundSetup instanceof RoundSetupAva) {
         $gears = new RoundGearsAva($round, $roundSetup);
     } elseif ($roundSetup instanceof RoundSetupBvw) {
         $gears = new RoundGearsBvw($round, $roundSetup);
     } elseif ($roundSetup instanceof RoundSetupNull) {
         $gears = new RoundGearsNull($round, $roundSetup);
     } elseif ($roundSetup instanceof RoundSetupSeed) {
         $gears = new RoundGearsSeed($round, $roundSetup);
     } else {
         throw new \InvalidArgumentException('can not create round-gears for ' . get_class($roundSetup));
     }
     $gears->setGameGearsFactory($this->gameGearsFactory);
     $gears->setLogger($this->logger);
     $this->eventDispatcher->addSubscriber($gears);
     $this->entityManager->flush();
     return $gears;
 }
Example #3
0
 /**
  * @param FormBuilderInterface $builder
  * @param array $options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $tournamentModeChoices = array();
     foreach (Tournament::getTournamentModes() as $mode) {
         $tournamentModeChoices[$mode] = 'tournament.tournament_mode.' . $mode . '.label';
     }
     $gameModeChoices = array();
     foreach (Tournament::getGameModes() as $mode) {
         $gameModeChoices[$mode] = 'tournament.game_mode.' . $mode . '.label';
     }
     $legModeChoices = array();
     foreach (Tournament::getLegModes() as $mode) {
         $legModeChoices[$mode] = 'tournament.leg_mode.' . $mode . '.label';
     }
     $builder->add('name', 'text', array('label' => 'tournament.name'))->add('tournamentMode', 'choice', array('label' => 'tournament.tournament_mode.choose', 'expanded' => true, 'choices' => $tournamentModeChoices))->add('tournamentCount', 'integer', array('label' => 'tournament.tournament_count.choose'))->add('gameMode', 'choice', array('label' => 'tournament.game_mode.choose', 'expanded' => true, 'choices' => $gameModeChoices))->add('gameCount', 'integer', array('label' => 'tournament.game_count.choose'))->add('legMode', 'choice', array('label' => 'tournament.leg_mode.choose', 'expanded' => true, 'choices' => $legModeChoices))->add('boards', 'entity', array('label' => 'tournament.board.choose', 'multiple' => true, 'expanded' => true, 'class' => 'Fda\\BoardBundle\\Entity\\Board', 'property' => 'name'))->add('players', 'entity', array('label' => 'tournament.player.choose', 'multiple' => true, 'expanded' => true, 'class' => 'Fda\\PlayerBundle\\Entity\\Player', 'property' => 'name'));
 }
Example #4
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     /** @var Board[] $boards */
     $boards = array($this->getReference('board-0'));
     /** @var Player[] $players */
     $players = array($this->getReference('player-0'), $this->getReference('player-1'), $this->getReference('player-2'));
     $tournamentSetup = new TournamentSetup();
     $tournamentSetup->setSeed(RoundSetupSeed::create([[$players[0]->getId(), $players[1]->getId(), $players[2]->getId()]]));
     $round1 = RoundSetupAva::createStraight();
     $round1->setGameMode(new GameMode(GameMode::FIRST_TO, 1));
     $round1->setLegMode(new LegMode(LegMode::SINGLE_OUT_301));
     $tournamentSetup->addRound($round1);
     $tournament = new Tournament();
     $tournament->setName('real simple');
     $tournament->setSetup($tournamentSetup);
     $tournament->setBoards($boards);
     $tournament->setPlayers($players);
     $this->setReference('tournament-0', $tournament);
     $manager->persist($tournament);
     $manager->flush();
 }
 protected function getRealSimpleTournament()
 {
     /** @var Board[] $boards */
     $boards = array($this->fixtures->getReference('board-0'));
     /** @var Player[] $players */
     $players = array($this->fixtures->getReference('player-0'), $this->fixtures->getReference('player-1'), $this->fixtures->getReference('player-2'));
     $tournamentSetup = new TournamentSetup();
     $tournamentSetup->setSeed(RoundSetupSeed::create([[$players[0]->getId(), $players[1]->getId(), $players[2]->getId()]]));
     $round1 = RoundSetupAva::createStraight();
     $round1->setGameMode(new GameMode(GameMode::FIRST_TO, 3));
     $round1->setLegMode(new LegMode(LegMode::SINGLE_OUT_301));
     $tournamentSetup->addRound($round1);
     $tournament = new Tournament();
     $tournament->setName('real simple');
     $tournament->setSetup($tournamentSetup);
     $tournament->setBoards($boards);
     $tournament->setPlayers($players);
     /** @var \Doctrine\ORM\EntityManager $entityManager */
     $entityManager = $this->getContainer()->get('doctrine.orm.default_entity_manager');
     $entityManager->persist($tournament);
     return $tournament;
 }
Example #6
0
 /**
  * @param PlayerManager $playerManager to resolve player-IDs
  * @return Tournament
  * @throws \Exception
  */
 public function createTournament(PlayerManager $playerManager)
 {
     if ($this->preset == self::PRESET_TEST) {
         $setup = PresetTesting::create($this->getPlayerIdsGrouped());
     } elseif ($this->preset == self::PRESET_SIMPLE) {
         $setup = PresetSimple::create($this->getPlayerIdsGrouped());
         // TODO implement missing presets
         //        } elseif ($this->preset == self::PRESET_FULL) {
         //            $setup = PresetFull::create($this->numberOfGroups);
         //        } elseif ($this->preset == self::PRESET_LEAGUE) {
         //            $setup = PresetLeague::create($this->numberOfGroups);
     } else {
         throw new \Exception('TODO');
     }
     $tournament = new Tournament();
     $tournament->setName($this->name);
     $tournament->setSetup($setup);
     $tournament->setBoards($this->boards);
     $players = array();
     foreach ($this->getPlayerIds() as $playerId) {
         $players[] = $playerManager->getPlayer($playerId);
     }
     $tournament->setPlayers($players);
     return $tournament;
 }