Skip to content

Chapter 14 - Replayability, Daily Challenges, and Telemetry ​

Where this chapter fits: the run layer from chapter 13 becomes a shared experience. One seed per calendar day makes everyone's daily challenge comparable, seven local counters record how you play, and a run summary closes the loop.

Time: [TODO Simon: time estimate for chapter 14]

The chapter 14 build in a daily challenge: the status line reads DAILY SEED 739859

A Daily Challenge run in the chapter 14 build. The seed shown in the status line is the day number of the UTC date of capture (1 September 2026). Every player who started a daily that day saw the same upgrade cards.

Prerequisites ​

Chapter 13 (the deterministic upgrade draft and run-state model) and chapter 12 (profile persistence).

Learning objectives ​

By the end of this chapter you should be able to:

  1. implement a shared daily challenge by deriving one seed per calendar day,
  2. thread a seed through every randomised decision a "fair" mode needs to control, and identify the ones this build leaves uncontrolled,
  3. persist gameplay statistics (PlayerStatistics) as local, privacy-friendly telemetry,
  4. present a post-run summary that closes the loop on a run.

Code anchors ​

  • Source/Data/Enums.cs (RunMode: Classic, DailyChallenge, LevelSelect; GameStatus.RunSummary)
  • Source/Game/LastPerimeterApp.cs (chapter 14 staged version: day-number seeding in StartRun, the seed handoff in UpdateLevelComplete, FinishRun, UpdateRunSummary)
  • Source/Data/GameSession.cs (DailyChallengeActive, DailyChallengeSeed, SummaryLine)
  • Source/Data/PlayerStatistics.cs (lifetime counters including BestDailyChallengeScore)
  • Source/Systems/PowerupSystem.cs (CreateUpgradeChoices(level, seed) from chapter 13)

The key lesson ​

Replayability should come from meaningful variation and good tuning, not from making numbers larger forever.

The daily challenge: one seed per day ​

A daily challenge is a social contract: everyone who plays today plays the same run. The whole trick is deriving the seed from the calendar:

In StartRun:

csharp
_gameSession = new GameSession
{
    // ...
    RunMode = runMode,
    HighScore = _profileTracker.Profile.HighScore,
    DailyChallengeSeed = runMode == RunMode.DailyChallenge ? DateOnly.FromDateTime(DateTime.UtcNow).DayNumber : 0,
};
_dailyChallengeDescription = runMode == RunMode.DailyChallenge ? $"DAILY SEED {_gameSession.DailyChallengeSeed}" : string.Empty;

DateOnly.DayNumber counts days since 1 January 0001, so every player on the planet gets the same integer for the same UTC date. 1 September 2026 is day 739,859, which is the number in the screenshot above. No server is required. The seed is also shown to the player (DAILY SEED ... becomes the level StatusMessage), which makes the contract inspectable.

GameSession.DailyChallengeActive is not set in StartRun. It is derived from the run mode and never stored, so there is no second flag that can disagree with RunMode:

csharp
public bool DailyChallengeActive => RunMode == RunMode.DailyChallenge;

The seed then flows into the chapter 13 draft when a level is cleared:

csharp
_gameSession.PendingUpgradeChoices = _powerupSystem.CreateUpgradeChoices(_gameSession.Level, _gameSession.DailyChallengeSeed == 0 ? _gameSession.Level : _gameSession.DailyChallengeSeed);

So on a given day, everyone sees the same upgrade cards after each level.

What is and is not seeded in this build ​

DecisionSource of randomnessSeeded by the daily challenge?
level definition (roster, speed, goal, inset)none: CreateLevel is a pure functionidentical by construction
upgrade cards after each levelnew Random(seed + level * 31)yes
enemy retarget angles and timersEnemySystem._random (optional constructor Random)no
powerup type, node, and spawn timingPowerupSystem._random (optional constructor Random)no

Levels are identical by construction and drafts are identical by seed, but moment-to-moment enemy motion is not. Whether that breaks "leaderboard-safe" fairness is the central question of this chapter. Both EnemySystem and PowerupSystem now accept an optional Random, so the headline exercise is to thread the daily seed into them.

Telemetry as a design aid ​

Frame telemetry as learning, not surveillance. This build records local-only counters:

csharp
public sealed class PlayerStatistics
{
    public int TotalRunsPlayed { get; set; }
    public int TotalDeaths { get; set; }
    public int TotalLevelsCleared { get; set; }
    public int HighestLevelReached { get; set; } = 1;
    public int TotalPowerupsCollected { get; set; }
    public int TotalCapturesCompleted { get; set; }
    public int BestDailyChallengeScore { get; set; }
}

LastPerimeterApp reports each event to ProfileTracker where it happens. RecordRunStarted runs in StartRun, RecordPowerupCollected on pickup, RecordCapture on every claim, RecordLevelCleared on level completion, and RecordDeath in the death handler. The tracker updates the counters and flags the profile dirty. SaveIfDirty() then writes it through ProfileStorage, so the numbers survive restarts (chapter 12 shows the resulting JSON). Even these seven integers answer real tuning questions. Deaths per level cleared is a difficulty signal. Powerups per capture says whether pickups are worth chasing.

Closing the loop: the run summary ​

FinishRun reports the run to the profile tracker and builds the summary line:

csharp
private void FinishRun()
{
    if (_gameSession is null)
    {
        return;
    }

    _profileTracker.RecordRunFinished(_gameSession.Score, dailyChallenge: _gameSession.DailyChallengeActive);
    _runSummary = $"SCORE {_gameSession.Score}  HI {_profileTracker.Profile.HighScore}  LEVEL {_gameSession.Level}";
}

The BestDailyChallengeScore rule lives in ProfileTracker.RecordRunFinished(int score, bool dailyChallenge = false): the daily best only moves when the dailyChallenge flag is true. GameStatus.RunSummary then shows the summary line until the player confirms back to the menu (the chapter 12 screenshot of the overlay applies unchanged). Daily scores get their own best (BestDailyChallengeScore) because comparing a seeded daily against a free-form classic run would be meaningless.

Build it step by step ​

This chapter is copy-along. Step 1 copies the chapter's files from the snapshot, and the steps after it walk through what changed and why. The listings show the parts worth studying, not every line.

Step 1 - Copy the chapter files ​

From your LastPerimeter folder, copy the Source and Tests folders from this chapter's snapshot over your own. The command creates any folders you do not have yet and overwrites the files that changed. Replace <course-repo> with the path to your copy of the course repository (the course index explains how to get it).

In PowerShell:

powershell
Copy-Item -Recurse -Force "<course-repo>/DOCUMENTATION/LastPerimeter-Source/14-Replayability-Daily-Challenges-And-Telemetry/Source", "<course-repo>/DOCUMENTATION/LastPerimeter-Source/14-Replayability-Daily-Challenges-And-Telemetry/Tests" .

In bash:

bash
cp -R "<course-repo>/DOCUMENTATION/LastPerimeter-Source/14-Replayability-Daily-Challenges-And-Telemetry/Source" "<course-repo>/DOCUMENTATION/LastPerimeter-Source/14-Replayability-Daily-Challenges-And-Telemetry/Tests" .

That copy brings in these files:

New files:

  • None.

Replaced files (you already have these, so overwrite them):

  • Source/Game/LastPerimeterApp.cs

There are no new source files. RunMode, PlayerStatistics, and the session fields shipped with chapters 11-13.

NOTE

Every step after this one describes code that is already in the files you just copied. Open the file each step names and read along. You type nothing unless a step says so.

Step 2 - The menu entry: DAILY CHALLENGE ​

Open Source/Game/LastPerimeterApp.cs. DAILY CHALLENGE is the second main-menu item and routes to StartRun(RunMode.DailyChallenge, 1). The cases after it are renumbered.

Step 3 - The seed: StartRun and SetupLevel ​

Open Source/Game/LastPerimeterApp.cs. StartRun sets DailyChallengeSeed and builds _dailyChallengeDescription. DailyChallengeActive follows from RunMode, so it needs no assignment. SetupLevel shows the description as the status message when a daily is active.

Step 4 - The seeded draft: UpdateLevelComplete ​

Open Source/Game/LastPerimeterApp.cs. UpdateLevelComplete passes the daily seed into CreateUpgradeChoices.

Step 5 - The daily best: FinishRun ​

Open Source/Game/LastPerimeterApp.cs. FinishRun passes dailyChallenge: _gameSession.DailyChallengeActive to RecordRunFinished, so the tracker updates BestDailyChallengeScore.

Step 6 - Build, test, run ​

Run these commands from your LastPerimeter folder:

bash
dotnet build
dotnet test
dotnet run --project Platforms/DesktopVK

dotnet test reports 73 passing tests. On Windows you can also run dotnet run --project Platforms/WindowsDX12.

Chapter snapshot ​

The buildable project lives at DOCUMENTATION/LastPerimeter-Source/14-Replayability-Daily-Challenges-And-Telemetry. This chapter adds no new source files. Its adds list in scripts/chapter-manifest.json is empty, and all the data types already shipped with chapters 11-13. Its staged app adds the Daily Challenge mode: the day-number seed, the DAILY SEED status line, the seeded draft handoff, and BestDailyChallengeScore tracking.

bash
cd DOCUMENTATION/LastPerimeter-Source/14-Replayability-Daily-Challenges-And-Telemetry
dotnet build
dotnet test

No new test files arrive. The suite remains at 73 tests.

Checkpoint ​

  1. In your LastPerimeter folder, run dotnet test. It reports 73 passing tests. If it does not, compare your Source and Tests folders with the chapter 14 snapshot.
  2. Run dotnet run --project Platforms/DesktopVK. Press Enter on the title screen and choose DAILY CHALLENGE, the second row of the main menu (the Controls table in chapter 03 lists every key). The status line reads DAILY SEED followed by a number. Write the number down.
  3. Clear level 1 and press Enter on the LEVEL COMPLETE overlay. Write down the three upgrade cards on offer.
  4. Pick a card, press Escape, and choose QUIT TO MENU. Start a second DAILY CHALLENGE. The DAILY SEED number is identical, and the cards after level 1 match the first run.
  5. Quit the game and open profile.json in a text editor. On Windows it is %LOCALAPPDATA%\LastPerimeter\profile.json, on Linux ~/.local/share/LastPerimeter/profile.json, and on macOS ~/Library/Application Support/LastPerimeter/profile.json. TotalRunsPlayed and BestDailyChallengeScore have moved, and so has TotalDeaths if you lost a life. To start again with a fresh profile, close the game and delete that file. The game creates a new one the next time it saves.
  6. As a bonus, explain why DateTime.UtcNow rather than local time is the right call for a shared seed, and what happens to a player who starts a daily at 23:59 UTC.

What you should have now ​

You now have:

  • a DAILY CHALLENGE menu entry that starts a run seeded from the UTC day number,
  • the seed shown in the status line (DAILY SEED n) and passed into the upgrade draft, so every daily run on the same day offers the same cards,
  • seven lifetime counters in PlayerStatistics, saved to profile.json,
  • a separate BestDailyChallengeScore that only daily runs update,
  • the same 73 tests as chapter 13. Enemy motion and powerup spawns are not seeded yet, which is the first item in Extensions.

Common mistakes ​

  • seeding from local time (two players in different time zones get different dailies),
  • reseeding the draft with Level when a daily seed exists,
  • counting a statistic in two places (for example deaths in both the death handler and the shield),
  • treating the daily best as comparable with the classic high score.

Extensions ​

Try to add:

  1. ghost replays,
  2. leaderboard-safe seed rules (what else must be deterministic before scores are comparable?),
  3. adaptive mutators,
  4. full seeded-run support: build one Random from the daily seed and pass it to the EnemySystem and PowerupSystem constructors, so the entire daily run is reproducible,
  5. a challenge-definition format (mode + seed + modifier list),
  6. a richer post-run summary (captures, powerups, and the chosen upgrades from GameSession.ChosenUpgrades),
  7. a stats dashboard built on PlayerStatistics for future tuning.