microsoft / jericho

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

Dictionary errors on MacOS Monterey #62

Closed Sirius79 closed 1 year ago

Sirius79 commented 1 year ago

I am having issues running some of the methods like env.get_dictionary() and env.get_valid_actions(). Both of them are giving the error: Error: Word count doesn't match dictionary size!

This is the code snippet I'm using:

  from jericho import *

  env = FrotzEnv("../roms/jericho-game-suite/zork1.z5")
  initial_observation, info = env.reset()
  valid_actions = env.get_valid_actions()
  vocab = env.get_dictionary()

Setup

Can you please help me figure out if I'm missing anything here?

MarcCote commented 1 year ago

Thanks for reporting this. What version of spacy do you have installed?

MarcCote commented 1 year ago

Never mind, the error comes from the ztools code (nothing to do with spacy). Here https://github.com/microsoft/jericho/blob/master/frotz/src/ztools/showdict.c#L71-L75

I don't have access to a Mac right now but I've tested your code example on Python 3.9.15, Linux and it works fine. I assume it's something related to MacOS (or your C compiler).

Sirius79 commented 1 year ago

Understood. I also tried following the solution in #40 but that didn't help.

For now, I have commented out https://github.com/microsoft/jericho/blob/8637c21df1c75672842d521bb21be643bc8b18a3/frotz/src/ztools/showdict.c#L73-L74

Thanks for your help!

MarcCote commented 1 year ago

@Sirius79 can you try printing the value for dict_size and word_count for zork1.z5 ?

Sirius79 commented 1 year ago

@MarcCote I'm getting the following values:

word_count: 697 dict_size: 83397896

The dict_size is changing for each run

MarcCote commented 1 year ago

Ok, that's seems problematic. What's the output of

  from jericho import *

  env = FrotzEnv("../roms/jericho-game-suite/zork1.z5")
  print(env.frotz_lib.get_dictionary_word_count("../roms/jericho-game-suite/zork1.z5"))

?

Sirius79 commented 1 year ago

Getting the following error for the last line:

ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type

MarcCote commented 1 year ago

Opps, try this.

  from jericho import *
  env = FrotzEnv("../roms/jericho-game-suite/zork1.z5")
  print(env.frotz_lib.get_dictionary_word_count(env.story_file))
Sirius79 commented 1 year ago

This prints 697

MarcCote commented 1 year ago

Ok that's interesting. It seems get_dictionary is missing an argument! Can you try changing this line https://github.com/microsoft/jericho/blob/master/jericho/jericho.py#L333 from

frotz_lib.get_dictionary.argtypes = [POINTER(DictionaryWord)]

to

frotz_lib.get_dictionary.argtypes = [POINTER(DictionaryWord), c_int]
Sirius79 commented 1 year ago

Yep it's working now! Thanks a lot for your help!

MarcCote commented 1 year ago

Awesome! I'll make a commit and make a release later today.

MarcCote commented 1 year ago

The main branch should work now.

Sirius79 commented 1 year ago

Thanks for the quick fix!