def test_process_defaults_shape_as_expected_with_gfootball_env(self):
        # Arrange
        raw_obs = self._gfootball_env.reset()

        # Act
        processed_obs = RawObs(
            using=RawObs.standard_keys).set_obs(raw_obs).process()

        self.assertEqual(
            RawObs(using=RawObs.standard_keys).shape, processed_obs.shape)
    def test_output_shape_as_expected_with_gfootball_env_reset(self):
        obs = self._gfootball_env.reset()
        # Act
        raw_obs = RawObs.convert_observation(obs)

        # Assert
        self.assertEqual(RawObs().shape, raw_obs.shape)
    def test_process_all_shape_as_expected_with_gfootball_env(self):
        # Arrange
        raw_obs = self._gfootball_env.reset()

        # Act
        processed_obs = self._sut.set_obs(raw_obs).process()

        self.assertEqual(RawObs().shape, processed_obs.shape)
    def test_output_shape_as_expected_with_kaggle_env_reset(self):
        # Arrange
        obs = self._kaggle_env.reset()

        # Act
        raw_obs = RawObs.convert_observation(obs)

        # Assert
        self.assertEqual(RawObs().shape, raw_obs.shape)
    def test_with_obs_indexed_out_of_list(self):
        # Arrange
        ro = RawObs().set_obs(self._raw_obs_fixture.data[0])

        # Act
        raw_obs = ro.process()

        # Assert
        self.assertEqual(ro.shape, raw_obs.shape)
    def test_process_returns_none_if_nothing_to_do(self):
        # Arrange
        ro = RawObs(using=[]).set_obs(self._raw_obs_fixture.data[0])

        # Act
        raw_obs = ro.process()

        # Assert
        self.assertEqual((1, 0), ro.shape)
        self.assertIsNone(raw_obs)
Example #7
0
    def test_shapes_as_expected_without_env_on_reset(self):
        # Arrange
        raw_obs = self._env.reset()

        # Act
        processed_obs = self._sut.process_obs(raw_obs)

        # Assert
        self.assertIsInstance(processed_obs, np.ndarray)
        self.assertEqual((RawObs().shape[1] + 115, ), processed_obs.shape)
Example #8
0
    def test_shapes_as_expected_with_kaggle_env(self):
        # Arrange
        wrapped_env = self._sut(gym.make("GFootball-kaggle_11_vs_11-v0"))

        # Act
        obs = wrapped_env.reset()

        # Assert
        self.assertIsInstance(obs, np.ndarray)
        self.assertEqual(wrapped_env.observation_space.shape, obs.shape)
        self.assertEqual((RawObs().shape[1] + 115, ), obs.shape)
Example #9
0
    def test_shapes_as_expected_with_env_on_reset(self):
        # Arrange
        wrapped_env = self._sut(self._env)

        # Act
        obs = wrapped_env.reset()

        # Assert
        self.assertIsInstance(obs, np.ndarray)
        self.assertEqual(wrapped_env.observation_space.shape, obs.shape)
        self.assertEqual((RawObs().shape[1] + 115, ), obs.shape)
Example #10
0
    def test_shapes_as_expected_without_env_on_step(self):
        # Arrange
        _ = self._env.reset()
        obs, reward, done, info = self._env.step(0)

        # Act
        obs = self._sut.process_obs(obs)

        # Assert
        self.assertIsInstance(obs, np.ndarray)
        self.assertEqual((RawObs().shape[1] + 115, ), obs.shape)
Example #11
0
    def process_obs(obs: Union[Dict[str, Any], List[Any]],
                    using: List[str] = None) -> np.ndarray:
        """Generate array with simple obs and raw obs."""

        if isinstance(obs, dict):
            obs = obs['players_raw']

        simple_obs = Simple115StateWrapper.convert_observation(
            obs, fixed_positions=False).reshape(-1)
        raw_obs = RawObs(using=using).set_obs(obs[0]).process()

        return np.concatenate([simple_obs, raw_obs.reshape(-1)
                               ]) if raw_obs is not None else simple_obs
Example #12
0
    def __init__(self,
                 env: gym.Env = None,
                 raw_using: List[str] = None,
                 raw_dump_path: str = None) -> None:
        """
        :param env: A gym env, or None.
        :param raw_using: List of keys to use in raw observations.
        """
        if env is not None:
            super().__init__(env)

        self.raw_dump_path = raw_dump_path
        self.raw_obs = RawObs(using=raw_using)

        self.simple_obs_shape = 115
        self.raw_obs_shape = self.raw_obs.shape[1]

        self.observation_space = gym.spaces.Box(low=-np.inf,
                                                high=np.inf,
                                                shape=(self.simple_obs_shape +
                                                       self.raw_obs_shape, ),
                                                dtype=np.float32)
 def setUp(self):
     self._kaggle_env = gym.make("GFootball-kaggle_11_vs_11-v0")
     self._gfootball_env = self._env = FootballEnv(config=Config())
     self._sut = RawObs()
 def setUp(self):
     self._raw_obs_fixture = RawObsFixture()
     self.sut = RawObs(using=RawObs.standard_keys)
     self.sut.set_obs(self._raw_obs_fixture.data)