public function run(array &$data)
 {
     $data['template'] = $this->getTemplate();
     $this->addCurrentGameInfo($data);
     // get Model Data
     /** @var $iig ModelIsInGameInfo */
     $iig = ModelIsInGameInfo::getIsInGameInfo(ModelUser::getCurrentUser()->getId(), ModelGame::getCurrentGame()->getId());
     $this->id_set = $iig->getIdStartingSet();
     $this->possibleStartRegions = ModelStartRegion::getRegionsForSet($this->id_set);
     // array(int id_opttype => array(int option_number => array(int id_area => ModelStartRegion)))
     // update moves
     if (isset($_POST['selectstart'])) {
         $this->selectOption($data);
     }
     if (isset($_POST['fixate_start'])) {
         $this->fixateMove($data);
     }
     // parse moves
     $this->checkFixate($data, PHASE_SELECTSTART);
     $this->checkCurrentPhase($data, PHASE_SELECTSTART);
     $this->parseOptions($data);
 }
 /**
  * fixates the move if no error occured
  *
  * @throws ControllerException
  * @return void
  */
 public function finishMove()
 {
     if ($this->error) {
         return;
     }
     // check if every option has taken countries
     $move = ModelSelectStartMove::getSelectStartMoveForUser($this->id_user, $this->id_game);
     $regions_selected = $move->getRegions();
     // array(int option_number => array(int id_zarea))
     // get Model Data
     /** @var $iig ModelIsInGameInfo */
     $iig = ModelIsInGameInfo::getIsInGameInfo($this->id_user, $this->id_game);
     $id_set = $iig->getIdStartingSet();
     $regions = ModelStartRegion::getRegionsForSet($id_set);
     // array(int id_opttype => array(int option_number => array(int id_area => ModelStartRegion)))
     foreach ($regions as $opttype) {
         foreach ($opttype as $opt_number => $areas) {
             if (!isset($regions_selected[$opt_number])) {
                 throw new ControllerException('Choose countries first.');
             }
         }
     }
     $this->fixatePhase(true);
 }
 /**
  * run the game logic
  *
  * @throws LogicException
  * @return void
  */
 public function run()
 {
     if (!$this->checkIfValid()) {
         throw new LogicException('Game ' . $this->id_game . ' not valid for processing.');
     }
     $this->startProcessing();
     try {
         // run through moves for each user
         $iter = ModelSelectStartMove::iterator($this->id_game);
         while ($iter->hasNext()) {
             // areas to select for user
             $selectStartMove = $iter->next();
             $regions_selected = $selectStartMove->getRegions();
             // array(int option_number => array(int id_zarea))
             $id_user = $selectStartMove->getIdUser();
             /* @var $iigi ModelIsInGameInfo */
             $iigi = ModelIsInGameInfo::getIsInGameInfo($id_user, $this->id_game);
             $id_set = $iigi->getIdStartingSet();
             foreach ($regions_selected as $option_number => $areas) {
                 $regions = ModelStartRegion::getRegionsForSetAndOption($id_set, $option_number);
                 // array(int id_area => ModelStartRegion)
                 foreach ($areas as $id_zarea) {
                     $gameArea = ModelGameArea::getGameArea($this->id_game, $id_zarea);
                     $id_area = $gameArea->getIdArea();
                     /* @var $region ModelStartRegion */
                     $region = $regions[$id_area];
                     $id_option = $region->getIdOptionType();
                     $unit_count = ModelOptionType::getOptionType($id_option)->getUnits();
                     // set user for game area
                     $gameArea->setIdUser($id_user);
                     // create units for user
                     $iterUnits = ModelLandUnit::iterator();
                     while ($iterUnits->hasNext()) {
                         $landUnit = $iterUnits->next();
                         $id_unit = $landUnit->getId();
                         $inGameLandUnit = ModelInGameLandUnit::getModelByIdZAreaUserUnit($this->id_game, $id_zarea, $id_user, $id_unit);
                         $inGameLandUnit->setCount($unit_count);
                     }
                 }
             }
         }
         // add units to all empty game-areas
         $iter = ModelGameArea::iterator(NEUTRAL_COUNTRY, $this->id_game);
         while ($iter->hasNext()) {
             /* @var $gameArea ModelGameArea */
             $gameArea = $iter->next();
             if ($gameArea->getIdType() !== TYPE_LAND) {
                 continue;
             }
             $count = $gameArea->getProductivity();
             if ($gameArea->getIdResource() === RESOURCE_OIL) {
                 ++$count;
             }
             $iterUnits = ModelLandUnit::iterator();
             while ($iterUnits->hasNext()) {
                 $landUnit = $iterUnits->next();
                 $id_unit = $landUnit->getId();
                 $inGameLandUnit = ModelInGameLandUnit::getModelByIdZAreaUserUnit($this->id_game, $gameArea->getId(), NEUTRAL_COUNTRY, $id_unit);
                 $inGameLandUnit->setCount($count);
             }
         }
         $this->finishProcessing();
     } catch (\Exception $ex) {
         $this->logger->fatal($ex);
         $this->rollback();
     }
 }