def test_permonst(self): mon = nethack.permonst(0) assert mon.mname == "giant ant" del mon mon = nethack.permonst(1) assert mon.mname == "killer bee"
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")
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") # Test https://github.com/pybind/pybind11/issues/2394 for _ in range(2): mon = nethack.permonst(0) self.assertEqual(mon.mname, "giant ant")
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.permonst(nethack.glyph_to_mon(glyph)).mname == "Oracle": self.oracle_glyph = glyph break assert self.oracle_glyph is not None
def test_illegal_numbers(self): with pytest.raises( IndexError, match=r"should be between 0 and NUMMONS \(%i\) but got %i" % (nethack.NUMMONS, nethack.NUMMONS), ): nethack.permonst(nethack.NUMMONS) with pytest.raises( IndexError, match=r"should be between 0 and NUMMONS \(%i\) but got %i" % (nethack.NUMMONS, -1), ): nethack.permonst(-1) with pytest.raises( IndexError, match=r"should be between 0 and MAXMCLASSES \(%i\) but got 127" % nethack.MAXMCLASSES, ): nethack.class_sym.from_mlet("\x7F")
def test_permonst_and_class_sym(self): glyph = 155 # Lichen. mon = nethack.permonst(nethack.glyph_to_mon(glyph)) assert mon.mname == "lichen" cs = nethack.class_sym.from_mlet(mon.mlet) assert cs.sym == "F" assert cs.explain == "fungus or mold" assert nethack.NHW_MESSAGE == 1 assert hasattr(nethack, "MAXWIN")
def test_simple(self): glyph = 155 # Lichen. mon = nethack.permonst(nethack.glyph_to_mon(glyph)) self.assertEqual(mon.mname, "lichen") cs = nethack.class_sym.from_mlet(mon.mlet) self.assertEqual(cs.sym, "F") self.assertEqual(cs.explain, "fungus or mold") self.assertEqual(nethack.NHW_MESSAGE, 1) self.assertTrue(hasattr(nethack, "MAXWIN"))
def test_run(self): archivefile = tempfile.mktemp(suffix="nethack_test", prefix=".zip") game = nethack.NetHack(archivefile=archivefile) response = game.reset() actions = [ nethack.MiscAction.MORE, nethack.MiscAction.MORE, nethack.MiscAction.MORE, nethack.MiscAction.MORE, nethack.MiscAction.MORE, nethack.MiscAction.MORE, ] for action in actions: while not response.ProgramState().InMoveloop(): response, done, info = game.step(nethack.MiscAction.MORE) response, done, info = game.step(action) if done: # Only the good die young. response = game.reset() obs = response.Observation() chars = _fb_ndarray_to_np(obs.Chars()) glyphs = _fb_ndarray_to_np(obs.Glyphs()) status = response.Blstats() x, y = status.CursX(), status.CursY() self.assertEqual(np.count_nonzero(chars == ord("@")), 1) self.assertEqual(chars[y, x], ord("@")) mon = nethack.permonst(nethack.glyph_to_mon(glyphs[y][x])) self.assertEqual(mon.mname, "monk") self.assertEqual(mon.mlevel, 10) class_sym = nethack.class_sym.from_mlet(mon.mlet) self.assertEqual(class_sym.sym, "@") self.assertEqual(class_sym.explain, "human or elf") self.assertEqual(os.waitpid(info["pid"], os.WNOHANG), (0, 0)) del game # Should kill process. with self.assertRaisesRegex(OSError, "No (child|such)? process"): os.waitpid(info["pid"], 0)
def test_run(self): game = nethack.Nethack(observation_keys=("glyphs", "chars", "colors", "blstats", "program_state")) _, _, _, _, program_state = game.reset() actions = [ nethack.MiscAction.MORE, nethack.MiscAction.MORE, nethack.MiscAction.MORE, nethack.MiscAction.MORE, nethack.MiscAction.MORE, nethack.MiscAction.MORE, ] for action in actions: while not program_state[3]: # in_moveloop. obs, done = game.step(nethack.MiscAction.MORE) _, _, _, _, program_state = obs obs, done = game.step(action) if done: # Only the good die young. obs = game.reset() glyphs, chars, colors, blstats, _ = obs x, y = blstats[:2] assert np.count_nonzero(chars == ord("@")) == 1 # That's where you're @. assert chars[y, x] == ord("@") # You're bright (4th bit, 8) white (7), too. assert colors[y, x] == 8 ^ 7 mon = nethack.permonst(nethack.glyph_to_mon(glyphs[y][x])) assert mon.mname == "monk" assert mon.mlevel == 10 class_sym = nethack.class_sym.from_mlet(mon.mlet) assert class_sym.sym == "@" assert class_sym.explain == "human or elf" game.close() assert os.path.isfile( os.path.join(os.getcwd(), "nle.ttyrec%i.bz2" % nethack.TTYREC_VERSION))
def test_run(self): # TODO: Implement ttyrecording filename in libnethack wrapper. # archivefile = tempfile.mktemp(suffix="nethack_test", prefix=".zip") game = nethack.Nethack(observation_keys=("glyphs", "chars", "colors", "blstats", "program_state")) _, _, _, _, program_state = game.reset() actions = [ nethack.MiscAction.MORE, nethack.MiscAction.MORE, nethack.MiscAction.MORE, nethack.MiscAction.MORE, nethack.MiscAction.MORE, nethack.MiscAction.MORE, ] for action in actions: while not program_state[3]: # in_moveloop. obs, done = game.step(nethack.MiscAction.MORE) _, _, _, _, program_state = obs obs, done = game.step(action) if done: # Only the good die young. obs = game.reset() glyphs, chars, colors, blstats, _ = obs x, y = blstats[:2] assert np.count_nonzero(chars == ord("@")) == 1 # That's where you're @. assert chars[y, x] == ord("@") # You're bright (4th bit, 8) white (7), too. assert colors[y, x] == 8 ^ 7 mon = nethack.permonst(nethack.glyph_to_mon(glyphs[y][x])) assert mon.mname == "monk" assert mon.mlevel == 10 class_sym = nethack.class_sym.from_mlet(mon.mlet) assert class_sym.sym == "@" assert class_sym.explain == "human or elf" game.close()
def test_permonst_and_class_sym(self): glyph = 155 # Lichen. mon = nethack.permonst(nethack.glyph_to_mon(glyph)) assert mon.mname == "lichen" cs = nethack.class_sym.from_mlet(mon.mlet) assert cs.sym == "F" assert cs.explain == "fungus or mold" assert nethack.NHW_MESSAGE == 1 assert hasattr(nethack, "MAXWIN") # Slightly irritating to need `chr` here. cs = nethack.class_sym.from_oc_class(chr(nethack.WAND_CLASS)) assert cs.sym == "/" assert cs.explain == "wand" obj = nethack.objclass(0) cs = nethack.class_sym.from_oc_class(obj.oc_class) assert cs.sym == "]" assert cs.explain == "strange object"