flix

0.81.0

Game

The rules of Invaders, as a pure function.

step takes a world and one input snapshot and returns the next world. It has no clock, no window, and no IO, and its randomness is threaded through as data. That is what lets the whole game be tested headlessly, and what makes an identical input script replay to an identical world.

step is a pipeline of small stages. Each one is worth reading on its own, and each is tested on its own.

Definitions

def digest(w: World): String§ Source

An exact, comparable rendering of a world.

Flix records do not derive Eq, and comparing worlds is what the replay tests do, so the game provides this instead. It is deliberately exact rather than rounded -- two runs of the same code on the same machine produce bit-identical floats, and IEEE arithmetic is deterministic across machines too, so there is nothing to be gained by blurring it. A digest also gives a readable diff when a replay does drift.

def initial(seed: Int64): World§ Source

A fresh game. Pure, and identical for the same seed.

def step(w: World, input: Snapshot): World \ Sound§ Source

Advances the game by exactly one logical tick.

Pure. Given the same world and the same input, always the same result.