def start(path: str, infos: Optional[EnvInfos] = None, wrappers: List[callable] = []) -> Environment: """ Starts a TextWorld environment to play a game. Arguments: path: Path to the game file. infos: For customizing the information returned by this environment (see :py:class:`textworld.EnvInfos <textworld.core.EnvInfos>` for the list of available information). wrappers: List of wrappers to apply to the environment. Returns: TextWorld environment running the provided game. """ # Check the game file exists. if not os.path.isfile(path): msg = "Unable to find game '{}'.".format(os.path.abspath(path)) raise IOError(msg) # Guess the backend from the extension. backend = "glulx" if path.endswith(".ulx") else "zmachine" if backend == "zmachine": env = JerichoEnv(infos) elif backend == "glulx": env = GitGlulxEnv(infos) else: msg = "Unsupported backend: {}".format(backend) raise ValueError(msg) if TWInform7.compatible(path): wrappers = [TWInform7] + list(wrappers) # Apply all wrappers for wrapper in wrappers: env = wrapper(env) env.load(path) return env
def setUp(self): self.env_z8 = Inform7Data(JerichoEnv(self.infos)) self.env_z8.load(self.gamefile_z8) self.env_ulx = Inform7Data(GitGlulxEnv(self.infos)) self.env_ulx.load(self.gamefile_ulx)
def setUp(self): self.env_z8 = StateTracking(JerichoEnv(self.infos)) self.env_z8.load(self.gamefile_z8) self.env_ulx = StateTracking(GitGlulxEnv(self.infos)) self.env_ulx.load(self.gamefile_ulx)