Skip to content

Commit c07c582

Browse files
committed
Patch: do not issue score command when no Inform7 event was detected
1 parent 4a8d333 commit c07c582

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

textworld/envs/glulx/git_glulx_ml.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ def init(self, output: str, game: Game,
152152
self._state_tracking = state_tracking
153153
self._compute_intermediate_reward = compute_intermediate_reward and len(game.quests) > 0
154154
self._objective = game.objective
155+
self._score = 0
155156
self._max_score = sum(quest.reward for quest in game.quests)
156157

157158
def view(self) -> "GlulxGameState":
@@ -320,14 +321,18 @@ def intermediate_reward(self):
320321
@property
321322
def score(self):
322323
if not hasattr(self, "_score"):
323-
output = self._raw
324-
if not self.game_ended:
325-
output = self._env._send("score")
326-
327-
match = re.search("scored (?P<score>[0-9]+) out of a possible (?P<max_score>[0-9]+),", output)
328-
self._score = 0
329-
if match:
330-
self._score = int(match.groupdict()["score"])
324+
# Check if there was any Inform7 events.
325+
if self._feedback == self._raw:
326+
self._score = self.previous_state.score
327+
else:
328+
output = self._raw
329+
if not self.game_ended:
330+
output = self._env._send("score")
331+
332+
match = re.search("scored (?P<score>[0-9]+) out of a possible (?P<max_score>[0-9]+),", output)
333+
self._score = 0
334+
if match:
335+
self._score = int(match.groupdict()["score"])
331336

332337
return self._score
333338

0 commit comments

Comments
 (0)