@@ -89,7 +89,7 @@ def _detect_i7_events_debug_tags(text: str) -> Tuple[List[str], str]:
8989 """
9090 matches = []
9191 open_tags = []
92- for match in re .findall ("\[[^]]+\]\n ?" , text ):
92+ for match in re .findall (r "\[[^]]+\]\n?" , text ):
9393 text = text .replace (match , "" ) # Remove i7 debug tags.
9494 tag_name = match .strip ()[1 :- 1 ] # Strip starting '[' and trailing ']'.
9595
@@ -127,8 +127,6 @@ def __init__(self, *args, **kwargs):
127127 :param kwargs: The kwargs
128128 """
129129 super ().__init__ (* args , ** kwargs )
130- self ._has_won = False
131- self ._has_lost = False
132130 self .has_timeout = False
133131 self ._state_tracking = False
134132 self ._compute_intermediate_reward = False
@@ -153,7 +151,7 @@ def init(self, output: str, game: Game,
153151 self ._compute_intermediate_reward = compute_intermediate_reward and len (game .quests ) > 0
154152 self ._objective = game .objective
155153 self ._score = 0
156- self ._max_score = sum ( quest . reward for quest in game . quests )
154+ self ._max_score = self . _game_progression . max_score
157155
158156 def view (self ) -> "GlulxGameState" :
159157 """
@@ -218,12 +216,6 @@ def update(self, command: str, output: str) -> "GlulxGameState":
218216 # An action that affects the state of the game.
219217 game_state ._game_progression .update (game_state ._action )
220218
221- if game_state ._compute_intermediate_reward :
222- if game_state ._game_progression .winning_policy is None :
223- game_state ._has_lost = True
224- elif len (game_state ._game_progression .winning_policy ) == 0 :
225- game_state ._has_won = True
226-
227219 return game_state
228220
229221 @property
@@ -321,18 +313,22 @@ def intermediate_reward(self):
321313 @property
322314 def score (self ):
323315 if not hasattr (self , "_score" ):
324- # Check if there was any Inform7 events.
325- if self ._feedback == self ._raw :
326- self ._score = self .previous_state .score
316+ if self ._state_tracking :
317+ self ._score = self ._game_progression .score
327318 else :
328- output = self ._raw
329- if not self .game_ended :
330- output = self ._env ._send ("score" )
331319
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" ])
320+ # Check if there was any Inform7 events.
321+ if self ._feedback == self ._raw :
322+ self ._score = self .previous_state .score
323+ else :
324+ output = self ._raw
325+ if not self .game_ended :
326+ output = self ._env ._send ("score" )
327+
328+ match = re .search ("scored (?P<score>[0-9]+) out of a possible (?P<max_score>[0-9]+)," , output )
329+ self ._score = 0
330+ if match :
331+ self ._score = int (match .groupdict ()["score" ])
336332
337333 return self ._score
338334
@@ -342,11 +338,23 @@ def max_score(self):
342338
343339 @property
344340 def has_won (self ):
345- return self ._has_won or '*** The End ***' in self .feedback
341+ if not hasattr (self , "_has_won" ):
342+ if self ._compute_intermediate_reward :
343+ self ._has_won = self ._game_progression .completed
344+ else :
345+ self ._has_won = '*** The End ***' in self .feedback
346+
347+ return self ._has_won
346348
347349 @property
348350 def has_lost (self ):
349- return self ._has_lost or '*** You lost! ***' in self .feedback
351+ if not hasattr (self , "_has_lost" ):
352+ if self ._compute_intermediate_reward :
353+ self ._has_lost = self ._game_progression .failed
354+ else :
355+ self ._has_lost = '*** You lost! ***' in self .feedback
356+
357+ return self ._has_lost
350358
351359 @property
352360 def game_ended (self ) -> bool :
0 commit comments