Пример #1
0
 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
     try:
         string_moves= downward.run( pddl_file_name )
         found_plan = True
     except Exception, e:
         if verbose: 
             print e
             print "Chips plan faild"
  
 if not found_plan:
     if verbose: print "agent (no plan to reach goal, generating plan to reach any explore tile)"
     
     pddl_file_name = self.create_pddl_file(lambda(file):self.state.write_explore_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"              
         # nothing we can do now
         return tw.WAIT
 
 # setup moves
 self.moves= map( translate_move, string_moves)
 self.locs= map( lambda x: tuple( map( 
                int, 
                filter( lambda s: "pos" in s, x.translate( None, "()").split())[0].split('-')[1:3] )),
        string_moves) 
 if verbose: print self.locs