1515other than the coin to collect.
1616"""
1717
18+ import os
1819import argparse
20+ from os .path import join as pjoin
1921from typing import Mapping , Optional , Any
2022
2123import textworld
2224from textworld .generator .graph_networks import reverse_direction
2325
2426from textworld .utils import encode_seeds
25- from textworld .generator .game import GameOptions , Quest , EventCondition
27+ from textworld .generator .data import KnowledgeBase
28+ from textworld .generator .game import GameOptions , Quest , Event
2629from textworld .challenges import register
2730
2831
32+ KB_PATH = pjoin (os .path .dirname (__file__ ), "textworld_data" )
33+
34+
2935def build_argparser (parser = None ):
3036 parser = parser or argparse .ArgumentParser ()
3137
3238 group = parser .add_argument_group ('Coin Collector game settings' )
3339 group .add_argument ("--level" , required = True , type = int ,
3440 help = "The difficulty level. Must be between 1 and 300 (included)." )
3541
36- group .add_argument ("--force-entity-numbering" , required = True , action = "store_true" ,
37- help = "This will set `--entity-numbering` to be True which is required for this challenge." )
38-
3942 return parser
4043
4144
@@ -49,7 +52,7 @@ def make(settings: Mapping[str, Any], options: Optional[GameOptions] = None) ->
4952 :py:class:`textworld.GameOptions <textworld.generator.game.GameOptions>`
5053 for the list of available options).
5154
52- .. warning:: This challenge requires `options.grammar.allowed_variables_numbering` to be `True`.
55+ .. warning:: This challenge enforces `options.grammar.allowed_variables_numbering` to be `True`.
5356
5457 Returns:
5558 Generated game.
@@ -68,9 +71,11 @@ def make(settings: Mapping[str, Any], options: Optional[GameOptions] = None) ->
6871 """
6972 options = options or GameOptions ()
7073
74+ # Load knowledge base specific to this challenge.
75+ options .kb = KnowledgeBase .load (KB_PATH )
76+
7177 # Needed for games with a lot of rooms.
72- options .grammar .allowed_variables_numbering = settings ["force_entity_numbering" ]
73- assert options .grammar .allowed_variables_numbering
78+ options .grammar .allowed_variables_numbering = True
7479
7580 level = settings ["level" ]
7681 if level < 1 or level > 300 :
@@ -167,7 +172,7 @@ def make_game(mode: str, options: GameOptions) -> textworld.Game:
167172
168173 # Generate the quest thats by collecting the coin.
169174 quest = Quest (win_events = [
170- EventCondition (conditions = {M .new_fact ("in" , coin , M .inventory )})
175+ Event (conditions = {M .new_fact ("in" , coin , M .inventory )})
171176 ])
172177
173178 M .quests = [quest ]
0 commit comments