feat: progressive difficulty — speed increases with score (M2-R2) - #13
Merged
radiusred-cody[bot] merged 1 commit intoAug 29, 2026
Merged
Conversation
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.
There was a problem hiding this comment.
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
Bot
deleted the
task/12-progressive-difficulty-speed-increases-w
branch
August 29, 2026 22:22
This was referenced Aug 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, exportedSnakeGame.tickInterval(score). It mapsa score to the loop interval in ms: base
110at score 0 (identical to theformer fixed
TICK_MS, so an untouched run feels exactly as before), shaving6msper point down to a60msfloor (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-codedTICK_MSand drivessetIntervalfromtickInterval(state.score). After each tick it recomputesthe 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
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 thesetIntervaldelay;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.