diff --git a/nle/env/tasks.py b/nle/env/tasks.py index b53521188..d4ef331c7 100644 --- a/nle/env/tasks.py +++ b/nle/env/tasks.py @@ -163,7 +163,7 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.oracle_glyph = None for glyph in range(nethack.GLYPH_MON_OFF, nethack.GLYPH_PET_OFF): - if nethack.glyph_to_mon(glyph).mname == "Oracle": + if nethack.permonst(nethack.glyph_to_mon(glyph)).mname == "Oracle": self.oracle_glyph = glyph break assert self.oracle_glyph is not None diff --git a/nle/tests/test_nethack.py b/nle/tests/test_nethack.py index ed845b0bb..37e397ed6 100644 --- a/nle/tests/test_nethack.py +++ b/nle/tests/test_nethack.py @@ -49,11 +49,11 @@ def test_run(self): self.assertEqual(np.count_nonzero(chars == ord("@")), 1) self.assertEqual(chars[y, x], ord("@")) - mon = nethack.glyph_to_mon(glyphs[y][x]) + mon = nethack.permonst(nethack.glyph_to_mon(glyphs[y][x])) self.assertEqual(mon.mname, "monk") self.assertEqual(mon.mlevel, 10) - class_sym = nethack.mlet_to_class_sym(mon.mlet) + class_sym = nethack.class_sym.from_mlet(mon.mlet) self.assertEqual(class_sym.sym, "@") self.assertEqual(class_sym.explain, "human or elf") @@ -69,11 +69,11 @@ class HelperTest(unittest.TestCase): def test_simple(self): glyph = 155 # Lichen. - mon = nethack.glyph_to_mon(glyph) + mon = nethack.permonst(nethack.glyph_to_mon(glyph)) self.assertEqual(mon.mname, "lichen") - cs = nethack.mlet_to_class_sym(mon.mlet) + cs = nethack.class_sym.from_mlet(mon.mlet) self.assertEqual(cs.sym, "F") self.assertEqual(cs.explain, "fungus or mold") @@ -81,6 +81,14 @@ def test_simple(self): self.assertEqual(nethack.NHW_MESSAGE, 1) self.assertTrue(hasattr(nethack, "MAXWIN")) + def test_permonst(self): + mon = nethack.permonst(0) + self.assertEqual(mon.mname, "giant ant") + del mon + + mon = nethack.permonst(1) + self.assertEqual(mon.mname, "killer bee") + if __name__ == "__main__": unittest.main() diff --git a/win/rl/helper.cc b/win/rl/helper.cc index c59382cd9..9871578e8 100644 --- a/win/rl/helper.cc +++ b/win/rl/helper.cc @@ -33,6 +33,7 @@ PYBIND11_MODULE(helper, m) m.attr("MAXWIN") = py::int_(MAXWIN); m.attr("NUMMONS") = py::int_(NUMMONS); + m.attr("NUM_OBJECTS") = py::int_(NUM_OBJECTS); // Glyph array offsets. This is what the glyph_is_* functions // are based on, see display.h. @@ -54,7 +55,11 @@ PYBIND11_MODULE(helper, m) m.attr("NO_GLYPH") = py::int_(NO_GLYPH); m.attr("GLYPH_INVISIBLE") = py::int_(GLYPH_INVISIBLE); + m.attr("CORPSE") = py::int_(CORPSE); + m.attr("STATUE") = py::int_(STATUE); + m.attr("MAXPCHARS") = py::int_(static_cast(MAXPCHARS)); + m.attr("MAXEXPCHARS") = py::int_(static_cast(MAXEXPCHARS)); m.attr("EXPL_MAX") = py::int_(static_cast(EXPL_MAX)); m.attr("NUM_ZAP") = py::int_(static_cast(NUM_ZAP)); m.attr("WARNCOUNT") = py::int_(static_cast(WARNCOUNT)); @@ -119,7 +124,9 @@ PYBIND11_MODULE(helper, m) m.def("glyph_is_warning", [](int glyph) { return glyph_is_warning(glyph); }); - py::class_(m, "permonst") + py::class_ >(m, + "permonst") + .def(py::init([](int index) -> permonst * { return &mons[index]; })) .def_readonly("mname", &permonst::mname) /* full name */ .def_readonly("mlet", &permonst::mlet) /* symbol */ .def_readonly("mlevel", &permonst::mlevel) /* base monster level */ @@ -129,8 +136,7 @@ PYBIND11_MODULE(helper, m) // .def_readonly("maligntyp", &permonst::maligntyp) /* basic // monster alignment */ .def_readonly("geno", &permonst::geno) /* creation/geno mask value */ - // .def_readonly("mattk", &permonst::mattk) /* attacks matrix - // */ + // .def_readonly("mattk", &permonst::mattk) /* attacks matrix */ .def_readonly("cwt", &permonst::cwt) /* weight of corpse */ .def_readonly("cnutrit", &permonst::cnutrit) /* its nutritional value */ @@ -151,6 +157,10 @@ PYBIND11_MODULE(helper, m) ; py::class_(m, "class_sym") + .def_static( + "from_mlet", + [](char let) -> const class_sym * { return &def_monsyms[let]; }, + py::return_value_policy::reference) .def_readonly("sym", &class_sym::sym) .def_readonly("name", &class_sym::name) .def_readonly("explain", &class_sym::explain) @@ -159,16 +169,12 @@ PYBIND11_MODULE(helper, m) + "' explain='" + std::string(cs.explain) + "'>"; }); - // m.def("mon", [](const int i) { return mons[i]; }); - m.def( - "glyph_to_mon", - [](int glyph) -> const permonst * { - return &mons[glyph_to_mon(glyph)]; - }, - py::return_value_policy::reference); - - m.def( - "mlet_to_class_sym", - [](char let) -> const class_sym * { return &def_monsyms[let]; }, - py::return_value_policy::reference); + m.def("glyph_to_mon", [](int glyph) { return glyph_to_mon(glyph); }); + m.def("glyph_to_obj", [](int glyph) { return glyph_to_obj(glyph); }); + m.def("glyph_to_trap", [](int glyph) { return glyph_to_trap(glyph); }); + m.def("glyph_to_cmap", [](int glyph) { return glyph_to_cmap(glyph); }); + m.def("glyph_to_swallow", + [](int glyph) { return glyph_to_swallow(glyph); }); + m.def("glyph_to_warning", + [](int glyph) { return glyph_to_warning(glyph); }); }