public function decide(GameState $state): GameState
    {
        if (!$state->getNextPlayer()->equals($this->objectivePlayer)) {
            throw new BadMethodCallException('It is not this players turn');
        }
        if (empty($state->getPossibleMoves())) {
            throw new RuntimeException('There are no possible moves');
        }

        $rootNode = new DecisionNode(
            $this->objectivePlayer,
            $state,
            $this->maxDepth,
            NodeType::MAX(),
            AlphaBeta::initial()
        );

        $moveWithEvaluation = $rootNode->traverseGameTree();
        $this->analytics = $moveWithEvaluation->analytics;
        if ($moveWithEvaluation->move === null) {
            throw new LogicException('Could not find move even though there are moves. Is the maxdepth parameter correct?');
        }
        return $moveWithEvaluation->move;
    }
public function decide(GameState $state): GameState
    {
        if (!$state->getNextPlayer()->equals($this->objectivePlayer)) {
            throw new BadMethodCallException('It is not this players turn');
        }
        if (empty($state->getPossibleMoves())) {
            throw new RuntimeException('There are no possible moves');
        }

        $rootNode = new DecisionNode(
            $this->objectivePlayer,
            $state,
            $this->maxDepth,
            NodeType::MAX(),
            AlphaBeta::initial()
        );

        $moveWithEvaluation = $rootNode->traverseGameTree();
        $this->analytics = $moveWithEvaluation->analytics;
        if ($moveWithEvaluation->move === null) {
            throw new LogicException('Could not find move even though there are moves. Is the maxdepth parameter correct?');
        }
        return $moveWithEvaluation->move;
    }
public function decide ( GameState $ state ) : GameState { if ( ! $ state -> getNextPlayer ( ) -> equals ( $ this -> objectivePlayer ) ) { throw new BadMethodCallException ( 'It is not this players turn' ) ; } if ( empty ( $ state -> getPossibleMoves ( ) ) ) { throw new RuntimeException ( 'There are no possible moves' ) ; } $ rootNode = new DecisionNode ( $ this -> objectivePlayer , $ state , $ this -> maxDepth , NodeType :: MAX ( ) , AlphaBeta :: initial ( ) ) ; $ moveWithEvaluation = $ rootNode -> traverseGameTree ( ) ; $ this -> analytics = $ moveWithEvaluation -> analytics ; if ( $ moveWithEvaluation -> move === null ) { throw new LogicException ( 'Could not find move even though there are moves. Is the maxdepth parameter correct?' ) ; } return $ moveWithEvaluation -> move ; }
Evaluate possible decisions and take the best one
@param GameState $state Current state of the game for which there needs
to be made a decision. This implicitly means that the objective player
currently must have its turn in the GameState.
@return GameState The state resulting after the engine made its decision.
Evaluate possible decisions and take the best one