@@ -147,7 +147,7 @@ def make_game_with(world, quests=None, grammar=None):
147147 return game
148148
149149
150- def make_game (world_size : int , nb_objects : int , quest_length : int ,
150+ def make_game (world_size : int , nb_objects : int , quest_length : int , quest_breadth : int ,
151151 grammar_flags : Mapping = {},
152152 rngs : Optional [Dict [str , RandomState ]] = None
153153 ) -> Game :
@@ -158,6 +158,7 @@ def make_game(world_size: int, nb_objects: int, quest_length: int,
158158 world_size: Number of rooms in the world.
159159 nb_objects: Number of objects in the world.
160160 quest_length: Minimum nb. of actions the quest requires to be completed.
161+ quest_breadth: How many branches the quest can have.
161162 grammar_flags: Options for the grammar.
162163
163164 Returns:
@@ -175,14 +176,34 @@ def make_game(world_size: int, nb_objects: int, quest_length: int,
175176 world = make_world (world_size , nb_objects = 0 , rngs = rngs )
176177
177178 # Sample a quest according to quest_length.
178- options = ChainingOptions ()
179+ class Options (ChainingOptions ):
180+
181+ def get_rules (self , depth ):
182+ if depth == 0 :
183+ # Last action should not be "go <dir>".
184+ return data .get_rules ().get_matching ("^(?!go.*).*" )
185+ else :
186+ return super ().get_rules (depth )
187+
188+ options = Options ()
179189 options .backward = True
190+ options .min_depth = 1
180191 options .max_depth = quest_length
192+ options .min_breadth = 1
193+ options .max_breadth = quest_breadth
181194 options .create_variables = True
182195 options .rng = rngs ['rng_quest' ]
183196 options .restricted_types = {"r" , "d" }
184197 chain = sample_quest (world .state , options )
198+
199+ subquests = []
200+ for i in range (1 , len (chain .nodes )):
201+ if chain .nodes [i ].breadth != chain .nodes [i - 1 ].breadth :
202+ quest = Quest (chain .actions [:i ])
203+ subquests .append (quest )
204+
185205 quest = Quest (chain .actions )
206+ subquests .append (quest )
186207
187208 # Set the initial state required for the quest.
188209 world .state = chain .initial_state
@@ -191,7 +212,9 @@ def make_game(world_size: int, nb_objects: int, quest_length: int,
191212 world .populate (nb_objects , rng = rngs ['rng_objects' ])
192213
193214 grammar = make_grammar (grammar_flags , rng = rngs ['rng_grammar' ])
194- game = make_game_with (world , [quest ], grammar )
215+ game = make_game_with (world , subquests , grammar )
216+ game .change_grammar (grammar )
217+
195218 return game
196219
197220
0 commit comments