コード例 #1
0
ファイル: pddlagent.py プロジェクト: ccplanner/planner
 def get_move(self):
     """return a move"""
     if verbose: 
         print "agent (move requested)"
         print "agent (printing game status prior to move)"
         print_game_status()
     self.tick += 1
     self.state.update()
     if verbose and len( self.locs) > 2 :
             print self.locs[-1]
             print self.locs[-2]
     if len( self.moves )  and ( len( self.locs ) and self.locs.pop() == tw.chips_pos() or 
                                 len( self.locs ) and self.locs.pop() == tw.chips_pos()):
         move = self.moves.pop()
         if verbose: print "agent (cached move: %s)" % translate_tw_move(move)
         return move
     if verbose: print "agent (no cached moves or plan no longer valid)" 
     
     pddl_file_name = self.create_pddl_file(lambda(file):self.state.write_pddl(file))
    
     found_plan=False #can we get to the exit
     try:
         # get moves and translate them
         if verbose: print "agent (running planner)"
         string_moves= downward.run( pddl_file_name )
         found_plan = True
         print string_moves
     except Exception, e:
         found_plan = False
         if verbose: 
             print e
             print "Caught exception"
コード例 #2
0
ファイル: run_agent.py プロジェクト: ccplanner/planner
    def get_move(self):
        '''A wrapper agent that has memory, to deal with fast ticks'''
	time.sleep( 1 / 20) # each tick is 1/20th of second
        try:
            if self.skiped_moves >= 4 or tworld.chips_pos() != self.last_pos:
                self.skiped_moves = 0
                self.last_pos= tworld.chips_pos()
                self.last_move=agent.get_move()
            else:
                self.skiped_moves += 1
            return self.last_move
        except Exception, e:
            print "EXCEPTION:"
            print traceback.format_exc()
            print "giving up and exiting, but you can try another level"
            sys.exit()
コード例 #3
0
ファイル: pddlagent.py プロジェクト: ccplanner/planner
def print_game_status():
    print "game (printing board, top tiles only)"
    print_board(9,9,False)
    x,y = tw.chips_pos()
    print "game (Keys R:%d B:%d Y:%d G:%d)" % tw.get_keys()
    print "game (Boots Ice:%d Suction:%d Fire:%d Water:%d)" % tw.get_boots()
    print "game (Player: %d,%d)" % (x, y)
    print "game (Chips left: %d)" % tw.chips_needed()
コード例 #4
0
ファイル: agent.py プロジェクト: ccplanner/tworld_py
def verbose_agent():
    """print out lots of debug and then return a random direction"""
    print_board(9,9)
    x,y = tworld.chips_pos()
    print "Keys R:%d B:%d Y:%d G:%d" % tworld.get_keys()
    print "Boots Ice:%d Suction:%d Fire:%d Water:%d" % tworld.get_boots()
    print "(%d,%d)" % (x, y)
    print "Chips left: %d" % tworld.chips_needed()
    return random_move()