/** * @inheritDoc */ public function pickRegions(\Mastercoding\Conquest\Bot\AbstractBot $bot, \Mastercoding\Conquest\Move\PickRegions $move, $amountLeft, \Mastercoding\Conquest\Command\StartingRegions\Pick $pickCommand) { // possible regions $regionIds = array_diff($pickCommand->getRegionIds(), $move->getRegionIds()); // map region ids by continent $mappedRegions = array(); foreach ($regionIds as $regionId) { // get region $region = $bot->getMap()->getRegionById($regionId); $mappedRegions[$region->getContinentId()][] = $regionId; } // now return as many different as possible $chosenRegions = array(); foreach ($mappedRegions as $continentId => $regions) { $region = $this->pickRegionForContinent($bot, $bot->getMap()->getContinentById($continentId), $regions); $chosenRegions[] = $region; // remove region id from array $regionIds = array_diff($regionIds, array($region)); } // add additional $amountToPick = $amountLeft - count($chosenRegions); if ($amountToPick > 0) { $chosenRegions = array_merge($chosenRegions, $this->pickAdditionalRegions($chosenRegions, $regionIds, $amountToPick)); } // return as command for ($i = 0; $i < $amountLeft; $i++) { $move->addRegionId($chosenRegions[$i]); } // ok return array($move, 0); }
/** * @inheritDoc */ public function placeArmies(\Mastercoding\Conquest\Bot\AbstractBot $bot, \Mastercoding\Conquest\Move\PlaceArmies $move, $amountLeft, \Mastercoding\Conquest\Command\Go\PlaceArmies $placeArmiesCommand) { // place on any of my regions $myRegions = $bot->getMap()->getRegionsForPlayer($bot->getMap()->getYou()); // first $myRegions->rewind(); $first = $myRegions->current(); // moves $move->addPlaceArmies($first->getId(), $amountLeft); return array($move, 0); }
/** * @inheritDoc */ public function placeArmies(\Mastercoding\Conquest\Bot\AbstractBot $bot, \Mastercoding\Conquest\Move\PlaceArmies $move, $amountLeft, \Mastercoding\Conquest\Command\Go\PlaceArmies $placeArmiesCommand) { // place on any of my regions $myRegions = $bot->getMap()->getRegionsForPlayer($bot->getMap()->getYou()); // first $random = rand(0, $myRegions->count() - 1); $myRegions->rewind(); for ($i = 0; $i < $random; $i++) { $myRegions->next(); } // region $region = $myRegions->current(); // moves $move->addPlaceArmies($region->getId(), $amountLeft); return array($move, 0); }