@@ -47,7 +47,12 @@ def build_test_game():
4747 chest .add_property ("open" )
4848 R2 .add (chest )
4949
50- M .set_quest_from_commands (commands )
50+ quest1 = M .new_quest_using_commands (commands )
51+ quest1 .reward = 2
52+ quest2 = M .new_quest_using_commands (commands + ["close chest" ])
53+ quest2 .set_winning_conditions ([M .new_fact ("in" , carrot , chest ),
54+ M .new_fact ("closed" , chest )])
55+ M ._quests = [quest1 , quest2 ]
5156 game = M .build ()
5257 return game
5358
@@ -128,7 +133,10 @@ def test_inventory(self):
128133 game_state , _ , _ = self .env .step ("take carrot" )
129134 game_state , _ , _ = self .env .step ("go east" )
130135 game_state , _ , _ = self .env .step ("insert carrot into chest" )
131- assert game_state .inventory == ""
136+ assert "carrying nothing" in game_state .inventory
137+
138+ game_state , _ , _ = self .env .step ("close chest" )
139+ assert game_state .inventory == "" # Game has ended
132140
133141 def test_objective (self ):
134142 assert self .game_state .objective .strip () in self .game_state .feedback
@@ -145,16 +153,19 @@ def test_description(self):
145153
146154 # End the game.
147155 game_state , _ , _ = self .env .step ("insert carrot into chest" )
156+ game_state , _ , _ = self .env .step ("close chest" )
148157 assert game_state .description == ""
149158
150159 def test_score (self ):
151160 assert self .game_state .score == 0
152- assert self .game_state .max_score == 1
161+ assert self .game_state .max_score == 3
153162 game_state , _ , _ = self .env .step ("go east" )
154163 assert game_state .score == 0
155164 game_state , _ , _ = self .env .step ("insert carrot into chest" )
156- assert game_state .score == 1
157- assert game_state .max_score == 1
165+ assert game_state .score == 2
166+ assert game_state .max_score == 3
167+ game_state , _ , _ = self .env .step ("close chest" )
168+ assert game_state .score == 3
158169
159170 def test_game_ended_when_no_quest (self ):
160171 M = GameMaker ()
@@ -184,6 +195,8 @@ def test_has_won(self):
184195 game_state , _ , _ = self .env .step ("go east" )
185196 assert not game_state .has_won
186197 game_state , _ , done = self .env .step ("insert carrot into chest" )
198+ assert not game_state .has_won
199+ game_state , _ , done = self .env .step ("close chest" )
187200 assert game_state .has_won
188201
189202 def test_has_lost (self ):
@@ -210,31 +223,33 @@ def test_intermediate_reward(self):
210223 game_state , _ , _ = self .env .step ("close wooden door" )
211224 assert game_state .intermediate_reward == 0
212225 game_state , _ , done = self .env .step ("insert carrot into chest" )
226+ game_state , _ , done = self .env .step ("close chest" )
213227 assert done
214228 assert game_state .has_won
215229 assert game_state .intermediate_reward == 1
216230
217231 def test_policy_commands (self ):
218- assert self .game_state .policy_commands == self .game .quests [ 0 ] .commands
232+ assert self .game_state .policy_commands == self .game .main_quest .commands
219233
220234 game_state , _ , _ = self .env .step ("drop carrot" )
221- expected = ["take carrot" ] + self .game .quests [ 0 ] .commands
235+ expected = ["take carrot" ] + self .game .main_quest .commands
222236 assert game_state .policy_commands == expected , game_state .policy_commands
223237
224238 game_state , _ , _ = self .env .step ("take carrot" )
225- expected = self .game .quests [ 0 ] .commands
239+ expected = self .game .main_quest .commands
226240 assert game_state .policy_commands == expected
227241
228242 game_state , _ , _ = self .env .step ("go east" )
229- expected = self .game .quests [ 0 ] .commands [1 :]
243+ expected = self .game .main_quest .commands [1 :]
230244 assert game_state .policy_commands == expected
231245
232246 game_state , _ , _ = self .env .step ("insert carrot into chest" )
247+ game_state , _ , _ = self .env .step ("close chest" )
233248 assert game_state .policy_commands == [], game_state .policy_commands
234249
235250 # Test parallel subquests.
236251 game_state = self .env .reset ()
237- commands = self .game .quests [ 0 ] .commands
252+ commands = self .game .main_quest .commands
238253 assert game_state .policy_commands == commands
239254 game_state , _ , _ = self .env .step ("close wooden door" )
240255 assert game_state .policy_commands == ["open wooden door" ] + commands
@@ -248,15 +263,15 @@ def test_policy_commands(self):
248263
249264 # Irreversible action.
250265 game_state = self .env .reset ()
251- assert game_state .policy_commands == self .game .quests [ 0 ] .commands
266+ assert game_state .policy_commands == self .game .main_quest .commands
252267 game_state , _ , done = self .env .step ("eat carrot" )
253268 assert done
254269 assert game_state .has_lost
255270 assert len (game_state .policy_commands ) == 0
256271
257272 def test_admissible_commands (self ):
258273 game_state = self .env .reset ()
259- for command in self .game .quests [ 0 ] .commands :
274+ for command in self .game .main_quest .commands :
260275 assert command in game_state .admissible_commands
261276 game_state , _ , done = self .env .step (command )
262277
0 commit comments