Exemplo n.º 1
0
  def test_disable_fog(self):
    obs = self.observe()

    for i, o in enumerate(obs):
      # Probes are active gathering
      for u in utils.get_units(o, unit_type=units.Protoss.Probe).values():
        self.assert_unit(u, display_type=sc_raw.Visible, is_active=True)

      # All Nexus are idle.
      own = utils.get_unit(o, unit_type=units.Protoss.Nexus, owner=i+1)
      other = utils.get_unit(o, unit_type=units.Protoss.Nexus, owner=2-i)
      self.assert_unit(own, display_type=sc_raw.Visible, is_active=False)
      self.assert_unit(other, display_type=sc_raw.Visible, is_active=False)
      self.assertEmpty(own.orders)
      self.assertEmpty(other.orders)

      # Give it an action.
      self.raw_unit_command(i, "Train_Probe_quick", own.tag)

    self.step(32)
    obs = self.observe()

    # All Nexus are active.
    for i, o in enumerate(obs):
      own = utils.get_unit(o, unit_type=units.Protoss.Nexus, owner=i+1)
      other = utils.get_unit(o, unit_type=units.Protoss.Nexus, owner=2-i)
      self.assert_unit(own, display_type=sc_raw.Visible, is_active=True)
      self.assert_unit(other, display_type=sc_raw.Visible, is_active=True)
      self.assertLen(own.orders, 1)
      self.assertEmpty(other.orders)
Exemplo n.º 2
0
  def test_active(self):
    obs = self.observe()

    # P1 can see P2.
    self.create_unit(
        unit_type=units.Protoss.Observer, owner=1,
        pos=utils.get_unit(obs[1], unit_type=units.Protoss.Nexus).pos)

    self.step(32)  # Make sure visibility updates.
    obs = self.observe()

    for i, o in enumerate(obs):
      # Probes are active gathering
      for u in utils.get_units(o, unit_type=units.Protoss.Probe).values():
        self.assert_unit(u, display_type=sc_raw.Visible, is_active=True)

      # Own Nexus is idle
      nexus = utils.get_unit(o, unit_type=units.Protoss.Nexus, owner=i+1)
      self.assert_unit(nexus, display_type=sc_raw.Visible, is_active=False)
      self.assertEmpty(nexus.orders)

      # Give it an action.
      self.raw_unit_command(i, "Train_Probe_quick", nexus.tag)

    # P1 can tell P2's Nexus is idle.
    nexus = utils.get_unit(obs[0], unit_type=units.Protoss.Nexus, owner=2)
    self.assert_unit(nexus, display_type=sc_raw.Visible, is_active=False)

    # Observer is idle.
    self.assert_unit(utils.get_unit(obs[0], unit_type=units.Protoss.Observer),
                     display_type=sc_raw.Visible, is_active=False)
    self.assert_unit(utils.get_unit(obs[1], unit_type=units.Protoss.Observer),
                     display_type=sc_raw.Hidden, is_active=False)

    self.step(32)
    obs = self.observe()

    # All Nexus are now active
    nexus0 = utils.get_unit(obs[0], unit_type=units.Protoss.Nexus, owner=1)
    nexus1 = utils.get_unit(obs[0], unit_type=units.Protoss.Nexus, owner=2)
    nexus2 = utils.get_unit(obs[1], unit_type=units.Protoss.Nexus)
    self.assert_unit(nexus0, display_type=sc_raw.Visible, is_active=True)
    self.assert_unit(nexus1, display_type=sc_raw.Visible, is_active=True)
    self.assert_unit(nexus2, display_type=sc_raw.Visible, is_active=True)
    self.assertLen(nexus0.orders, 1)
    self.assertLen(nexus2.orders, 1)
    self.assertEmpty(nexus1.orders)  # Can't see opponent's orders

    # Go back to a snapshot
    self.kill_unit(utils.get_unit(obs[0], unit_type=units.Protoss.Observer).tag)

    self.step(100)  # Make sure visibility updates.
    obs = self.observe()

    self.assertIsNone(utils.get_unit(obs[0], unit_type=units.Protoss.Observer))

    # Own Nexus is now active, snapshot isn't.
    nexus0 = utils.get_unit(obs[0], unit_type=units.Protoss.Nexus, owner=1)
    nexus1 = utils.get_unit(obs[0], unit_type=units.Protoss.Nexus, owner=2)
    nexus2 = utils.get_unit(obs[1], unit_type=units.Protoss.Nexus)
    self.assert_unit(nexus0, display_type=sc_raw.Visible, is_active=True)
    self.assert_unit(nexus1, display_type=sc_raw.Snapshot, is_active=False)
    self.assert_unit(nexus2, display_type=sc_raw.Visible, is_active=True)
    self.assertLen(nexus0.orders, 1)
    self.assertLen(nexus2.orders, 1)
    self.assertEmpty(nexus1.orders)  # Can't see opponent's orders