コード例 #1
0
    def _is_episode_end(self, observation):
        internal = observation[self._internal_index]
        stairs_down = internal[4]
        if stairs_down:
            glyphs = observation[self._glyph_index]
            blstats = observation[self._blstats_index]
            x, y = blstats[:2]

            neighbors = glyphs[y - 1:y + 2, x - 1:x + 2]
            if np.any(nethack.glyph_is_pet(neighbors)):
                return self.StepStatus.TASK_SUCCESSFUL
        return self.StepStatus.RUNNING
コード例 #2
0
ファイル: tasks.py プロジェクト: vishalbelsare/nle
    def _is_episode_end(self, observation):
        internal = observation[self._internal_index]
        stairs_down = internal[4]
        if stairs_down:
            glyphs = observation[self._glyph_index]
            blstats = observation[self._blstats_index]
            x, y = blstats[:2]

            neighbors = glyphs[y - 1:y + 2, x - 1:x + 2].reshape(-1).tolist()
            # TODO: vectorize
            for glyph in neighbors:
                if nethack.glyph_is_pet(glyph):
                    return self.StepStatus.TASK_SUCCESSFUL
        return self.StepStatus.RUNNING
コード例 #3
0
ファイル: tasks.py プロジェクト: qiming-zou/nle
 def _is_episode_end(self, response) -> None:
     internal = response.Internal()
     if internal and internal.StairsDown():
         obs = response.Observation()
         s = response.Blstats()
         if obs and s:
             glyphs = (obs.Glyphs().DataAsNumpy().view(np.int16).reshape(
                 base.DUNGEON_SHAPE))
             x = s.CursX()
             y = s.CursY()
             neighbors = glyphs[y - 1:y + 2,
                                x - 1:x + 2].reshape(-1).tolist()
             # TODO: vectorize
             for glyph in neighbors:
                 if nethack.glyph_is_pet(glyph):
                     return self.StepStatus.TASK_SUCCESSFUL
     return self.StepStatus.RUNNING
コード例 #4
0
ファイル: test_nethack.py プロジェクト: stjordanis/nle
    def test_glyph_is(self):
        assert nethack.glyph_is_monster(nethack.GLYPH_MON_OFF)
        assert nethack.glyph_is_pet(nethack.GLYPH_PET_OFF)
        assert nethack.glyph_is_invisible(nethack.GLYPH_INVIS_OFF)
        assert nethack.glyph_is_detected_monster(nethack.GLYPH_DETECT_OFF)
        assert nethack.glyph_is_body(nethack.GLYPH_BODY_OFF)
        assert nethack.glyph_is_ridden_monster(nethack.GLYPH_RIDDEN_OFF)
        assert nethack.glyph_is_object(nethack.GLYPH_OBJ_OFF)
        assert nethack.glyph_is_cmap(nethack.GLYPH_CMAP_OFF)
        # No glyph_is_explode, glyph_is_zap in NH.
        assert nethack.glyph_is_swallow(nethack.GLYPH_SWALLOW_OFF)
        assert nethack.glyph_is_warning(nethack.GLYPH_WARNING_OFF)
        assert nethack.glyph_is_statue(nethack.GLYPH_STATUE_OFF)

        vec = np.array(
            [
                nethack.GLYPH_MON_OFF,
                nethack.GLYPH_PET_OFF,
                nethack.GLYPH_INVIS_OFF,
                nethack.GLYPH_DETECT_OFF,
                nethack.GLYPH_BODY_OFF,
                nethack.GLYPH_RIDDEN_OFF,
                nethack.GLYPH_OBJ_OFF,
                nethack.GLYPH_CMAP_OFF,
                nethack.GLYPH_EXPLODE_OFF,
                nethack.GLYPH_ZAP_OFF,
                nethack.GLYPH_SWALLOW_OFF,
                nethack.GLYPH_WARNING_OFF,
                nethack.GLYPH_STATUE_OFF,
            ],
            dtype=np.int32,
        )
        np.testing.assert_array_equal(
            nethack.glyph_is_monster(vec),
            np.isin(
                vec,
                [
                    nethack.GLYPH_MON_OFF,
                    nethack.GLYPH_PET_OFF,
                    nethack.GLYPH_DETECT_OFF,
                    nethack.GLYPH_RIDDEN_OFF,
                ],
            ),
        )
        np.testing.assert_array_equal(
            nethack.glyph_is_pet(vec),
            np.isin(vec, [nethack.GLYPH_PET_OFF]),
        )
        np.testing.assert_array_equal(
            nethack.glyph_is_invisible(vec),
            np.isin(vec, [nethack.GLYPH_INVIS_OFF]),
        )
        np.testing.assert_array_equal(
            nethack.glyph_is_normal_object(vec),
            np.isin(vec, [nethack.GLYPH_OBJ_OFF]),
        )
        np.testing.assert_array_equal(
            nethack.glyph_is_detected_monster(vec),
            np.isin(vec, [nethack.GLYPH_DETECT_OFF]),
        )
        np.testing.assert_array_equal(
            nethack.glyph_is_body(vec),
            np.isin(vec, [nethack.GLYPH_BODY_OFF]),
        )
        np.testing.assert_array_equal(
            nethack.glyph_is_ridden_monster(vec),
            np.isin(vec, [nethack.GLYPH_RIDDEN_OFF]),
        )
        np.testing.assert_array_equal(
            nethack.glyph_is_object(vec),
            np.isin(
                vec,
                [
                    nethack.GLYPH_BODY_OFF,
                    nethack.GLYPH_OBJ_OFF,
                    nethack.GLYPH_STATUE_OFF,
                ],
            ),
        )
        assert np.all(nethack.glyph_is_trap(vec) == 0)
        for idx in range(nethack.MAXPCHARS):  # Find an actual trap.
            if "trap" in nethack.symdef.from_idx(idx).explanation:
                assert nethack.glyph_is_trap(nethack.GLYPH_CMAP_OFF + idx)
                break
        np.testing.assert_array_equal(  # Explosions are cmaps?
            nethack.glyph_is_cmap(vec),
            np.isin(vec, [nethack.GLYPH_CMAP_OFF, nethack.GLYPH_EXPLODE_OFF]),
        )
        # No glyph_is_explode, glyph_is_zap in NH.
        np.testing.assert_array_equal(
            nethack.glyph_is_swallow(vec),
            np.isin(vec, [nethack.GLYPH_SWALLOW_OFF]),
        )
        np.testing.assert_array_equal(
            nethack.glyph_is_warning(vec),
            np.isin(vec, [nethack.GLYPH_WARNING_OFF]),
        )
        np.testing.assert_array_equal(
            nethack.glyph_is_statue(vec),
            np.isin(vec, [nethack.GLYPH_STATUE_OFF]),
        )

        # Test some non-offset value too.
        assert nethack.glyph_is_warning(
            (nethack.GLYPH_WARNING_OFF + nethack.GLYPH_STATUE_OFF) // 2)