microsoft / TextWorld

​TextWorld is a sandbox learning environment for the training and evaluation of reinforcement learning (RL) agents on text-based games.
Other
1.23k stars 189 forks source link

update grammar file to reflect the logic #286

Closed lanhoang712 closed 3 years ago

lanhoang712 commented 3 years ago

Hello, if we define new predicates in the logic file, what would be the correct way to update the grammar for the game observation? i.e. if we have predicate_A in the logic file, how to set the observation to say the [obj] is [something related to predicate_A]?

MarcCote commented 3 years ago

Hi, here's a simple example that shows one way of doing it.

https://gist.github.com/MarcCote/336ab87ebc8d5c0cb1562beabf270a41

First, in a working directory, create a copy of the TextWorld built-in data using

tw-data

Next, copy statue.twl (from the gist) into textworld_data/logic/, house_statue.twg intextworld_data/text_grammars/, and save a copy of portable_statue.py in the working directory .

Then, make a new game

tw-make --third-party portable_statue.py tw-portable-statue --output games/tw-game.z8

You can try the game using the tw-play command

tw-play games/tw-game.z8

-= Museum =-
You've entered a Museum.

There is an ivory statue and a granite statue on the floor.

> x statue                                                                                                                                                    
Which do you mean, the ivory statue or the granite statue?

> ivory                                                                                                                                                       
The ivory statue looks vulnerable.

> x granite                                                                                                                                                   
It's a hefty granite statue.

>

You can also check out the tw-cooking challenge data to see a more complex example.

If you had something else in mind, let me know. :)

lanhoang712 commented 3 years ago

Thank you so much @MarcCote :), much is appreciated. I will try the codes and report back if I have further questions on it.

MarcCote commented 3 years ago

I know TextWorld's documentation is a bit lacking in terms of customization (logic, grammar, of knowledge of Inform7, etc.). So, do not hesitate if you want to discuss more about what is possible to do.

lanhoang712 commented 3 years ago

Thank you @MarcCote, I have run the code and it worked, thank you so much! I will close this issue. I do have some other questions on defining actions so will open another issue. Really appreciate your help.