Ejemplo n.º 1
0
 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;
 }
test($ret[0]['left'] == 0);
test($ret[0]['right'] == 0);
test($ret[0]['self'] == 0);
$ret = Resource::satisfy(array($clay), array($caravanr, $caravanl), 10);
test(count($ret) == 2);
$ret = Resource::satisfy(array($clay), array(ResourceOption::left($clay), ResourceOption::right($clay)), 10);
test(count($ret) == 2);
$ret = Resource::satisfy(array($stone, $stone, $ore), array(ResourceOption::me($stone), ResourceOption::me($ore), ResourceOption::me($glass), ResourceOption::me($paper), ResourceOption::left($stone, 2), ResourceOption::left($ore, 2), ResourceOption::left($glass, 2), ResourceOption::left($paper, 2), ResourceOption::right($stone, 2), ResourceOption::right($ore, 2), ResourceOption::right($glass, 2), ResourceOption::right($paper, 2)), 100);
test(count($ret) == 2);
$wo = new Resource(true, false);
$wo->add(Resource::WOOD);
$wo->add(Resource::ORE);
$wb = new Resource(true, false);
$wb->add(Resource::CLAY);
$wb->add(Resource::WOOD);
$ret = Resource::satisfy(array($clay, $clay, $linen), array(ResourceOption::me($paper), ResourceOption::me($linen), ResourceOption::me($wo), ResourceOption::me($wb), ResourceOption::left($paper, 2), ResourceOption::left($linen, 2), ResourceOption::left($wo, 2), ResourceOption::left($wb, 2), ResourceOption::right($paper, 2), ResourceOption::right($linen, 2), ResourceOption::right($wo, 2), ResourceOption::right($wb, 2)), 100);
test(count($ret) == 2);
// Test science scoring
$s1 = new Science();
test($s1->points() == 0);
$s1->add(Science::GEAR);
test($s1->points() == 1);
$s1->add(Science::GEAR);
test($s1->points() == 4);
$s1->add(Science::COMPASS);
test($s1->points() == 5);
$s1->add(Science::ANY);
test($s1->points() == 13);
$s1->add(Science::ANY);
test($s1->points() == 18);
$s1->add(Science::TABLET);