コード例 #1
0
    def getAction(self, rawState, epsilon):

        legalActions = rawState.getLegalActions()
        legalActions.remove(Directions.STOP)

        if util.flipCoin(epsilon):
            return random.choice(legalActions)

        else:
            qValues = [(Directions.getIndex(action),
                        self.getQValue(rawState, action))
                       for action in legalActions]
            qValues = sorted(qValues, key=lambda x: x[1], reverse=True)

            for index, qValue in qValues:
                action = Directions.fromIndex(index)
                if action in legalActions:
                    return action
コード例 #2
0
    def getAction(self, rawState, epsilon):
        legalActions = rawState.getLegalActions()
        legalActions.remove(Directions.STOP)

        qState = self.trainingRoom.featuresExtractor.getFeatures(
            rawState, None)

        if util.flipCoin(epsilon):
            return random.choice(legalActions)

        else:
            qValues = list(
                enumerate(self.model.model.predict(np.array([qState]))[0]))
            qValues = sorted(qValues, key=lambda x: x[1], reverse=True)

            for index, qValue in qValues:
                action = Directions.fromIndex(index)
                if action in legalActions:
                    return action
コード例 #3
0
def chooseNextCrossroad(crossroads, ghostsPos, pacmanPos, distMap, walls):
    sortedCrossroads = []
    sorted = False
    while not sorted:
        if len(sortedCrossroads) < len(crossroads):
            closest = random.choice(crossroads)
            for crossroad in crossroads:
                if distMap[crossroad, pacmanPos] < distMap[closest, pacmanPos] and crossroad not in sortedCrossroads:
                    closest = crossroad
            sortedCrossroads.append(closest)
        else:
            sorted = True

    for i in range(0, len(sortedCrossroads)):
        reachable = util.accessibleAStar(pacmanPos, sortedCrossroads[i], ghostsPos, walls)
        if reachable:
            return sortedCrossroads[i]

    return sortedCrossroads[len(sortedCrossroads) - 1]
コード例 #4
0
 def getAction(self, state):
     return random.choice(state.getLegalActions(self.index))
コード例 #5
0
 def getAction(self, state):
     import random, time
     time.sleep(2.0)
     return random.choice(state.getLegalActions(self.index))