Example #1
0
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.
    if path.endswith(".ulx"):
        env = GitGlulxEnv(infos)
    elif re.search(r"\.z[1-8]", path):
        env = JerichoEnv(infos)
    else:
        msg = "Unsupported game format: {}".format(path)
        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)