Beispiel #1
0
class cacheing_pddl_agent:

    def __init__(self):
        self.moves=[] # list of moves to carry out moves.pop() is next move
        self.state = StateWorld()
        self.moves = []
        self.locs=[] # list of where chip will be after each move
        self.tick = 0
        global verbose
        verbose = cfg.opts.pddl_agent_verbose

    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"
        
        if not found_plan:
            assert (not cfg.opts.agent_memoryless)
            if verbose: print "agent (no plan to reach goal, generating plan to reach any chips)"
            
            pddl_file_name = self.create_pddl_file(lambda(file):self.state.write_chips_pddl(file))
        
            if verbose: print "agent (running planner again)"
            try:
                string_moves= downward.run( pddl_file_name )
                found_plan = True
            except Exception, e:
                if verbose: 
                    print e
                    print "Chips plan faild"
Beispiel #2
0
 def __init__(self):
     self.moves=[] # list of moves to carry out moves.pop() is next move
     self.state = StateWorld()
     self.moves = []
     self.locs=[] # list of where chip will be after each move
     self.tick = 0
     global verbose
     verbose = cfg.opts.pddl_agent_verbose