/**
  * At this point the game has been created and registered - but the player has not chosen a group.
  * Note -- if they walk away they will be a player without a group -- not a good thing!
  */
 public function run()
 {
     $c = $this->get_controller();
     if (!$c->_prep()) {
         $params = array('error' => 'Cannot start game');
         return $this->forward('index', NULL, NULL, $params);
     }
     //@TODO: make sure the groups are not already owned! hell is other players
     $t = Ultimatum_Model_Ultgroups::getInstance()->table();
     $sql = sprintf('SELECT %s FROM %s', $t->idField(), $t->tableName());
     $ids = $t->getAdapter()->fetchCol($sql);
     $group_ids = Zupal_Util_Array::random_set($ids, 4);
     $game_id = $this->view()->game->identity();
     foreach ($group_ids as $id) {
         $groups[] = $group = Ultimatum_Model_Ultgroups::getInstance()->get($id);
         $gamegroup = new Ultimatum_Model_Ultgamegroups();
         $gamegroup->game = $game_id;
         $gamegroup->group_id = $id;
         $gamegroup->save();
         // note -- will be saved with no owner.
         $gamegroup->start_size();
         $scans[] = $this->view()->player->scan_group($group);
     }
     $this->view()->groups = $groups;
     $this->view()->scans = $scans;
 }
 /**
  *
  * @param int $pWalks = 10
  * @return int
  */
 public function randomize($pWalks = 4)
 {
     $keys = array('offense', 'defense', 'growth', 'network');
     $this->offense = $this->defense = $this->growth = $this->network = 0;
     for ($i = 0; $i < $pWalks; $i += 2) {
         $rand_pairs = Zupal_Util_Array::random_set($keys, 2);
         ++$this->{$rand_pairs[0]};
         --$this->{$rand_pairs[1]};
     }
     $this->set_title($this->_random_name());
     $this->set_status('published');
 }