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
+22
-1
@@ -3,11 +3,13 @@
|
||||
/// the next event. Nothing is mutated, so a stream value can be run any number of times with the same results.
|
||||
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>)
|
||||
|
||||
@@ -21,6 +23,17 @@ let keyDowns: Stream<string> = Stream(fun _ -> failwith "TODO m08")
|
||||
/// Emits the `key` of every KeyUp event; ignores everything else.
|
||||
let keyUps: Stream<string> = Stream(fun _ -> failwith "TODO m08")
|
||||
|
||||
/// (m13) Emits the position `(x, y)` of every Click event; ignores everything else.
|
||||
/// Given: nothing to write here. It is the third source, built exactly like your `keyDowns`.
|
||||
let clicks: Stream<int * int> =
|
||||
let rec source () =
|
||||
Stream(fun e ->
|
||||
match e with
|
||||
| Click(x, y) -> [ (x, y) ], source ()
|
||||
| _ -> [], source ())
|
||||
|
||||
source ()
|
||||
|
||||
/// On `Time t`, emits every multiple `k*ms` with `last < k*ms <= t`, ascending, where `last` starts at 0
|
||||
/// and becomes `t` afterwards. A big time jump can emit several values. Ignores key events.
|
||||
/// Hint: write a private helper that carries `last`.
|
||||
@@ -45,5 +58,13 @@ let scan (f: 'b -> 'a -> 'b) (z: 'b) (s: Stream<'a>) : Stream<'b> = failwith "TO
|
||||
/// Note: streams only act when an event arrives, so if no event ever arrives, `v` is never emitted.
|
||||
let startWith (v: 'a) (s: Stream<'a>) : Stream<'a> = failwith "TODO m08"
|
||||
|
||||
/// (m10) Limit how far one Time event can move the clock that `s` sees, so a long silence (a background tab)
|
||||
/// does not turn into hundreds of beats at once.
|
||||
/// `s` gets a clock of its own, starting at 0. On `Time t` that clock advances by `t - last`, but by at most `maxGap`
|
||||
/// and never by less than 0 (time does not run backwards), where `last` is the `t` of the previous Time event
|
||||
/// (0 at the start). `s` is then stepped with `Time clock`. Key and click events are passed to `s` unchanged.
|
||||
/// Hint: a private helper that carries `last` and `clock`, like the one for `interval`.
|
||||
let clampTime (maxGap: int64) (s: Stream<'a>) : Stream<'a> = failwith "TODO m10"
|
||||
|
||||
/// Feed all events through the stream and collect every output, in order. A pure fold.
|
||||
let run (events: Event list) (s: Stream<'a>) : 'a list = failwith "TODO m08"
|
||||
Reference in new issue
Block a user