Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we obtain the game map in a data format? #187

Closed
ankitvad opened this issue Oct 4, 2019 · 12 comments
Closed

Can we obtain the game map in a data format? #187

ankitvad opened this issue Oct 4, 2019 · 12 comments

Comments

@ankitvad
Copy link

ankitvad commented Oct 4, 2019

Hi, I've found out the --overview and --save-overview option which can generate an image representation of the generated game map with the locations and the inventory/objective. Is there a way to obtain the generated game graph/map? Which contains the different rooms and the connection label between the rooms? For example, Kitchen and a connection west to room..etc. in a text/JSON/graph format etc.. something other than an image..

Or maybe there is someplace in the repo. from where I can obtain this information?
Thanks.

@MarcCote
Copy link
Contributor

MarcCote commented Oct 4, 2019

Hi @ankitvad, the underlying representation can be obtained by looking at the facts of the world.

Here a small example. At the moment, the following requires the master branch.

import gym
import textworld
import textworld.gym

options = textworld.GameOptions()
options.seeds = 1234
gamefile, game = textworld.make(options)

env_infos = textworld.EnvInfos(facts=True)
env_id = textworld.gym.register_game(gamefile, env_infos)
env = gym.make(env_id)
obs, infos = env.reset()

from pprint import pprint
pprint(infos["facts"])

# Uncomment the next line to see the overview image.
# textworld.render.visualize(game, interactive=True)

Running the above code, outputs the following

[Proposition('at', (Variable(None, 'P'), Variable('attic', 'r'))),
 Proposition('at', (Variable('type G chest', 'c'), Variable('attic', 'r'))),
 Proposition('in', (Variable('type G key', 'k'), Variable(None, 'I'))),
 Proposition('locked', (Variable('type G chest', 'c'),)),
 Proposition('match', (Variable('type G key', 'k'), Variable('type G chest', 'c')))]

I hope that helps. Let me know if that's not what you were looking for.

@ankitvad
Copy link
Author

ankitvad commented Oct 4, 2019

Hi @MarcCote thanks for the reply. While this is definitely helpful..I was more interested in obtaining the location orientation (wrt each other) information. For example:

# Connect rooms together.

Something like this. Ideally I’d like the whole map information in a parsable and processable way. Something that’s like a graph where the nodes are the different room, then those have sub graphs with nodes representing objects in the room and the property(exactly like the inventory information in the visualize diagram). Primarily, I’d like to get the location information for each room. Ie. let’s say the kitchen has a connection to the bathroom on the east side, as a result kitchen will be east to the kitchen.. etc.
Can I call some parameter to give me this information? The info. That is parsed to create the visualize diagram.. that has objects locations and the location orientation wrt to each other. Ie. north of, east of, etc.

@MarcCote
Copy link
Contributor

MarcCote commented Oct 4, 2019

Yea, so the list of facts contains that information for sure as it is used to generate the overview figures. Each fact can be seen as a named relation between two entities. With the facts, you can generate something like this
image

@ankitvad
Copy link
Author

ankitvad commented Oct 4, 2019

Oh.. this is perfect. :D
Thanks! I wasn’t able to find the N/E/W/S information in the example above. But I get it.. that’s just a single room.
Thanks for the information.

@ankitvad ankitvad closed this as completed Oct 4, 2019
@MarcCote
Copy link
Contributor

MarcCote commented Oct 4, 2019

Great!
PS: in order to generate the figure above, I had to alter the facts a bit (e.g. even though we see an exit node in the graph, there's no such thing in TW - at the moment). So, do not hesitate to reach out to us if you need help.

@ankitvad
Copy link
Author

ankitvad commented Oct 4, 2019

I’m sorry, I’m not able to see the exit node. Where is that exactly? In the diagram?

@MarcCote
Copy link
Contributor

MarcCote commented Oct 4, 2019

My bad. I was thinking of another figure. There's indeed no exit node. So, another example of graph manipulation would be the link(r, d, r') predicate which is used in TextWorld to indicate two rooms are connected to each via a door. However, that link predicate doesn't tell you in which direction the two rooms are connected. For that, you have to look for the corresponding {dir}_of(r, r') predicates.

For instance,

link(kitchen, door, living room)
north_of(kitchen, living room)  # Read as the kitchen is north of the living room.
south_of(livingroom, kitchen)

has been translated to

north_of(door, kitchen)  # Read as the door is on the north wall of the kitchen.
south_of(door, livingroom)

@ankitvad
Copy link
Author

Hi, @MarcCote I had one additional question. If I’m using the EnvInfo filter to obtain all admissible commands at each step, is there a way to retain the env state?
I’m consulting this: https://colab.research.google.com/github/yfletberliac/rlss-2019/blob/master/labs/final_project/TextWorld.ipynb#scrollTo=Ig7o6cMPEGqg

Every time I do something like -
r1 = env.step(“some command”) the env state changes. If at an env state there are 5 commands that are admissible And I’d like to run all of them one by one to see the change in description/state and reward for the initial state. Is there any way to accomplish this without resetting the environment and playing the whole game till that point again? Can I maybe copy the environment? But not a reference copy like a complete separate element? Or something else? Or maybe there’s a way to go back 1 step? Any info. Will be helpful? Thanks.

@MarcCote
Copy link
Contributor

MarcCote commented Oct 10, 2019

Unfortunately, the only way to achieve what you want at the moment is to do a reset and replay the previous commands. The main reason is that we depend on the state of the game interpreter (here git-glulx) which is running in another process.

That said, I can think of a way we could support a "snapshot" functionality but that would require some tinkering. If you don't mind, can you create an issue for this?

PS: is that your colab notebook? It looks great.
EDIT: oh I see it was part of a summer school. @yfletberliac I like it.

@ankitvad
Copy link
Author

@MarcCote Yup. Makes sense. Thanks. Sure, I'll create an issue.
Yes, it's part of this repo - https://github.com/yfletberliac/rlss-2019.

@ankitvad
Copy link
Author

Yea, so the list of facts contains that information for sure as it is used to generate the overview figures. Each fact can be seen as a named relation between two entities. With the facts, you can generate something like this
image
@MarcCote Also, is there an option in TextWorld to obtain an overview of the map like in the image? Or should I parse the facts and create this knowledge graph myself? Could you share the script you used to generate the KG from the facts?

@MarcCote
Copy link
Contributor

@ankitvad can you try this PR
#189
Check the example section of the docstring for textworld.render.graph.show_graph.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants