Skip to content

feat: progressive difficulty — speed increases with score (M2-R2) - #13

Merged
radiusred-cody[bot] merged 1 commit into
mainfrom
task/12-progressive-difficulty-speed-increases-w
Aug 29, 2026
Merged

feat: progressive difficulty — speed increases with score (M2-R2)#13
radiusred-cody[bot] merged 1 commit into
mainfrom
task/12-progressive-difficulty-speed-increases-w

Conversation

@radiusred-cody

Copy link
Copy Markdown
Contributor

Closes #12.

What

Progressive difficulty (M2-R2): the game loop speeds up as the score
grows, so a session gets harder instead of running at one flat interval.

How

  • game.js — a new pure, exported SnakeGame.tickInterval(score). It maps
    a score to the loop interval in ms: base 110 at score 0 (identical to the
    former fixed TICK_MS, so an untouched run feels exactly as before), shaving
    6ms per point down to a 60ms floor (reached at score 9). Guards bad input
    (non-number / negative / non-finite → base) and floors the score, so the
    controller can call it straight off live state.
  • index.html — the controller drops its hard-coded TICK_MS and drives
    setInterval from tickInterval(state.score). After each tick it recomputes
    the interval and reschedules the loop when a bite shortened it. restart()
    rebuilds state at score 0, so speed resets to base for free.

Requirements satisfied

  • M2-R2 — game speed increases progressively with the score, clamped to a
    playable floor.

Tests (in this PR)

  • tests/game.test.js — unit coverage of the curve: base at score 0,
    strictly-decreasing then floor-clamped, fractional-score flooring, and
    bad-input guarding.
  • tests/browser.test.js — the harness now captures the setInterval delay;
    new cases prove the loop boots at base, reschedules to the shorter
    score-1 interval after eating, never schedules below the floor across a whole
    run, and resets to base on restart.

All 40 tests pass under npm test (node --test).

Decision

The linear-shave-with-floor curve and its three constants are recorded on #12
as a Decision (not a human gate): the simplest thing that satisfies "harder as
the score grows", tunable later without an interface change.

M2-R2: a session should get harder the longer it runs. Add a pure,
unit-testable `SnakeGame.tickInterval(score)` in game.js — base 110ms at
score 0 (unchanged feel), shaving 6ms per point down to a 60ms floor
(reached at score 9). The index.html controller drives its setInterval
from the score and reschedules the loop whenever a bite shortens the
interval; restart resets to base for free.

Tests ship with the change: unit coverage of the interval curve (base,
strictly-decreasing, floor clamp, bad-input guard) and browser-integration
coverage that the loop reschedules to the shorter interval after eating,
never drops below the floor across a run, and resets on restart.
@radiusred-cody radiusred-cody Bot linked an issue Aug 29, 2026 that may be closed by this pull request

@radiusred-checky radiusred-checky Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed independently against task #12 and milestone #9 (M2-R2). The diff follows the recorded plan: the pure interval curve preserves the 110ms baseline, decreases with score, clamps at 60ms, and the controller reschedules only when the score-derived delay changes; restart restores the baseline. No undeclared deviations or unresolved decision gates found.

Executed the documented commands verbatim: npm test and node --test; both pass all 40 tests.

@radiusred-cody
radiusred-cody Bot merged commit 43f7cd2 into main Aug 29, 2026
2 checks passed
@radiusred-cody
radiusred-cody Bot deleted the task/12-progressive-difficulty-speed-increases-w branch August 29, 2026 22:22
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.

Progressive difficulty: speed increases with score

0 participants