@@ -165,6 +165,54 @@ def test_names_disambiguation():
165165 assert "tasty apple" in game_state .inventory
166166 assert "tasty apple" not in game_state .description
167167
168+ # With two-argument actions.
169+ M = textworld .GameMaker ()
170+ roomA = M .new_room ("roomA" )
171+ roomB = M .new_room ("roomB" )
172+ roomC = M .new_room ("roomC" )
173+ M .set_player (roomA )
174+
175+ path = M .connect (roomA .east , roomB .west )
176+ gateway = M .new_door (path , name = "gateway" )
177+
178+ path = M .connect (roomA .west , roomC .east )
179+ rectangular_gateway = M .new_door (path , name = "rectangular gateway" )
180+
181+ keycard = M .new (type = "k" , name = "keycard" )
182+ rectangular_keycard = M .new (type = "k" , name = "rectangular keycard" )
183+ roomA .add (keycard , rectangular_keycard )
184+
185+ M .add_fact ("match" , keycard , gateway )
186+ M .add_fact ("match" , rectangular_keycard , rectangular_gateway )
187+ M .add_fact ("locked" , gateway )
188+ M .add_fact ("locked" , rectangular_gateway )
189+
190+ game = M .build ()
191+ game_name = "test_names_disambiguation"
192+ with make_temp_directory (prefix = game_name ) as tmpdir :
193+ game_file = compile_game (game , game_name , games_folder = tmpdir )
194+ env = textworld .start (game_file )
195+ env .reset ()
196+ game_state , _ , done = env .step ("take keycard" )
197+ assert "keycard" in game_state .inventory
198+ game_state , _ , done = env .step ("take keycard" )
199+ assert "rectangular keycard" in game_state .inventory
200+
201+ game_state , _ , done = env .step ("unlock gateway with rectangular keycard" )
202+ assert "That doesn't seem to fit the lock." in game_state .command_feedback
203+ game_state , _ , done = env .step ("unlock gateway with keycard" )
204+ game_state , _ , done = env .step ("open gateway" )
205+ game_state , _ , done = env .step ("go east" )
206+ assert "-= Roomb =-" in game_state .description
207+
208+ game_state , _ , done = env .step ("go west" )
209+ game_state , _ , done = env .step ("unlock rectangular gateway with keycard" )
210+ assert "That doesn't seem to fit the lock." in game_state .command_feedback
211+ game_state , _ , done = env .step ("unlock rectangular gateway with rectangular keycard" )
212+ game_state , _ , done = env .step ("open rectangular gateway" )
213+ game_state , _ , done = env .step ("go west" )
214+ assert "-= Roomc =-" in game_state .description
215+
168216
169217def test_take_all_and_variants ():
170218 M = textworld .GameMaker ()
0 commit comments