Skip to content

Implement Replay Recording and Playback Engine#54

Open
mac-dubem wants to merge 1 commit into
MindFlowInteractive:mainfrom
mac-dubem:feat/replay-engine
Open

Implement Replay Recording and Playback Engine#54
mac-dubem wants to merge 1 commit into
MindFlowInteractive:mainfrom
mac-dubem:feat/replay-engine

Conversation

@mac-dubem

Copy link
Copy Markdown

Description

Build a replay system that records every player action during a session as a timestamped event log and supports deterministic playback of that log. Replays let players review their own solutions, serve as proof-of-solve for on-chain achievement verification, and provide debugging data for the puzzle design team. Replay files are compact, portable, and verifiable.

Changes

  • src/replay/mod.rs — New replay module with:

    • ReplayEvent enum: SessionStart, SessionEnd, HintReveal, AnswerAttempt { answer }
    • ReplaySession struct for recording, saving (.qreplay binary via bincode), loading, and playback
    • Microsecond-precision timestamps relative to session start
    • Puzzle content hash for integrity cross-checking on playback
    • Playback at configurable speed (1x, 2x, 4x) with inter-event timing
    • Replay summary (total time, hints used, attempt count, final score) printed at playback end
  • src/main.rs — Added --playback <file> and --speed <1|2|4> CLI flags

  • Cargo.toml — Added bincode dependency for binary serialization

  • src/lib.rs — Registered pub mod replay

Tests

10 unit tests covering:

  • Event recording order
  • Monotonic timestamp generation
  • bincode serialization roundtrip
  • Save and load .qreplay files
  • Integrity hash match/mismatch detection
  • Empty replay playback (no panic)
  • Default state verification
  • Nonexistent and corrupted file error handling

All 175 tests pass (the 1 pre-existing failure in leaderboard::tests::replacement_when_full is unrelated).

Closes #47

- Add replay module at src/replay/mod.rs with ReplayEvent enum
  (HintReveal, AnswerAttempt, SessionStart, SessionEnd)
- Events recorded with microsecond timestamps relative to session start
- Completed replays serialized to .qreplay binary file via bincode
- --playback <file> CLI flag loads and replays .qreplay files
- --speed 1|2|4 flag controls playback speed (default 1x)
- Replay files include puzzle content hash for integrity cross-check
- Replay summary (total time, hints, attempts, score) printed at end
- 10 unit tests covering recording, serialization, playback, integrity

Closes MindFlowInteractive#47
@Mkalbani

Copy link
Copy Markdown
Contributor

@mac-dubem please resolve conflict

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Replay Recording and Playback Engine

2 participants