コード例 #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
ファイル: keyboardAgents.py プロジェクト: derekchung10/pacman
    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
ファイル: CDAgents.py プロジェクト: Jisha-George/MScProject
    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
ファイル: keyboardAgents.py プロジェクト: penlin/2013AI
    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
ファイル: keyboardAgents.py プロジェクト: JenseDf/pacman
  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
コード例 #7
0
    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
ファイル: keyboardAgents.py プロジェクト: zbard/StanAI
  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
ファイル: keyboardAgents.py プロジェクト: jsuit/pacbot
  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