Exemplo n.º 1
0
    def test_symdef(self):
        tree_cmap_offset = 18  # Cf. drawing.c.
        tree_glyph = nethack.GLYPH_CMAP_OFF + tree_cmap_offset
        tree_symdef = nethack.symdef.from_idx(tree_cmap_offset)

        assert tree_cmap_offset == nethack.glyph_to_cmap(tree_glyph)
        assert tree_symdef.sym == ord("#")
        assert tree_symdef.explanation == "tree"
        assert tree_symdef.color == 2  # CLR_GREEN.
        assert str(
            tree_symdef) == "<nethack.symdef sym='#' explanation='tree'>"

        darkroom_glyph = nethack.GLYPH_CMAP_OFF
        assert nethack.glyph_to_cmap(darkroom_glyph) == 0
        darkroom_symdef = nethack.symdef.from_idx(0)
        assert darkroom_symdef.sym == ord(" ")
        assert darkroom_symdef.explanation == "dark part of a room"
        assert darkroom_symdef.color == 8  # NO_COLOR
Exemplo n.º 2
0
    def test_symdef(self):
        tree_cmap_offset = 18  # Cf. drawing.c.
        tree_glyph = nethack.GLYPH_CMAP_OFF + tree_cmap_offset
        sd = nethack.symdef.from_idx(tree_cmap_offset)

        assert tree_cmap_offset == nethack.glyph_to_cmap(tree_glyph)
        assert sd.sym == ord("#")
        assert sd.explanation == "tree"
        assert sd.color == 2  # CLR_GREEN.
        assert str(sd) == "<nethack.symdef sym='#' explanation='tree'>"
Exemplo n.º 3
0
    def test_glyph_to(self):
        assert np.all(
            nethack.glyph_to_mon(
                np.array([
                    nethack.GLYPH_MON_OFF,
                    nethack.GLYPH_PET_OFF,
                    nethack.GLYPH_DETECT_OFF,
                    nethack.GLYPH_RIDDEN_OFF,
                    nethack.GLYPH_STATUE_OFF,
                ])) == 0)

        # STATUE and CORPSE from onames.h (generated by makedefs).
        # Returned by glyph_to_obj.
        corpse = get_object("corpse").oc_name_idx
        statue = get_object("statue").oc_name_idx
        np.testing.assert_array_equal(
            nethack.glyph_to_obj(
                np.array([
                    nethack.GLYPH_BODY_OFF,
                    nethack.GLYPH_STATUE_OFF,
                    nethack.GLYPH_OBJ_OFF,
                ])),
            np.array([corpse, statue, 0]),
        )

        for idx in range(nethack.MAXPCHARS):  # Find the arrow trap.
            if nethack.symdef.from_idx(idx).explanation == "arrow trap":
                np.testing.assert_array_equal(
                    nethack.glyph_to_trap(
                        np.array([
                            nethack.GLYPH_CMAP_OFF,
                            nethack.GLYPH_CMAP_OFF + idx
                        ])),
                    # Traps are one-indexed in defsym_to_trap as per rm.h.
                    np.array([nethack.NO_GLYPH, 1]),
                )
                break

        np.testing.assert_array_equal(
            nethack.glyph_to_cmap(
                np.array([
                    nethack.GLYPH_CMAP_OFF,
                    nethack.GLYPH_STATUE_OFF,
                ])),
            np.array([0, nethack.NO_GLYPH]),
        )

        assert nethack.glyph_to_swallow(nethack.GLYPH_SWALLOW_OFF) == 0

        np.testing.assert_array_equal(
            nethack.glyph_to_warning(
                np.arange(nethack.GLYPH_WARNING_OFF,
                          nethack.GLYPH_STATUE_OFF)),
            np.arange(nethack.WARNCOUNT),
        )