Giter Club home page Giter Club logo

Comments (4)

lanhoang712 avatar lanhoang712 commented on June 16, 2024 1

Hi Marc, thank you and sorry for the delay in responding. These examples and the twl file are perfect in explaining how to add actions/rules to the game. Thank you so much! Let me have a play with these and ask you further if I struggle with the new logic :).

from textworld.

MarcCote avatar MarcCote commented on June 16, 2024

Hi, correct me if I'm wrong but I believe you want something like this right?

apple = M.new(type='f', name='apple')
apple_eaten_event = Event(conditions={M.new_fact("eaten", apple)})
q1 = Quest(win_events=[apple_eaten_event]

If you really wish to define a quest according to an action, you can do the following:

room = M.new("kitchen")
apple = M.new(type='f', name='apple')
room.add(apple)

q1 = M.new_quest_using_commands(["take apple", "eat apple"])

or

apple_eaten_event = M.new_event_using_commands(["take apple", "eat apple"])
q1 = Quest(win_events=[apple_eaten_event]

Let me know if that's not it. Happy to discuss it more.

from textworld.

lanhoang712 avatar lanhoang712 commented on June 16, 2024

Perfect, thank you yes that's what I want to do. When would you use the object Action and can it be used for new action?

from textworld.

MarcCote avatar MarcCote commented on June 16, 2024

Great!

Regarding your follow-up question, under the hood, the Event class will look at the last actions and use its postconditions as the conditions. So, your original code is totally fine to create Event and Quest objects.

However, when building the game, TextWorld tries to infer the text commands from the event's actions. In your case, the eat action does not match any rule found in TextWorld's KnowledgeBase.

from textworld.generator import GameMaker, Event, Quest
from textworld.logic import Action

M = GameMaker()
apple = M.new(type='f', name='apple')
eat = Action(name='eat', preconditions=[], postconditions=[M.new_fact("eaten", apple)])
print(eat)
print(M.options.kb.logic.rules['eat'])
eat ::  -> eaten(f_0: f)       # print(eat)
eat :: in(f, I) -> eaten(f)    # print(M.options.kb.logic.rules['eat'])

As you can see, your new action is missing the precondition facts to match the existing eat rule from the KnowledgeBase.

For a completely new action (i.e., that is not already in the KB), you would need to add its Rule (i.e., the general form of an action) first. To do so, you will have to add a new .twl logic file containing the new rule, any new predicates, and the matching Inform7 code. As an example, you can check the tw_cooking games, in particular meal.twl.

Since extending TextWorld is far from being user-friendly at the moment, I'm happy to help you out creating new logic if that's something you need.

from textworld.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.