Skip to content

Commit e49e646

Browse files
committed
BF: object disambiguation for 2-arity actions.
1 parent c25477a commit e49e646

File tree

2 files changed

+54
-7
lines changed

2 files changed

+54
-7
lines changed

textworld/generator/inform7/tests/test_world2inform7.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

169217
def test_take_all_and_variants():
170218
M = textworld.GameMaker()

textworld/generator/inform7/world2inform7.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,10 @@ def generate_inform7_source(game, seed=1234, use_i7_description=False):
329329
# Refeering to an object by it whole name shouldn't be ambiguous.
330330
source += textwrap.dedent("""\
331331
Does the player mean doing something with something (called target):
332-
if the player's command matches the text printed name of the target:
333-
it is very likely.
332+
if the player's command matches the text printed name of the target and the second noun is nothing:
333+
it is very likely;
334+
if the player's command matches the text printed name of the target and the player's command matches the text printed name of the second noun:
335+
it is very likely. [Handle action with two arguments.]
334336
335337
""")
336338

@@ -391,11 +393,8 @@ def generate_inform7_source(game, seed=1234, use_i7_description=False):
391393
remove the list of containers from L;
392394
remove the list of supporters from L;
393395
remove the list of doors from L;
394-
if the number of entries in L is 1:
395-
say "There is [L with indefinite articles] on the floor.";
396-
else if the number of entries in L is greater than 1:
397-
say "There's [L with indefinite articles] on the floor.";
398-
396+
say "There is [L with indefinite articles] on the floor.";
397+
399398
""")
400399

401400
# Print properties of objects when listing the inventory contents and the room contents.

0 commit comments

Comments
 (0)