Skip to content
Snippets Groups Projects
Commit 9a6830df authored by Tessaris Sergio's avatar Tessaris Sergio
Browse files

included hunter orientation in JSON dump

parent cea81755
No related branches found
No related tags found
No related merge requests found
......@@ -264,7 +264,7 @@ class WumpusWorld(GridWorld):
size = coordLst('size')[0]
blocks = coordLst('blocks')
hunters = coordLst('hunters')
hunters = json_obj.get('hunters', [])
pits = coordLst('pits')
wumpuses = coordLst('wumpuses')
exits = coordLst('exits')
......@@ -272,8 +272,13 @@ class WumpusWorld(GridWorld):
world = cls(size, blocks)
for pos in hunters:
world.addObject(Hunter(orientation=Hunter.Orientation.N), pos)
for hunter in (hunters if (len(hunters) == 0) or isinstance(hunters[0], Sequence) else [hunters]):
pos = getCoord(hunter)
try:
orientation = Hunter.Orientation[str(hunter[2]).upper()]
except Exception:
orientation = Hunter.Orientation.N
world.addObject(Hunter(orientation=orientation), pos)
for pos in (exits or hunters or [coord(0, 0)]):
world.addObject(Exit(), pos)
......@@ -361,7 +366,7 @@ class WumpusWorld(GridWorld):
golds = []
for obj in self.objects:
if isinstance(obj, Hunter):
hunters.append(coord_tuple(obj.location))
hunters.append(coord_tuple(obj.location) + (obj.orientation.name,))
elif isinstance(obj, Pit):
pits.append(coord_tuple(obj.location))
elif isinstance(obj, Wumpus):
......@@ -451,6 +456,8 @@ if __name__ == "__main__":
world.run_episode(hunter, UserPlayer.player())
print(json.dumps(world.to_JSON()))
JSON_STRING = '{"size": [7, 7], "hunters": [[0, 0]], "pits": [[4, 0], [3, 1], [2, 2], [6, 2], [4, 4], [3, 5], [4, 6], [5, 6]], "wumpuses": [[1, 2]], "exits": [[0, 0]], "golds": [[6, 3]]}'
JSON_STRING = '{"size": [7, 7], "hunters": [[0, 0, "E"]], "pits": [[4, 0], [3, 1], [2, 2], [6, 2], [4, 4], [3, 5], [4, 6], [5, 6]], "wumpuses": [[1, 2]], "exits": [[0, 0]], "golds": [[6, 3]]}'
world = WumpusWorld.from_JSON(json.loads(JSON_STRING))
print(world)
print(json.dumps(world.to_JSON()))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment