def pyhop_state_from_world(world, name="state"): s = pyhop.State(name) s.pos = {} s.clear = {} s.holding = False s.fire = {} s.free = {} s.fire_ext_avail = set() s.holdingfireext = None s.hasmortar = {} # keys are s.mortaravailable = {} mortarblocks = [] blocks = [] for objname in world.objects: if world.objects[objname].type.name == "BLOCK" and objname != "table": blocks.append(objname) elif world.objects[objname].type.name == "ARSONIST": s.free[objname] = False elif world.objects[objname].type.name == "MORTARBLOCK": mortarblocks.append(objname) for atom in world.atoms: if atom.predicate.name == "clear": s.clear[atom.args[0].name] = True elif atom.predicate.name == "holding": s.holding = atom.args[0].name elif atom.predicate.name == "fire-extinguisher": s.fire_ext_avail.add(atom.args[0].name) elif atom.predicate.name == "holdingextinguisher": s.holdingfireext = atom.args[0].name elif atom.predicate.name == "arm-empty": s.holding = False elif atom.predicate.name == "on": s.pos[atom.args[0].name] = atom.args[1].name elif atom.predicate.name == "on-table": s.pos[atom.args[0].name] = "table" elif atom.predicate.name == "onfire": s.fire[atom.args[0].name] = True elif atom.predicate.name == "free": s.free[atom.args[0].name] = True elif atom.predicate.name == "available": s.mortaravailable[atom.args[0].name] = True elif "hasmortar" in world.types and atom.predicate.name == "hasmortar": s.hasmortar[atom.args[0].name] = atom.args[1].name for block in blocks: if block not in s.clear: s.clear[block] = False if block not in s.fire: s.fire[block] = False if block not in s.pos: s.pos[block] = "in-arm" if block not in list(s.hasmortar.keys()): s.hasmortar[block] = False for mblock in mortarblocks: if mblock not in list(s.mortaravailable.keys()): s.mortaravailable[mblock] = False return s
def pyhop_state_from_world(world, name = "state"): s = pyhop.State(name) s.agents={'curiosity':'3,3'} # put beacons here too? and mud tiles? s.dim={'dim':-1} s.agents = {} s.beaconlocs = {} # key is beacon id (e.g. b1), val is tile str like Tx3y4 s.beacontypes = {} # key is beacon id (e.g. b1), val is a number representing the type s.activated = {} # key is beacon id (e.g. b1), val is True if activated, False otherwise s.agents = {} s.mud = {} s.quicksand = [] beacons = [] agent = None for objname in world.objects: if world.objects[objname].type.name == "BEACON": beacons.append(objname) elif world.objects[objname].type.name == "AGENT" and not agent: # if agent already set, means multi-agent agent = objname elif world.objects[objname].type.name == "DIM": s.dim['dim'] = int(objname) # by default, make all beacons deactivated (if they are activated, will be changed below) for bcn in beacons: s.activated[bcn] = False # now process atoms for atom in world.atoms: if atom.predicate.name == "beacon-at": b_id = atom.args[0].name tile_str = atom.args[1].name s.beaconlocs[b_id] = tile_str elif atom.predicate.name == "activated": b_id = atom.args[0].name s.activated[b_id] = True elif atom.predicate.name == "agent-at": s.agents[atom.args[0].name] = convert(atom.args[1].name) elif atom.predicate.name == "quicksand": s.quicksand.append(convert(atom.args[0].name)) # convert tile names to pyhop operators for (k,v) in s.beaconlocs.items(): s.beaconlocs[k] = convert(v) #print("at the end of nbeacons_pyhop_state_from_world:") #print_state(s) return s
def pyhop_state_from_world_restaurant(world, name="state"): s = pyhop.State(name) # these are the states for the domain s.order_received = {} s.order_pending = {} s.order_prepared = {} s.order_served = {} ''' for atom in world.atoms: # get the orders into the s.order_received dictionary if atom.predicate.name == "order_serve": # if there are multiple orders for a single person,append the dishes into a list # create a list of one dish # atom.args[0].name is a person name # atom.args[1].name is a dish name print("hi") if atom.args[0].name in s.order_received: s.order_received[atom.args[0].name].append(atom.args[1].name) else: s.order_received[atom.args[0].name] = list(atom.args[1].name) ''' return s