Пример #1
0
    def getLegalActions(state, agentIndex):
        """
        Returns a list of possible actions.
        """

        agentState = state.getAgentState(agentIndex)
        return Actions.getPossibleActions(agentState.getPosition(), agentState.getDirection(),
                state.getWalls())
Пример #2
0
    def getLegalActions(state, ghostIndex):
        """
        Ghosts cannot stop, and cannot turn around unless they
        reach a dead end, but can turn 90 degrees at intersections.
        """

        agentState = state.getGhostState(ghostIndex)
        possibleActions = Actions.getPossibleActions(agentState.getPosition(),
                agentState.getDirection(), state.getWalls())
        reverse = Actions.reverseDirection(agentState.getDirection())

        if (Directions.STOP in possibleActions):
            possibleActions.remove(Directions.STOP)

        if (reverse in possibleActions and len(possibleActions) > 1):
            possibleActions.remove(reverse)

        return possibleActions