Metadata-Version: 2.4
Name: nethack-gym
Version: 0.1.0
Summary: NetHack with original tiles and a gamepad interface.
License-Expression: NGPL
Requires-Python: <3.14,>=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: nethack_gym/THIRD_PARTY.md
License-File: nethack_gym/_vendor/gnollhack_reference/LICENSE.md
Requires-Dist: gymnasium
Requires-Dist: numpy
Requires-Dist: pillow
Requires-Dist: pygame-ce
Provides-Extra: test
Requires-Dist: pytest>=7; extra == "test"
Dynamic: license-file

# NetHack Gym environment

Full NetHack 3.6.0 from the pinned NetHackDS fork, with its original tiles,
controller-driven name/character selection, menus, and a desktop renderer.
This package builds and runs independently of fmri-gym. No Nintendo SDK,
emulator, ROM, flex, or bison is required.

## Install and play

Use Python 3.10–3.13 on Linux or macOS. Native compilation requires `cc` and
`make` (on macOS, install the Xcode command line tools). Windows builds are not
provided. Linux/macOS are intended targets; validate your actual machine.

From a source checkout:

```sh
git submodule update --init --recursive
python -m pip install .
nethack-gym-build
nethack-gym
```

A built wheel includes the pinned engine sources, fonts, tiles, license, and
build tools. Wheel users do not need Git or a separate engine checkout:

```sh
python -m pip install /path/to/nethack_gym-0.1.0-py3-none-any.whl
nethack-gym-build
nethack-gym
```

A wheel contains source, not a precompiled engine. The explicit build step is
still necessary. Installing or resetting the environment never downloads or
compiles anything. `nethack-gym-build --source /path/to/nethackds` overrides
the bundled source; patches require the compatible fork/version.

The default build cache is
`~/.cache/nethack-gym/3.6.0-desktop-4-cursor`.
`NETHACK_GYM_HOME` overrides it; use a path without whitespace because of
upstream Makefile restrictions. The old fmri-gym cache is not migrated. To reuse
an old runtime/native saves, explicitly set that variable to its old revision
directory; retain backups. Rebuild when runtime compatibility requires it.

## Gymnasium API

```python
import gymnasium as gym
import nethack_gym  # registers the environment

env = gym.make("NetHackGym-v0", game_mode="classic")
try:
    observation, info = env.reset(seed=1000)
    observation, reward, terminated, truncated, info = env.step(5)
    pixels = env.render()
finally:
    env.close()
```

`render_mode="rgb_array"` is the supported render mode. `runtime=` can select a
previously built runtime directory. Actions are integers 0–7: Up, Right, Down,
Left, Z/A, X/B, C/X, V/Y. Observations contain `tiles`, `glyphs`, and 1280×720 RGB
`pixels`. Reward is currently zero. The native game determines termination.

## Play and campaigns

The standalone player uses arrows and Z/X/C/V, or an SDL game controller.
Z confirms, X cancels or searches, C opens commands/the keyboard, and V opens
inventory. Escape closes the window. Select letters and Enter using the on-screen
keyboard to name a character. Menus and role/race/gender/alignment selection are
provided by the actual engine.

```sh
nethack-gym --mode classic
nethack-gym --mode modern
nethack-gym --campaign player-001.campaign --seed 1000
```

The standalone player defaults to Modern mode; the Gymnasium environment defaults
to Classic. Classic retains permadeath. Modern adapts GnollHack's revival/healing
and score divisor, with this port's floor-entry respawn checkpoints and brief
protection. It is not the full GnollHack engine or content.

Without a seed or campaign file, standalone play uses native saves under
`player-classic` or `player-modern` in the cache. Re-enter the character name to
restore. With `--campaign`, use the same file and mode to continue later.
Campaigns use seed/action replay, not a portable native save snapshot.
Engine, mode, and frontend fingerprints must match. Moving to this standalone
replay implementation changes the fingerprint; previous checkpoints are rejected
rather than silently replayed with different code. Keep old environments for
old checkpoints. Native save compatibility is separately architecture/version
specific and is not guaranteed by matching filenames.

**Only load campaign/checkpoint files from trusted sources.** They use Python
pickle. This package owns its replay implementation and has no dependency on
fmri-gym or replay-state-gym.

## Build package distributions

```sh
git submodule update --init --recursive
python -m pip install build
python -m build
```

Both the source archive and wheel must contain the populated engine tree.
Building from an sdist does not require initializing submodules. The source
`.gitmodules` entry documents the upstream dependency; it does not cause pip
to fetch missing source files. See `_vendor/PROVENANCE.json` within the Python
package for the pinned engine commit. Never edit the engine submodule directly
for local patches: `build.py` patches a disposable copy in the cache.

## Tests

```sh
python -m pip install '.[test]'
nethack-gym-build
nethack-gym-build --test-driver --home /tmp/nethack-gym-tests
export NETHACK_GYM_TEST_HOME=/tmp/nethack-gym-tests
python -m pytest
```

The production and test-driver builds are separate. Test-driver engines are
rejected by normal clients. Native tests can also run without Gymnasium/pygame
(using numpy and Pillow):

```sh
python -m unittest discover -s tests -p test_native.py -v
python -m unittest discover -s tests -p test_modern_engine.py -v
python -m unittest discover -s tests -p test_entry_recovery.py -v
```

## Optional fmri-gym integration

fmri-gym should install this package as an external dependency and retain its
adapter, scanner/rig configuration, curricula, recording, and integration tests.
It should not be required to supply NetHack source. The original integration
notes are preserved in [docs/fmri-gym-integration.md](docs/fmri-gym-integration.md).
The `nethack-campaign` command can export a compatible recorded block into an
fmri-gym curriculum; it only reads/writes JSON and requires no fmri-gym import.
Integration tests are retained separately in `integration_tests/` pending
migration to the consuming repository.

## Source and notices

See [LICENSE](LICENSE) and
[nethack_gym/THIRD_PARTY.md](nethack_gym/THIRD_PARTY.md).
The engine's 820 upstream files are unchanged. Desktop patches and the optional
Modern adaptation are applied during the native build. Supplied GnollHack
reference files are included with their original license/provenance but are not
compiled. No blanket license-compliance assessment of another application is
implied by this package extraction.
