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
@@ -1,10 +1,14 @@
|
||||
package snake
|
||||
|
||||
/** 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), a key going down or up, or (from Module 13)
|
||||
* a mouse click at canvas pixel (x, y). Every stream ignores the kinds of event it does not use.
|
||||
*/
|
||||
enum Event:
|
||||
case Time(t: Long)
|
||||
case KeyDown(key: String)
|
||||
case KeyUp(key: String)
|
||||
case Click(x: Int, y: Int)
|
||||
|
||||
/**
|
||||
* m08 stream: an event stream is a pure automaton (a Mealy machine).
|
||||
@@ -54,6 +58,21 @@ final case class Stream[A](step: Event => (List[A], Stream[A])):
|
||||
(v :: out, next)
|
||||
}
|
||||
|
||||
// (m10) `last` is the previous real time, `clock` the time this stream has been told. A long silence
|
||||
// (a background tab) moves `clock` by at most `maxGap`, so this stream never has to catch up on minutes of beats.
|
||||
private def clampFrom(maxGap: Long, last: Long, clock: Long): Stream[A] =
|
||||
Stream {
|
||||
case Event.Time(t) =>
|
||||
val now = clock + math.min(math.max(t - last, 0L), maxGap)
|
||||
val (out, next) = step(Event.Time(now))
|
||||
(out, next.clampFrom(maxGap, t, now))
|
||||
case e =>
|
||||
val (out, next) = step(e)
|
||||
(out, next.clampFrom(maxGap, last, clock))
|
||||
}
|
||||
|
||||
def clampTime(maxGap: Long): Stream[A] = clampFrom(maxGap, 0, 0)
|
||||
|
||||
def run(events: List[Event]): List[A] =
|
||||
events
|
||||
.foldLeft((List.empty[A], this)) { case ((outs, stream), e) =>
|
||||
@@ -75,6 +94,12 @@ object Stream:
|
||||
case _ => (Nil, keyUps)
|
||||
}
|
||||
|
||||
// (m13, given in src/) The position of every Click event, in canvas pixels. Like the key sources it remembers nothing.
|
||||
lazy val clicks: Stream[(Int, Int)] = Stream {
|
||||
case Event.Click(x, y) => (List((x, y)), clicks)
|
||||
case _ => (Nil, clicks)
|
||||
}
|
||||
|
||||
// `last` is the time of the previous Time event. Multiples of ms in (last, t] fire, ascending.
|
||||
private def intervalFrom(ms: Long, last: Long): Stream[Long] = Stream {
|
||||
case Event.Time(t) => ((last / ms + 1 to t / ms).map(_ * ms).toList, intervalFrom(ms, t))
|
||||
|
||||
Reference in new issue
Block a user