Fix crash when env.step receives multiple commands (e.g. 'GO NORTH. GO EAST.') - #377
Daizhi Liao (dafahaha) wants to merge 1 commit into
Conversation
Handle multi-command output for score and moves.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Can you share an example of the raw text observation returned by the games when multiple commands are sent to it? I want to see the structure of |
|
The regex uses |
|
Sure. With
1 2
0
1 and |
|
So, would a better fix to address |
Problem
Fixes #366
When
env.step()receives a command string containing multiple commands (e.g."GO NORTH. GO EAST."or"DROP PEPPER THEN GET KNIFE"), the Inform7 parser executes all commands but returns multi-line output forscoreandmoves. This causesInform7Data._gather_infos()to crash with aValueErrorbecauseint()cannot parse multi-line text.Root Cause
In
textworld/envs/wrappers/tw_inform7.py, the_gather_infos()method attempts to parsescoreandmovesas integers:The fallback
split("\n")[0]also fails when the first line contains non-numeric text (e.g. command output descriptions before the actual number).Fix
except:toexcept (ValueError, TypeError):for proper exception handlingre.findall(r'\d+', ...)to extract all numbers from multi-line outputNoneif no numbers are found (graceful degradation)Testing
remodule is already imported at the top of the file