microsoft / jericho

A learning environment for man-made Interactive Fiction games.
GNU General Public License v2.0
253 stars 42 forks source link

Environment stuck in a state of Zork1 #53

Open wu-qing-157 opened 2 years ago

wu-qing-157 commented 2 years ago

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
mhauskn commented 2 years ago

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:

@MarcCote curious if you had encountered this issue as well?

MarcCote commented 2 years ago

Never happened to me. Interesting how we are finding bugs in 40+ years' games :)!

The time-out is a good idea.

wu-qing-157 commented 2 years ago

Thanks, I currently use a timeout to filter out the actions that will cause a hang.