/** * @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 pickRegions(\Mastercoding\Conquest\Bot\AbstractBot $bot, \Mastercoding\Conquest\Move\PickRegions $move, $amountLeft, \Mastercoding\Conquest\Command\StartingRegions\Pick $pickCommand) { // choices $choices = array_diff($pickCommand->getRegionIds(), $move->getRegionIds()); // only pick random if amount left is 6, because issues otherwise $random = array_rand($choices, $amountLeft); foreach ($random as $key) { $move->addRegionId($choices[$key]); } return array($move, 0); }
/** * @inheritDoc */ public function parse($line) { // seperate components $line = trim($line); $components = explode(' ', $line); // designator switch ($components[0]) { case 'settings': return \Mastercoding\Conquest\Command\SettingParser::parse($line); case 'setup_map': return \Mastercoding\Conquest\Command\SetupMapParser::parse($line); case 'go': return \Mastercoding\Conquest\Command\GoParser::parse($line); case 'info': return \Mastercoding\Conquest\Command\InfoParser::parse($line); case 'pick_starting_regions': return \Mastercoding\Conquest\Command\StartingRegions\Pick::create($components); case 'update_map': return \Mastercoding\Conquest\Command\UpdateMap\Update::create($components); case 'opponent_moves': return \Mastercoding\Conquest\Command\OpponentMoves\Moves::create($components); } return null; }