microsoft / jericho

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

Add dedicated method to change seed #34

Closed MarcCote closed 4 years ago

MarcCote commented 4 years ago

This PR adds the seed method to FrotzEnv that allows changing seed without creating a new instance of FrotzEnv.

NB: the default seed is the one from the bindings (i.e. the walkthrough) if it exists. Otherwise, the value -1 is used.

mhauskn commented 4 years ago

Thanks for this PR! I like the changes except for the side effect of having seed() reset the game. How would you feel about having a seed method with a small note that reset() needs to be called for the seed to take effect?

    def seed(self, seed=None):
        '''
        Sets the random seed used by the emulator.

        :param seed: The random seed. The default of `None` will use the seed \
        from the game's walkthrough. A value of `-1` will seed to time.
        :type seed: Int
        :returns: The value of the random seed.

        .. note:: :meth:`jericho.FrotzEnv.reset()` must be called before the seed takes effect.

        '''
        seed = seed or self.bindings.get('seed', -1)
        self._seed = seed
        return seed