예제 #1
0
    def getAction( self, state):
        from graphicsUtils import keys_waiting
        from graphicsUtils import keys_pressed
        keys = keys_waiting() + keys_pressed()
        if keys != []:
            self.keys = keys

        legal = state.getLegalActions(self.index)
        move = self.getMove(legal)

        if move == Directions.STOP:
            # Try to move in the same direction as before
            if self.lastMove in legal:
                move = self.lastMove

        if (self.STOP_KEY in self.keys) and Directions.STOP in legal: move = Directions.STOP

        if move not in legal:
            move = random.choice(legal)

        self.lastMove = move

        # Call to the saveData method to add manually created data to the training set
        saveData(move, self.getExpectedReward(state, move))

        return move
예제 #2
0
  def getAction( self, state):
    from graphicsUtils import keys_waiting
    from graphicsUtils import keys_pressed
    #print('type of keys_waiting is {}, keys_waiting is {}'.format(type(keys_waiting()), keys_waiting()))
    #print('type of keys_pressed is {}, keys_presse is {}'.format(type(keys_pressed()), keys_pressed()))
    
    # change to list
    keys = list(keys_waiting()) + list(keys_pressed())
    if keys != []:
      self.keys = keys
    
    legal = state.getLegalActions(self.index)
    move = self.getMove(legal)
    
    if move == Directions.STOP:
      # Try to move in the same direction as before
      if self.lastMove in legal:
        move = self.lastMove
    
    if (self.STOP_KEY in self.keys) and Directions.STOP in legal: move = Directions.STOP

    if move not in legal:
      move = random.choice(legal)
      
    self.lastMove = move
    return move
예제 #3
0
    def getAction(self, state):
        global USE_CURSE
        if USE_CURSE:
            textDisplay.CURSE_WINDOW.nodelay(0)
            key = textDisplay.CURSE_WINDOW.getch()
            keys = [chr(key)]
        else:
            from graphicsUtils import keys_waiting
            from graphicsUtils import keys_pressed
            keys = keys_waiting() + keys_pressed()
        if keys != []:
            self.keys = keys

        legal = state.getLegalActions(self.index)
        move = self.getMove(legal)

        if move == Directions.STOP:
            # Try to move in the same direction as before
            if self.lastMove in legal:
                move = self.lastMove

        if (self.STOP_KEY in self.keys) and Directions.STOP in legal:
            move = Directions.STOP

        if move not in legal:
            move = random.choice(legal)

        self.lastMove = move
        return move
예제 #4
0
    def getAction(self, state):
        """
          Compute the action to take in the current state.  With
          probability self.epsilon, we should take a random action and
          take the best policy action otherwise.  Note that if there are
          no legal actions, which is the case at the terminal state, you
          should choose None as the action.

          HINT: You might want to use util.flipCoin(prob)
          HINT: To pick randomly from a list, use random.choice(list)
        """

        keypress = keys_pressed() + keys_waiting()

        if keypress != []:
            self.keypress = keypress

        if self.episodesSoFar < self.numTraining:
            if (self.SPACE_KEY in self.keypress or 'space' in self.keypress):
                Directions.CD = True
        else:
            print("Corrective Demontration Locked!")

        if Directions.CD == True:
            action = self.CDStart(state)
        elif Directions.CD == False:
            # Pick Action
            action = self.QStart(state)

        return action
예제 #5
0
    def getAction(self, state):
        from graphicsUtils import keys_waiting
        from graphicsUtils import keys_pressed

        keys = keys_waiting() + keys_pressed()
        self.keys = keys

        legal = state.getLegalActions(self.index)
        move = self.getMove(legal)

        # if move == Directions.STOP:
        # Try to move in the same direction as before
        # if self.lastMove in legal:
        # move = self.lastMove

        if (self.STOP_KEY in self.keys) and Directions.STOP in legal:
            move = Directions.STOP
        elif (self.LAY_KEY in self.keys) and "Lay" in legal:
            move = "Lay"
        if move not in legal:
            move = random.choice(legal)

        self.lastMove = move

        return move
예제 #6
0
  def getAction( self, state):
    from graphicsUtils import keys_waiting
    from graphicsUtils import keys_pressed
    
    
    keys = keys_waiting() + keys_pressed()
    if keys != []:
        self.keys = keys
    
    print(self.keys)
    legal = state.getLegalActions(self.index)
    move = self.getMove(legal)
    
    if move == Directions.STOP:
      # Try to move in the same direction as before
      if self.lastMove in legal:
        move = self.lastMove
    
    if (self.STOP_KEY in self.keys) and Directions.STOP in legal: move = Directions.STOP

    if move not in legal:
      move = random.choice(legal)
      
    self.lastMove = move
    return move
    def getAction( self, state):
	#print self.index
        from graphicsUtils import keys_waiting
        from graphicsUtils import keys_pressed
        keys = keys_waiting() + keys_pressed()
	
	#print self.index, keys
        if keys != []:
            self.keys = keys

        legal = state.getLegalActions(self.index)
	#print legal
	move = self.getMove(legal)
	if self.index == 0:
	    #print legal,'legal'
	    #print random.choice(legal)
	    #print self.keys, 'keys'
	    #print random.choice(legal), 'rand'
	    return random.choice(legal)
	    
	else:
	    #print state.getGhostPosition(self.index)
	    if move == Directions.STOP:     #when keys = [] (keys is empty, i.e no input from the user)
            # Try to move in the same direction as before
                if self.lastMove in legal:
                    move = self.lastMove

            if (self.STOP_KEY in self.keys) and Directions.STOP in legal: move = Directions.STOP

            if move not in legal:
                move = random.choice(legal)

            self.lastMove = move
            return move
예제 #8
0
    def getAction(self, state):

        print(state.getLegalActions())
        #print(state.generateSuccessor())
        print(state.getLegalPacmanActions())
        print(state.getGhostPositions())
        print(state.getWalls())
        print()
        print(state.getFood())
        print(state.hasWall(1, 1))
        print(type(state.getWalls()))
        assert 1 < 0

        from graphicsUtils import keys_waiting
        from graphicsUtils import keys_pressed
        keys = list(keys_waiting()) + list(keys_pressed())
        if keys != []:
            self.keys = keys

        legal = state.getLegalActions(self.index)
        move = self.getMove(legal)

        if move == Directions.STOP:
            # Try to move in the same direction as before
            if self.lastMove in legal:
                move = self.lastMove

        if (self.STOP_KEY in self.keys) and Directions.STOP in legal:
            move = Directions.STOP

        if move not in legal:
            move = random.choice(legal)

        self.lastMove = move
        return move
예제 #9
0
 def getKeys():
     #print 'attempt get keys'
     Display._acquireLock()
     #print 'get keys'
     keys = graphicsUtils.keys_waiting() + graphicsUtils.keys_pressed()
     Display._releaseLock()
     return keys
예제 #10
0
  def getAction( self, state):
    from graphicsUtils import keys_waiting
    from graphicsUtils import keys_pressed
    keys = keys_waiting() + keys_pressed()
    if keys != []:
      self.keys = keys
    
    legal = state.getLegalActions(self.index)
    move = self.getMove(legal)
    
    if move == Directions.STOP:
      # Try to move in the same direction as before
      if self.lastMove in legal:
        move = self.lastMove
    
    if (self.STOP_KEY in self.keys) and Directions.STOP in legal: move = Directions.STOP

    if move not in legal:
      move = random.choice(legal)
      
    self.lastMove = move

    # Debugging
    import multiAgents
    print "val of state :",multiAgents.betterEvaluationFunction(state)

    return move
    def getAction(self, state):
        from graphicsUtils import keys_waiting
        from graphicsUtils import keys_pressed
        keys = keys_waiting() + keys_pressed()
        self.keys = keys

        legal = state.getLegalActions(self.index)
        move = self.getMove(legal)

        if (self.STOP_KEY in self.keys) and Directions.STOP in legal:
            move = Directions.STOP

        if move not in legal:
            move = random.choice(legal)

        self.lastMove = move
        return move
예제 #12
0
  def getAction( self, state):
    from graphicsUtils import keys_waiting
    from graphicsUtils import keys_pressed
    keys = keys_waiting() + keys_pressed()
    if keys != []:
      self.keys = keys
    legal = state.getLegalActions(self.index)
    move = self.getMove(legal)
    if self.singleStep == False and move == Directions.STOP:
      # Try to move in the same direction as before
      if self.lastMove in legal:
        move = self.lastMove

    if (self.STOP_KEY in keys) and Directions.STOP in legal: move = Directions.STOP

    if move not in legal:
      move = random.choice(legal)
    
    self.lastMove = move
    return move
예제 #13
0
  def getAction( self, state):
    from graphicsUtils import keys_waiting
    from graphicsUtils import keys_pressed
    keys = keys_waiting() + keys_pressed()
    if keys != []:
      self.keys = keys
    self.keys = keys

    legal = state.getLegalActions(self.index)
    move = self.getMove(legal)
    
    if (self.STOP_KEY in self.keys) and Directions.STOP in legal: move = Directions.STOP

    if move not in legal:
      move = random.choice(legal)
      
    self.lastMove = move

    # print self.keys, move

    return move
예제 #14
0
    def getAction(self, state):
        from graphicsUtils import keys_waiting
        from graphicsUtils import keys_pressed
        keys = keys_waiting() + keys_pressed()
        if keys != []:
            self.keys = keys

        legal = state.getLegalActions(self.index)
        move = self.getMove(legal)

        if move == Directions.STOP:
            # Try to move in the same direction as before
            if self.lastMove in legal:
                move = self.lastMove

        if (self.STOP_KEY in self.keys) and Directions.STOP in legal:
            move = Directions.STOP

        if move not in legal:
            move = random.choice(legal)

        # Log feature set and choice of move
        if move != Directions.STOP:
            self.outfile.write(api.getFeaturesAsString(state))
            if move == Directions.NORTH:
                self.outfile.write("0\n")
            elif move == Directions.EAST:
                self.outfile.write("1\n")
            elif move == Directions.SOUTH:
                self.outfile.write("2\n")
            elif move == Directions.WEST:
                self.outfile.write("3\n")

        # Now make the move
        self.lastMove = move
        return move
예제 #15
0
    def getAction(self, state):
        from graphicsUtils import keys_waiting
        from graphicsUtils import keys_pressed
        keys = keys_waiting() + keys_pressed()
        if keys != []:
            self.keys = keys

        legal = list(set().union(
            state.getLegalActions(self.index),
            state.getLegalActions(self.index + state.getNumAgents() / 2)))
        move = self.getMove(legal)

        #if move == Directions.STOP:
        #    # Try to move in the same direction as before
        #    if self.lastMove in legal:
        #        move = self.lastMove

        #if (self.STOP_KEY in self.keys) and Directions.STOP in legal: move = Directions.STOP

        #if move not in legal:
        #    move = random.choice(legal)

        self.lastMove = move
        return move