Пример #1
0
        for x in range(x_max):
            print "%2x|" % tworld.get_tile(x,y)[0],
        print "\n",
        for x in range(x_max):
            print "%2x|" % tworld.get_tile(x,y)[1],
        print "\n",
    print "\n"

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()

def random_move():
    """make random moves"""
    time.sleep(1)
    return random.choice( [tworld.NORTH, 
                           tworld.SOUTH, 
                           tworld.EAST, 
                           tworld.WEST,
                           tworld.WAIT])

tworld.set_agent( verbose_agent )
#tworld.load_level('cc-ms.dac',2)
tworld.load_level('classical.dac',3)
Пример #2
0
class wrapper_agent:
    def __init__(self, get_move_func ):
        self.last_pos = None
        self.last_move = None
        self.skiped_moves = 0
        self.wrapped_get_move = get_move_func

    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()

#wagent = wrapper_agent( pa.pddlagent )
wagent = wrapper_agent( agent.get_move )
tworld.set_agent( wagent.get_move )

tworld.load_level(level_set, options.level_num)