function satisfiable($want, $have) { $have = array_map(function ($r) { return ResourceOption::me($r); }, $have); $ret = Resource::satisfy($want, $have, 100); foreach ($ret as $dir) { $good = true; foreach ($dir as $amt) { if ($amt > 0) { $good = false; break; } } if ($good) { return true; } } return false; }
private function calculateCost(Card $card, $type) { if ($type == 'play') { // check for duplicates foreach ($this->cardsPlayed as $cardPlayed) { if ($cardPlayed->getName() == $card->getName()) { return array(); } } // check if it's a prerequisite for being free foreach ($this->cardsPlayed as $cardPlayed) { if ($card->hasPrereq($cardPlayed)) { return array(array()); } } $required = $card->getResourceCost(); } else { // $type == 'wonder' // Can't over-build the wonder if ($this->wonderStage == count($this->wonder['stages'])) { return array(); } $stage = $this->wonder['stages'][$this->wonderStage]; $required = $stage['requirements']; } // Otherwise, we're going to have to pay for this card somehow $have = array(); // We get all our resources for free foreach ($this->permResources as $resource) { $have[] = ResourceOption::me($resource); } // Add in all the left player's resources, factoring in discounts foreach ($this->leftPlayer->permResources as $resource) { if (!$resource->buyable()) { continue; } $have[] = ResourceOption::left($resource, $resource->discount($this->discounts['left'])); } // Add in all the right player's resources, factoring discounts foreach ($this->rightPlayer->permResources as $resource) { if (!$resource->buyable()) { continue; } $have[] = ResourceOption::right($resource, $resource->discount($this->discounts['right'])); } // Figure out how we can pay neighbors to satisfy our requirements $possible = Resource::satisfy($required, $have, $this->coins - $card->getMoneyCost()); return $possible; }