feat(scala): m01–m06 port with shared fixtures

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas WintherandClaude Sonnet 5.5 committed 2026-10-29 00:07:27 +01:00
1 parent 045029639e
commit 1e186733d1
23 files changed
+771 -2

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
package snake
/** m05 game: one `update` turns every action into a new state; replaying a game is a fold over its actions. */
object Game:
def update(state: GameState, action: Action): GameState = action match
case Action.Tick => Spawn.tick(state)
case Action.Turn(dir) => Rules.turn(state, dir)
case _ => state // TogglePause, Restart and Frame arrive in m10
def replay(state: GameState, actions: List[Action]): GameState = actions.foldLeft(state)(update)
// scanLeft is foldLeft that keeps every intermediate result.
def history(state: GameState, actions: List[Action]): List[GameState] = actions.scanLeft(state)(update)