Environment stuck in a state of Zork1
The environment get stuck when trying to get_valid_actions() after loading this state and applying step('put sack in egg').
The state is attached by a pickle file state.pickle.zip, and the following code can reproduce the problem.
import jericho
import pickle
env = jericho.FrotzEnv('zork1.z5')
with open('state.pickle', 'rb') as f:
state = pickle.load(f)
env.set_state(state)
env.step('put sack in egg')
env.get_valid_actions() # stuck here
Thank you for the bug report. After checking out an older version of Jericho (3.0.5) I can replicate the issue as described. Digging further, the get_valid_actions() call is getting stuck on the action "drop all down sack."
Examining the inventory before the hang: "You are carrying:\n A bird's nest\n The bird's nest contains:\n A broken jewel-encrusted egg\n The broken jewel-encrusted egg contains:\n A brown sack\n\n"
So we have 3 containers: Nest > Egg > Sack and we're asking to put everything into the sack, including the nest and egg. Zork has trouble handling this type of container switching.
Other buggy behaviors starting from the "put sack in egg" state is to "put egg in sack" - in this case it doesn't hang but if you examine the inventory afterwards "You are carrying:\n A bird's nest" (the egg and sack have completely disappeared). Similarly if we "put nest in sack", the resulting state is 'You are empty-handed.'
It's hard to address the root of the issue, which would require better containership programming in Zork. But there might be a couple workarounds:
- Implement a timeout on valid action search so as to prevent a full hang. (Maybe this isn't too hard if valid action search is already being performed in separate threads.)
- Manually disallow actions that put containers inside of each other. Or equivalently write zork-specific post-step routines to flatten any stacked containers.
@MarcCote curious if you had encountered this issue as well?
Never happened to me. Interesting how we are finding bugs in 40+ years' games :)!
The time-out is a good idea.
Thanks, I currently use a timeout to filter out the actions that will cause a hang.