<jupyter_start><jupyter_text>Noteworthy stuffsome [source diving](https://nethackwiki.com/wiki/Source_diving)* `nle/include/hack.h:349` -- stdin user confirmation  * auto-confirmation? requires game logic, level-design, and interaction analysis  * somehow intercept the stdin stream* `nle/src/allmain.c:53-65` -- real world effects seeping into the game* `nle/src/rnd.c:64`  -- biased uniform ${1..N}$ random nubmer generator  * $\mathrm{uin64} \mod N$ is biased, should use rejection sampling over the next power-of-two* `nle/src/drawing.c:142` the topology, objects and other glyphs<jupyter_code>import numpy
import torch
import gym<jupyter_output><empty_output><jupyter_text>* autopickup `@` -- toggle* safe movement `m` -- key comb<jupyter_code>import nle

from collections import namedtuple

# Bottom Line statistics namedtuple
BLStats = namedtuple('BLStats', [
    'x',
    'y',
    'strength_percentage',
    'str',  # 'strength',
    'dex',  # 'dexterity',
    'con',  # 'constitution',
    'int',  # 'intelligence',
    'wis',  # 'wisdom',
    'cha',  # 'charisma',
    'score',
    'hitpoints',
    'max_hitpoints',
    'depth',
    'gold',
    'energy',
    'max_energy',
    'armor_class',
    'monster_level',
    'experience_level',
    'experience_points',
    'time',
    'hunger_state',
    'carrying_capacity',
    'dungeon_number',
    'level_number',
])
class NLEWrapper(gym.ObservationWrapper):
    def observation(self, observation):
        observation['blstats'] = BLStats._make(observation['blstats'])
        return observation

    @property
    def last_observation(self):
        return self.observation(self.env._get_observation(self.env.last_observation))
    
    def __getattr__(self, name):
        # delegate the missing instance and calss attr's to the underlying env
        return getattr(self.env, name)<jupyter_output><empty_output><jupyter_text>Let's create an aliased `npy-pyt` context to play around with<jupyter_code>from rlplay.engine.core import context

env = NLEWrapper(gym.make("NetHackScore-v0"))
ctx = context(env)

obs = env.last_observation
# XXX we should prolly filter contorl ascii  if act >= 0x20 else act

ctoa = {chr(act): act for act in env.env._actions}
aton = {act: j for j, act in enumerate(env.env._actions)}
env.render()
obs, rew, done, info = env.step(aton[ctoa[input('>>> ')]])
env.render()

# 333 is the `@` glyph

bls = obs['blstats']
obs['glyphs'][
    bls.y - 5:bls.y + 5,
    bls.x - 5:bls.x + 5,
]<jupyter_output><empty_output><jupyter_text>```prearray([[    ,     ,     ,     ,     ,     ,     ,     ,     ,     ],       [    ,     ,     ,     ,     ,     ,     ,     ,     ,     ],       [    ,     ,     ,     ,     ,     ,     ,     ,     ,     ],       [    ,     ,     ,     ,     ,     ,     ,     ,     ,     ],       [    ,     ,     ,     , 2380, 2362, 2371, 2361, 2361, 2361],       [    ,     ,     ,     , 2380,  '@',  397, 2378, 2378, 2378],       [    ,     ,     ,     ,     , 2360, 2378, 2378, 2378, 1215],       [    ,     ,     ,     ,     , 2360, 2378, 2378, 2378, 2378],       [    ,     ,     ,     ,     , 2364, 2361, 2361, 2361, 2361],       [    ,     ,     ,     ,     ,     ,     ,     ,     ,     ]],      dtype=int16)```<jupyter_code># 2359 -- UNK
# 2380 -- `#` -- walkable
# 397 -- door
# 2378 -- floor

bls = obs['blstats']
obs['glyphs'][bls.y-5:bls.y+5,
              bls.x-5:bls.x+5,]
from plyr import suply

# suply(numpy.ndarray.shape.__get__, obs)
suply(lambda x: x.shape + (x.dtype,), obs)
from nle import nethack

glyph = torch.nn.Embedding(nethack.MAX_GLYPH, embedding_dim=32, )
x = glyph(ctx.pyt.obs['glyphs'].long())
ctx.npy.obs['glyphs']
env.render()
x
BLStats(*obs['blstats'].tolist())
obs['message'].view('S256')
obs['inv_glyphs']  # 55 -- items' look (viz.) ID
# obs['inv']
obs['inv_strs'].view('S80')
env.print_action_meanings()
obs, rew, done, info = env.step(0
                               )
env.render()
obs['glyphs']
# obs['blstats']
obs['glyphs'].shape<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16167664670658682, 'fraction_numerical': 0.03992015968063872, 'mean_word_length': 2.601976639712489, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 17, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '501178', 'license': 'MIT', 'n_tokens_mistral': 1599, 'n_tokens_neox': 1453, 'n_words': 289, 'path': 'stage/goal-setter-NLE.ipynb', 'repo_name': 'ivannz/rlplay', 'size': '4008'}