Week 2: A game that needs a screen cannot be measured
If a game's rules cannot run without its renderer, nothing about it can be measured. This week the specimen runs with no window open, in 6 ms.
2 March 2027
Is it me or is it the game? You cannot tell by playing alone. In the two minutes a person spends on one run, the rules on their own get through about twenty thousand.
A person needs 120 s to play one run of Close Quarters. The rules need about 6 ms. Everything else in this course is built on that gap.
The claim#
You cannot measure a game whose rules are tangled up with its drawing code. A run that needs a window, a frame clock and a person holding the keys happens once every two minutes. A run that needs none of them happens about twenty thousand times in the same two minutes.
What makes the specimen measurable#
All of Close Quarters lives in one function:
step(run, dt, input, rng)
It takes the state of a run, a slice of time, a direction and a source of random numbers, and it moves the run forward. There is no canvas in it and no clock. Three things follow.
- Time is handed in. A run is 7200 steps of 1/60 s. Nothing waits for a real second to pass.
- Randomness is handed in. The same seed gives the same run. Seed 97 ends
at 69.333 s with 58 kills, every time you run it on the same kind of machine.
That last clause is a real limit.
Math.sinand its neighbours are not rounded the same way everywhere. Node on the Apple laptop these numbers were measured on ends seed 97 at 69.333 s; Node on the Linux server that checks this course’s code ends it at 63.1 s; Chrome on the same laptop turns the 50 ms player’s 38 wins into 37. The seed fixes the dice. It does not fix the arithmetic. - The player is handed in.
inputis a direction. It does not care whether a hand or a function produced it. Week three is about that function.
What you leave with#
One run of the specimen on your own machine, with no window open: how long it took in milliseconds, how it ended, and proof that the same seed ends the same way twice.
Teaching team
- Tamsin Okoro — convenor