Exemple #1
0
 private function considerNextMove(GameState $newState) : DecisionWithScore
 {
     $nextPlayerIsFriendly = $newState->getNextPlayer()->isFriendsWith($this->objectivePlayer);
     $comparator = $nextPlayerIsFriendly ? DecisionWithScore::getBestComparator() : DecisionWithScore::getWorstComparator();
     $nextDecisionPoint = new static($this->objectivePlayer, $newState, $this->depthLeft - 1, $comparator);
     return $nextDecisionPoint->decide();
 }
Exemple #2
0
 /**
  * Evaluate possible decisions and take the best one
  */
 public function decide(GameState $state) : Decision
 {
     if (!$state->getNextPlayer()->equals($this->objectivePlayer)) {
         throw new BadMethodCallException('It is not this players turn');
     }
     $topLevelNode = new DecisionPoint($this->objectivePlayer, $state, $this->maxDepth, DecisionWithScore::getBestComparator());
     $decisionWithScore = $topLevelNode->decide();
     if ($decisionWithScore->decision === null) {
         throw new RuntimeException('There are no possible moves');
     }
     return $decisionWithScore->decision;
 }