feat(course): audit fixes and twelve extensions (Modules 7b, 12, 13)
Audit pass: - Frame rule counts frames since the last move, so every step lasts exactly movesEvery(score) frames, also right after a speed-up - clampTime + MAX_GAP_MS: a hidden tab no longer replays the whole gap - Pong Restart keeps held keys - Fact corrections (mulberry32 output coverage, Haskell IO, uniform) - New fixture cases from a mutation analysis Extensions (all three tracks, shared fixtures, course text): - Turn queue (Exercise 10.6), persisted high score (10.7), replay viewer (10.8), play() end-to-end helper (9.5) - Optional State (4.7) and optional Module 7b, stack-safe IO - Module 12, property-based testing with generators, shrinking, invariants and a model-based oracle - Module 13, Conway's Life with a Click event - JS type checking via jsconfig, JSDoc and types.d.ts - Maintainer tools: scripts/mutate.mjs, scripts/typecheck-js.sh, Playwright end-to-end suite (e2e/, scripts/e2e.sh) Docs: docs/contract.md is the canonical contract; specs and build log under docs/superpowers. Verified: JS 728, Scala 689, F# 691 unit tests; stubs and progression M01-M13 and M07b; 176 end-to-end tests on Chromium and WebKit. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
876f5aabb1
commit
edd57f0148
253 files changed
+21753
-503
No files matched your search
@@ -2,11 +2,13 @@
|
||||
/// There is no hidden state: whatever a stream "remembers" lives in the next stream it returns.
|
||||
module Snake.Stream
|
||||
|
||||
/// Something that happens to the program: time passing (ms since start) or a key going down or up.
|
||||
/// Something that happens to the program: time passing (ms since start) or a key going down or up, and from
|
||||
/// Module 13 a mouse click at `(x, y)` in canvas pixels. Every stream ignores the kinds of event it does not use.
|
||||
type Event =
|
||||
| Time of int64
|
||||
| KeyDown of string
|
||||
| KeyUp of string
|
||||
| Click of int * int
|
||||
|
||||
type Stream<'a> = Stream of (Event -> 'a list * Stream<'a>)
|
||||
|
||||
@@ -31,6 +33,16 @@ let keyUps: Stream<string> =
|
||||
|
||||
source ()
|
||||
|
||||
// (m13, given in src/) The position of every Click event, in canvas pixels. Like the key sources it remembers nothing.
|
||||
let clicks: Stream<int * int> =
|
||||
let rec source () =
|
||||
Stream(fun e ->
|
||||
match e with
|
||||
| Click(x, y) -> [ (x, y) ], source ()
|
||||
| _ -> [], source ())
|
||||
|
||||
source ()
|
||||
|
||||
// `last` is the time of the previous Time event. Multiples of ms in (last, t] fire, ascending.
|
||||
let rec private intervalFrom (ms: int64) (last: int64) : Stream<int64> =
|
||||
Stream(fun e ->
|
||||
@@ -76,6 +88,23 @@ let startWith (v: 'a) (s: Stream<'a>) : Stream<'a> =
|
||||
let out, next = step e s
|
||||
v :: out, next)
|
||||
|
||||
// (m10) `last` is the previous real time, `clock` the time the inner stream has been told. A long silence
|
||||
// (a background tab) moves `clock` by at most `maxGap`, so the inner stream never has to catch up on minutes of beats.
|
||||
let rec private clampFrom (maxGap: int64) (last: int64) (clock: int64) (s: Stream<'a>) : Stream<'a> =
|
||||
Stream(fun e ->
|
||||
match e with
|
||||
| Time t ->
|
||||
let now = clock + min (max (t - last) 0L) maxGap
|
||||
let out, next = step (Time now) s
|
||||
out, clampFrom maxGap t now next
|
||||
| KeyDown _
|
||||
| KeyUp _
|
||||
| Click _ ->
|
||||
let out, next = step e s
|
||||
out, clampFrom maxGap last clock next)
|
||||
|
||||
let clampTime (maxGap: int64) (s: Stream<'a>) : Stream<'a> = clampFrom maxGap 0L 0L s
|
||||
|
||||
// mapFold threads the stream through the events like fold, and keeps each step's outputs.
|
||||
let run (events: Event list) (s: Stream<'a>) : 'a list =
|
||||
List.mapFold (fun stream e -> step e stream) s events |> fst |> List.concat
|
||||
Reference in new issue
Block a user