Skip to content

Commit 355bf6f

Browse files
authored
Merge pull request #26 from MarcCote/enh_better_looking_take_action
Better-looking feedback message for the take command.
2 parents e611f6d + 0bb2766 commit 355bf6f

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

textworld/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class Environment:
163163
>>> command = "take keycard" # Command to send to the game.
164164
>>> game_state, reward, done = env.step(command)
165165
>>> env.render()
166-
Taken
166+
You pick up the keycard from the ground.
167167
"""
168168

169169
@property

textworld/envs/glulx/tests/test_git_glulx_ml.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ def test_feedback(self):
100100

101101
# Check feedback for dropping and taking the carrot.
102102
game_state, _, _ = self.env.step("drop carrot")
103-
assert game_state.feedback.strip() == "Dropped.", game_state.feedback
103+
assert "drop the carrot on the ground" in game_state.feedback
104104
game_state, _, _ = self.env.step("take carrot")
105-
assert game_state.feedback.strip() == "Taken.", game_state.feedback
105+
assert "pick up the carrot from the ground" in game_state.feedback
106106

107107
def test_command_feedback(self):
108108
assert self.game_state.command_feedback.strip() == ""
@@ -113,9 +113,9 @@ def test_command_feedback(self):
113113

114114
# Check command feedback for dropping and taking the carrot.
115115
game_state, _, _ = self.env.step("drop carrot")
116-
assert game_state.command_feedback.strip() == "Dropped.", game_state.command_feedback
116+
assert "drop the carrot on the ground" in game_state.command_feedback
117117
game_state, _, _ = self.env.step("take carrot")
118-
assert game_state.command_feedback.strip() == "Taken.", game_state.command_feedback
118+
assert "pick up the carrot from the ground" in game_state.command_feedback
119119

120120
def test_inventory(self):
121121
assert "carrot" in self.game_state.inventory

textworld/generator/inform7/tests/test_world2inform7.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def test_take_all_and_variants():
247247
env.reset()
248248

249249
game_state, _, done = env.step("take all ball")
250-
assert "red ball: Taken." in game_state.feedback
251-
assert "blue ball: Taken." in game_state.feedback
250+
assert "red ball:" in game_state.feedback
251+
assert "blue ball:" in game_state.feedback
252252
assert "red ball" in game_state.inventory
253253
assert "blue ball" in game_state.inventory

textworld/generator/inform7/world2inform7.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,25 @@ def generate_inform7_source(game, seed=1234, use_i7_description=False):
461461
462462
""")
463463

464+
# Customize reporting of the "take" action.
465+
# Ref: http://inform7.com/learn/man/RB_6_8.html
466+
source += textwrap.dedent("""\
467+
The taking action has an object called previous locale (matched as "from").
468+
469+
Setting action variables for taking:
470+
now previous locale is the holder of the noun.
471+
472+
Report taking something from the location:
473+
say "You pick up [the noun] from the ground." instead.
474+
475+
Report taking something:
476+
say "You take [the noun] from [the previous locale]." instead.
477+
478+
Report dropping something:
479+
say "You drop [the noun] on the ground." instead.
480+
481+
""")
482+
464483
# Special command to print game state.
465484
source += textwrap.dedent("""\
466485
The print state option is a truth state that varies.

0 commit comments

Comments
 (0)