def test_show_cloaked(self): self.assertTrue(self._info.options.show_cloaked) self.god() self.move_camera(32, 32) # Create some units. One cloaked, one to see it without detection. self.create_unit(unit_type=units.Protoss.DarkTemplar, owner=1, pos=(30, 30)) self.create_unit(unit_type=units.Protoss.Sentry, owner=2, pos=(28, 30)) self.step(16) obs = self.observe() # Verify both can see it, but that only the owner knows details. p1 = utils.get_unit(obs[0], unit_type=units.Protoss.DarkTemplar) p2 = utils.get_unit(obs[1], unit_type=units.Protoss.DarkTemplar) self.assert_unit(p1, display_type=sc_raw.Visible, health=40, shield=80, cloak=sc_raw.CloakedAllied) self.assert_unit(p2, display_type=sc_raw.Hidden, health=0, shield=0, cloak=sc_raw.Cloaked) screen1 = self._features.transform_obs(obs[0])["feature_screen"] screen2 = self._features.transform_obs(obs[1])["feature_screen"] dt = utils.xy_locs(screen1.unit_type == units.Protoss.DarkTemplar)[0] self.assert_layers(screen1, dt, unit_type=units.Protoss.DarkTemplar, unit_hit_points=40, unit_shields=80, cloaked=1) self.assert_layers(screen2, dt, unit_type=units.Protoss.DarkTemplar, unit_hit_points=0, unit_shields=0, cloaked=1) # Create an observer so the opponent has detection. self.create_unit(unit_type=units.Protoss.Observer, owner=2, pos=(28, 28)) self.step(16) # It takes a few frames for the observer to detect. obs = self.observe() # Verify both can see it, with the same details p1 = utils.get_unit(obs[0], unit_type=units.Protoss.DarkTemplar) p2 = utils.get_unit(obs[1], unit_type=units.Protoss.DarkTemplar) self.assert_unit(p1, display_type=sc_raw.Visible, health=40, shield=80, cloak=sc_raw.CloakedAllied) self.assert_unit(p2, display_type=sc_raw.Visible, health=40, shield=80, cloak=sc_raw.CloakedDetected) screen1 = self._features.transform_obs(obs[0])["feature_screen"] screen2 = self._features.transform_obs(obs[1])["feature_screen"] dt = utils.xy_locs(screen1.unit_type == units.Protoss.DarkTemplar)[0] self.assert_layers(screen1, dt, unit_type=units.Protoss.DarkTemplar, unit_hit_points=40, unit_shields=80, cloaked=1) self.assert_layers(screen2, dt, unit_type=units.Protoss.DarkTemplar, unit_hit_points=40, unit_shields=80, cloaked=1)
def test_camera_movement_delay(self): obs1 = self.observe() screen1 = self._features.transform_obs(obs1[0])["feature_screen"] nexus1 = utils.xy_locs(screen1.unit_type == units.Protoss.Nexus) self.step(1) obs2 = self.observe() screen2 = self._features.transform_obs(obs2[0])["feature_screen"] nexus2 = utils.xy_locs(screen2.unit_type == units.Protoss.Nexus) self.assertEqual(nexus1, nexus2) # Same place. loc = obs1[0].observation.raw_data.player.camera self.move_camera(loc.x + 3, loc.y + 3) self.step(EXPECTED_ACTION_DELAY) obs3 = self.observe() screen3 = self._features.transform_obs(obs3[0])["feature_screen"] nexus3 = utils.xy_locs(screen3.unit_type == units.Protoss.Nexus) self.assertNotEqual(nexus1, nexus3) # Different location due to camera.
def test_effects(self): def get_effect_proto(obs, effect_id): for e in obs.observation.raw_data.effects: if e.effect_id == effect_id: return e return None def get_effect_obs(obs, effect_id): for e in obs: if e.effect == effect_id: return e return None self.god() self.move_camera(32, 32) # Create some sentries. self.create_unit(unit_type=units.Protoss.Sentry, owner=1, pos=(30, 30)) self.create_unit(unit_type=units.Protoss.Stalker, owner=1, pos=(28, 30)) self.create_unit(unit_type=units.Protoss.Phoenix, owner=2, pos=(30, 28)) self.step() obs = self.observe() # Give enough energy. sentry = utils.get_unit(obs[0], unit_type=units.Protoss.Sentry) stalker = utils.get_unit(obs[0], unit_type=units.Protoss.Stalker) pheonix = utils.get_unit(obs[0], unit_type=units.Protoss.Phoenix) self.set_energy(sentry.tag, 200) self.set_energy(pheonix.tag, 200) self.step() obs = self.observe() self.raw_unit_command(0, "Effect_GuardianShield_quick", sentry.tag) self.step(16) obs = self.observe() self.assertIn(buffs.Buffs.GuardianShield, utils.get_unit(obs[0], tag=sentry.tag).buff_ids) self.assertIn(buffs.Buffs.GuardianShield, utils.get_unit(obs[1], tag=sentry.tag).buff_ids) self.assertIn(buffs.Buffs.GuardianShield, utils.get_unit(obs[0], tag=stalker.tag).buff_ids) self.assertIn(buffs.Buffs.GuardianShield, utils.get_unit(obs[1], tag=stalker.tag).buff_ids) self.assertNotIn(buffs.Buffs.GuardianShield, utils.get_unit(obs[0], tag=pheonix.tag).buff_ids) self.assertNotIn(buffs.Buffs.GuardianShield, utils.get_unit(obs[1], tag=pheonix.tag).buff_ids) # Both players should see the shield. e = get_effect_proto(obs[0], features.Effects.GuardianShield) self.assertIsNotNone(e) self.assert_point(e.pos[0], (30, 30)) self.assertEqual(e.alliance, sc_raw.Self) self.assertEqual(e.owner, 1) self.assertGreater(e.radius, 3) e = get_effect_proto(obs[1], features.Effects.GuardianShield) self.assertIsNotNone(e) self.assert_point(e.pos[0], (30, 30)) self.assertEqual(e.alliance, sc_raw.Enemy) self.assertEqual(e.owner, 1) self.assertGreater(e.radius, 3) # Should show up on the feature layers too. transformed_obs1 = self._features.transform_obs(obs[0]) transformed_obs2 = self._features.transform_obs(obs[1]) screen1 = transformed_obs1["feature_screen"] screen2 = transformed_obs2["feature_screen"] sentry_pos = utils.xy_locs(screen1.unit_type == units.Protoss.Sentry)[0] self.assert_layers(screen1, sentry_pos, unit_type=units.Protoss.Sentry, effects=features.Effects.GuardianShield, buffs=buffs.Buffs.GuardianShield) self.assert_layers(screen2, sentry_pos, unit_type=units.Protoss.Sentry, effects=features.Effects.GuardianShield, buffs=buffs.Buffs.GuardianShield) phoenix_pos = utils.xy_locs(screen1.unit_type == units.Protoss.Phoenix)[0] self.assert_layers(screen1, phoenix_pos, unit_type=units.Protoss.Phoenix, effects=features.Effects.GuardianShield, buffs=0) self.assert_layers(screen2, phoenix_pos, unit_type=units.Protoss.Phoenix, effects=features.Effects.GuardianShield, buffs=0) # Also in the raw_effects. raw1 = transformed_obs1["raw_effects"] e = get_effect_obs(raw1, features.Effects.GuardianShield) self.assertIsNotNone(e) # Not located at (30, 30) due to map shape and minimap coords. self.assertGreater(e.x, 20) self.assertGreater(e.y, 20) self.assertEqual(e.alliance, sc_raw.Self) self.assertEqual(e.owner, 1) self.assertGreater(e.radius, 3) self.raw_unit_command(1, "Effect_GravitonBeam_screen", pheonix.tag, target=stalker.tag) self.step(32) obs = self.observe() self.assertIn(buffs.Buffs.GravitonBeam, utils.get_unit(obs[0], tag=stalker.tag).buff_ids) self.assertIn(buffs.Buffs.GravitonBeam, utils.get_unit(obs[1], tag=stalker.tag).buff_ids) self.assertNotIn(buffs.Buffs.GravitonBeam, utils.get_unit(obs[0], tag=sentry.tag).buff_ids) self.assertNotIn(buffs.Buffs.GravitonBeam, utils.get_unit(obs[1], tag=sentry.tag).buff_ids) self.assertNotIn(buffs.Buffs.GravitonBeam, utils.get_unit(obs[0], tag=pheonix.tag).buff_ids) self.assertNotIn(buffs.Buffs.GravitonBeam, utils.get_unit(obs[1], tag=pheonix.tag).buff_ids)