Skip to content

Add --fix-moon-phase flag for deterministic time-based game effects#113

Open
akhti wants to merge 3 commits intoNetHack-LE:mainfrom
akhti:main
Open

Add --fix-moon-phase flag for deterministic time-based game effects#113
akhti wants to merge 3 commits intoNetHack-LE:mainfrom
akhti:main

Conversation

@akhti
Copy link
Copy Markdown

@akhti akhti commented Apr 7, 2026

This addresses the same issue as #13 , but without changing default

When fix_moon_phase=True and seeds are set, derive deterministic values for moon phase, friday 13th, night, and midnight from the seed instead of using real system time. This ensures reproducibility across runs regardless of when they are executed.

When fix_moon_phase=True and seeds are set, derive deterministic values
for moon phase, friday 13th, night, and midnight from the seed instead
of using real system time. This ensures reproducibility across runs
regardless of when they are executed.
Comment thread win/rl/pynethack.cc Outdated
Comment thread src/hacklib.c Outdated
Comment thread src/hacklib.c Outdated
- Rename getlt_fixed -> nle_getlt_fixed to mark as NLE addition
- Replace custom hash constants with a private ISAAC64 RNG instance
  seeded from core+1, matching NetHack's own RNG mechanism
- Add time_seed_is_set flag to fall back to real time when no seed set
@akhti
Copy link
Copy Markdown
Author

akhti commented Apr 8, 2026

Thanks for the review! I rewrote the code to use built-in rng so it's easier to read. Also renamed getlt_fixed -> nle_getlt_fixed

@akhti akhti requested a review from StephenOman April 9, 2026 19:11
@StephenOman StephenOman added the enhancement New feature or request label Apr 11, 2026
@StephenOman
Copy link
Copy Markdown
Collaborator

This is a better approach than using the magic numbers; I like it!

In addition, nle_getlt_fixed() could be relocated to nlernd.c, further reducing the code changes in hacklib.c, maintaining a stricter division between NetHack and NLE.

To round out this PR, think about adding some tests of this new functionality, and perhaps this is as good a time as any to add a new documentation page (in doc/nle/source) outlining how to use the seeds to enable deterministic game behaviour.

Thanks for the contribution!

@akhti
Copy link
Copy Markdown
Author

akhti commented Apr 14, 2026

@StephenOman thanks for the comments

I had to leave small shim nle_getlt_maybe_fixed in the main nethack, but most of the code is outside now. Added tests

- Move ISAAC64 time derivation from hacklib.c to nle_fill_fixed_tm()
  in nlernd.c, keeping hacklib.c changes minimal
- Add test_fix_moon_phase_deterministic_moon_messages: verifies that
  specific seeds produce expected moon phase/friday 13th messages,
  proven to fail when time_seed derivation changes
- Add tests for determinism, different seeds, no-seed fallback,
  and default-off behavior
- Add doc/nle/source/deterministic_seeds.rst covering all seeding
  mechanisms (core/disp, lgen, fix_moon_phase)
@akhti
Copy link
Copy Markdown
Author

akhti commented Apr 15, 2026

fixed lint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants