gameboy_worlds.interface.harvest_moon.environments

 1from typing import Optional, Dict, Any, List, Tuple
 2
 3from gymnasium import spaces
 4
 5from gameboy_worlds.emulation.harvest_moon.base_metrics import CoreHarvestMoonMetrics
 6from gameboy_worlds.utils import load_parameters, log_dict, log_info
 7from gameboy_worlds.emulation.emulator import Emulator
 8from gameboy_worlds.emulation.harvest_moon.trackers import (
 9    CoreHarvestMoonTracker,
10    HarvestMoonOCRTracker,
11)
12from gameboy_worlds.interface.environment import (
13    DummyEnvironment,
14    Environment,
15    TestEnvironmentMixin,
16    TrainEnvironmentMixin,
17)
18from gameboy_worlds.interface.controller import Controller
19
20import gymnasium as gym
21import numpy as np
22
23
24class HarvestMoonEnvironment(DummyEnvironment):
25    """
26    A basic Harvest Moon Environment.
27    """
28
29    REQUIRED_EMULATOR = Emulator
30    REQUIRED_STATE_TRACKER = CoreHarvestMoonMetrics
31
32
33class HarvestMoonOCREnvironment(HarvestMoonEnvironment):
34    """
35    A Harvest Moon Environment that includes OCR region captures and agent state.
36    """
37
38    REQUIRED_STATE_TRACKER = HarvestMoonOCRTracker
39    REQUIRED_EMULATOR = Emulator
40
41    @staticmethod
42    def override_emulator_kwargs(emulator_kwargs: dict) -> dict:
43        Environment.override_state_tracker_class(
44            emulator_kwargs, HarvestMoonOCREnvironment.REQUIRED_STATE_TRACKER
45        )
46        return emulator_kwargs
47
48
49class HarvestMoonTestEnvironment(TestEnvironmentMixin, HarvestMoonOCREnvironment):
50    pass
51
52
53class HarvestMoonTrainEnvironment(TrainEnvironmentMixin, HarvestMoonOCREnvironment):
54    pass
class HarvestMoonEnvironment(typing.Generic[~ObsType, ~ActType]):
25class HarvestMoonEnvironment(DummyEnvironment):
26    """
27    A basic Harvest Moon Environment.
28    """
29
30    REQUIRED_EMULATOR = Emulator
31    REQUIRED_STATE_TRACKER = CoreHarvestMoonMetrics

A basic Harvest Moon Environment.

REQUIRED_EMULATOR = <class 'gameboy_worlds.emulation.emulator.Emulator'>

The highest level emulator that the environment can interface with.

The state tracker that tracks the minimal state information required for the environment to function.

class HarvestMoonOCREnvironment(typing.Generic[~ObsType, ~ActType]):
34class HarvestMoonOCREnvironment(HarvestMoonEnvironment):
35    """
36    A Harvest Moon Environment that includes OCR region captures and agent state.
37    """
38
39    REQUIRED_STATE_TRACKER = HarvestMoonOCRTracker
40    REQUIRED_EMULATOR = Emulator
41
42    @staticmethod
43    def override_emulator_kwargs(emulator_kwargs: dict) -> dict:
44        Environment.override_state_tracker_class(
45            emulator_kwargs, HarvestMoonOCREnvironment.REQUIRED_STATE_TRACKER
46        )
47        return emulator_kwargs

A Harvest Moon Environment that includes OCR region captures and agent state.

The state tracker that tracks the minimal state information required for the environment to function.

REQUIRED_EMULATOR = <class 'gameboy_worlds.emulation.emulator.Emulator'>

The highest level emulator that the environment can interface with.

@staticmethod
def override_emulator_kwargs(emulator_kwargs: dict) -> dict:
42    @staticmethod
43    def override_emulator_kwargs(emulator_kwargs: dict) -> dict:
44        Environment.override_state_tracker_class(
45            emulator_kwargs, HarvestMoonOCREnvironment.REQUIRED_STATE_TRACKER
46        )
47        return emulator_kwargs

Override default emulator keyword arguments for this environment.

Override this method in subclasses to modify the default emulator keyword arguments.

You may want to use override_state_tracker_class or that style to ensure compatibility of state tracker classes.

Arguments:
  • emulator_kwargs (dict): Incoming emulator keyword arguments.
Returns:

dict: The overridden emulator keyword arguments.

class HarvestMoonTestEnvironment(typing.Generic[~ObsType, ~ActType]):
50class HarvestMoonTestEnvironment(TestEnvironmentMixin, HarvestMoonOCREnvironment):
51    pass

Mixin class for testing environments. Ensures the State Tracker used is a TestTrackerMixin and checks these for termination / truncation.

class HarvestMoonTrainEnvironment(typing.Generic[~ObsType, ~ActType]):
54class HarvestMoonTrainEnvironment(TrainEnvironmentMixin, HarvestMoonOCREnvironment):
55    pass

Mixin class for training environments. Records the allowed initial states for training and random shuffles between them when resetting.