How NetWars Works Chapter 21 of 21, plus appendices

21. Reference tests and verification

How do we know this document is right, and how do you know your rebuild is? This chapter answers both. It describes how the document was checked against the original program, including a test in which people who could read nothing but these pages rebuilt parts of the game and were compared, case by case, with the original code. Then it gives reference cases you can use without any of our tools: concrete inputs and the exact outputs of the original, produced by running its code. Marks: O observed, D derived from the code, H hypothesis (chapter 0).

How this document was checked

The program behind it

Everything here is read from a reconstructed source of NetWars 2.06 that rebuilds the original NETWARS.EXE byte for byte: the same SHA-256, built with the original Borland C++ 2.0 toolchain, every C function byte-identical when compiled, the hand-written assembly modules part of the identical image O (docs/build.md, docs/verification.md). So a statement about "the code" is a statement about the shipped program, not about a guess at it. What the code does at run time was also watched: recorded runs of the original in an emulator, with keys and forced states injected (docs/runtime-baseline.md).

Critics

Each chapter (0 to 21) was read, after it was written, by a critic who had not written it (a newcomer or fact-checking reader) and who checked its claims against the sources and the recorded runs; the corrections were made before the chapter was kept. Chapters 18 and 19 had two such passes, this chapter one. The writer assigns the marks O, D, H; the critic checked each against its source, and a claim without a source or a run is marked as a hypothesis.

The sufficiency check

Correct is not the same as sufficient: a true document can still leave out the one rule a rebuild needs. So the document was tested the way it is meant to be used O:

  1. Implementers restricted to the document. The implementers were AI agents, fresh ones each round with no prior context. They were instructed to read only these HTML pages, the readable data in assets/ and a short description of the functions to write (tools/doccheck/API.md: inputs, outputs and units, no rules). They wrote those functions in Python and noted every place where the text was unclear or silent and what they assumed. The restriction was an instruction, not a sandbox: in round 3 the parallel implementers shared one scratch directory, and a copy of an off-limits source file appeared in it; implementer C reports not opening it (round3_analysis.md, N47). Later rounds use a separate scratch directory per implementer.
  2. The original as the oracle. The same functions were answered by running the original machine code in a CPU emulator (Unicorn): the inputs are written into the game's own records and variables, the original routine runs unchanged, and the results are read back. Routines outside the one tested are replaced by recorders: drawing, sound, the timer, rand() (which hands out given values), the network, the death screen and, for the single-function tests, neighbouring routines; oracle_notes.md lists each.
  3. Seeded cases. A comparer generates the same random cases for both from a fixed seed: normal inputs and edge ranges (exact limits, powers of two, objects straight ahead, near misses), plus whole frames sampled from trajectories of the original itself. A case passes when every discrete output (states, flags, counters, messages, sounds) is equal and every continuous one is within a small tolerance (positions 1 unit, axes 0.01, pixels 1.5).
  4. Every mismatch is classified. Either the document was silent, vague or wrong (then the chapter is fixed), or the implementer missed something the text states, or the test's own conventions were unclear (then the function description is fixed; the oracle never changes what the original computes).

The 19 functions and what each covers:

#FunctionWhat it coversOriginal code runCases
1distance exponentthe nearness measure behind every contact and range test (chapter 3)lvec3_normalize_down/up700
2ship stepone frame of your ship: keyboard ramps, tumble, throttle, velocity controller, extra thrust (chapter 4)player_update500
3laser hityour shot's box test against a body (chapter 6)shot_hits_object700
4alien laser hitan alien shot's box test against youalien_shots_update700
5render one bodydisplay exponent, touch, view test, far "+", screen position, the faces queued and their order (chapter 9)render_object and the draw list400
6Fighter stepthe Fighter's behaviour and movement (chapter 7)ai_fighter, object_move500
7hit reportsmultiplayer: applying the hit words of the peers (chapter 8)net_sync_frame500
8radar blipone object's radar mark at every zoom level (chapter 15)render_object, draw_radar600
9HUDevery line, text and stroke letter of the instruments (chapter 15)draw_hud, radar frame300
10alien stepall four kinds and the mutant in every state: behaviour, movement, ramming, explosions, the lock test (chapters 7, 17)aliens_update600
11missile stepyour missile and both enemy missiles: homing, hits, giving up, score wrapplayer_missiles_update, enemy_missiles_update500
12missile lockthe crosshair lock and the launchaliens_update, player_fire_missile300
13pod stepa pod in every state (chapter 5)pods_update400
14satellite stepspin, loss, pick-ups and their limitssatellite_update, apply_pickup400
15satellite spawnposition, kind cycle, counter wrapsatellite_spawn200
16level set-upbudgets, limits, Pirate speed, pod reset and placementmain from its level label150
17alien spawnslot, kind rotation, mutants, spawn sidealien_spawn300
18sound sequencethe PC-speaker sequencer tick by tick (chapter 10)snd_effect_N, snd_tick150
19frame stepone whole single-player frame of the main loop, everything except drawing (chapters 2, 17)main's frame loop300

Results, per function, as the share of cases that pass. Rounds 1 and 2 tested functions 1–7 on chapters 0–9; round 3 had three implementers, each with a part of functions 1–19, on all chapters. The last column is the same round-3 code compared again after the test's own conventions were corrected (the code itself unchanged; mismatches that came from gaps in the document stay, since the gaps were fixed in the text, not in the implementations):

FunctionRound 1Round 2Round 3Round 3, final conventionsWhy not 100 at first; what remains
1 distance exponent100100100 (all three)100—
2 ship step89.699.6100100—
3 laser hit93.4100100100—
4 alien laser hit93.9100100100—
5 render one body68.292.898.298.2the vertex arithmetic close up (16-bit wrap): now written out in chapter 9
6 Fighter step78.899.6100100—
7 hit reports91.8100100100—
8 radar blip100100—
9 HUD100100—
10 alien step100100—
11 missile step100100—
12 missile lock100100—
13 pod step100100—
14 satellite step94.094.0a test convention (what a freed satellite reports), now stated
15 satellite spawn86.586.5the 16-bit counter wrap: now in chapter 17
16 level set-up42.7100a test convention (lost pods)
17 alien spawn100100—
18 sound sequence100100—
19 frame step93.397.3fixed: two values the test forgot to carry from frame to frame, and a powered shot at life 0 reported as a free slot (test conventions); remaining 2.7 %: only the death-screen convention (the death screen is outside the step), now stated

Every gap the rounds found was written into the chapters, mostly as "Exact rules" boxes: round 1 gave the precision rules of chapter 3, the keyboard and tumble details of chapter 4, the box tests of chapter 6, the Fighter's same-frame switch and the hit-report rules; round 2 the last roundings; round 3 the vertex arithmetic and culling formula of chapter 9, the satellite counter wrap, the "None" sound option, the status-line calls of chapter 15, the switch convention and the missile hit frame of chapter 17, and a satellite rule nobody had noticed: a dead ship that touches a shields satellite lives again (chapter 17, 8) O. Round 3 found no implementer slip: every difference came from the document or from the test's conventions. The round-3 fixes themselves have not been re-tested by a fresh implementer; the render_body fix was confirmed only by changing implementer C's vertex arithmetic to the new rule in a copy (400 of 400 cases then pass).

What the check does not cover

Reference cases

The tables below are inputs and the outputs of the original code, produced by the same oracle as the sufficiency check and generated, not typed (the generator keeps this page and the original in step). Use them as unit tests: if your rebuild gives a different number, read the chapter named in the heading again. Formats: positions and velocities in world units (exact decimals: the game counts in 1/65536 units), axes as Q14 integers (16384 = 1.0), speeds in world units per frame, rates in steps of 1/2048 turn per frame, pixels of the 640 × 350 screen with the origin included. Axis c is called "up" but points toward the bottom of the screen (chapter 3, chapter 15): a positive camera y is drawn below the centre. Unless a table says otherwise: single player, Polygons mode, shields 32, no bump immunity.

Distance exponents (chapter 3, chapter 17 2.2)

Vector (dx, 0, 0) in world units; start 0 = steering exponent, start 1 = display exponent of a scale-1 body (a scale-0 body has the start-0 column). Other axes 0.

dxstart 0start 1
088
12778
12867
25567
25656
100045
102345
102434
819112
819201
1638401
16385-10
-1638501
-16386-10
32769-10
32770-2-1
65540-3-2

Your ship, one frame (chapter 4, chapter 17 3)

Start: at the origin, identity axes (fwd (0, 0, 16384), right (16384, 0, 0), up (0, 16384, 0)), rates 0, shields 32, keyboard; the tumble counter is already counted down for this frame. Throttle is the requested forward speed in world units per frame (0x90 = 144 = full, −0x70 = −112 full reverse); extra thrust is the pick-up stock (0x400 per thrust satellite, at most 0x1000), used up one unit per axis correction. The rates column is pitch, yaw, roll; the tumble rates column is in the game's own order [pitch, roll, yaw].

casepitch, yaw, roll ratethrottleextra thrustvelocitypositionfwd (Q14)right (Q14)tumble rates [pitch, roll, yaw]
at rest, Shift (throttle up) + Right (yaw) held0, 2, 080(0.0123291015625, 0, 2)(0.0123291015625, 0, 2)(101, 0, 16384)(16384, 0, -97)[0, 0, 0]
at rest, Up held-2, 0, 000(0, 0, 0)(0, 0, 0)(0, -101, 16384)(16384, 0, 0)[0, 0, 0]
full throttle 0x90, flying at 144, nothing held0, 0, 01440(0, 0, 144)(0, 0, 144)(0, 0, 16384)(16384, 0, 0)[0, 0, 0]
the same with extra thrust 0x4000, 0, 01441023(0, 0, 160)(0, 0, 160)(0, 0, 16384)(16384, 0, 0)[0, 0, 0]
full throttle, Ctrl held0, 0, 01360(0, 0, 142)(0, 0, 142)(0, 0, 16384)(16384, 0, 0)[0, 0, 0]
tumbling (rates pitch 16, roll -8, yaw 4)15, 3, -700(0, 0, 0)(0, 0, 0)(150, 751, 16367)(16381, -355, -130)[15, -7, 3]

Your laser: hit or miss (chapter 6, chapter 17 7.3)

Shot at the origin after its move, identity axes; target centre and model scale. Box: ±512 along the flight, ±192 (scale 1) or ±96 (scale 0) across, limits included.

target centrescalehit
(0, 0, 512)1yes
(0, 0, 513)1no
(0, 0, -512)1yes
(192, 0, 0)1yes
(193, 0, 0)1no
(0, -192, 300)1yes
(96, 0, 0)0yes
(97, 0, 0)0no
(0, 0, 400)0yes

Alien laser and the pass-through (chapter 6, chapter 17 7.5)

You at the origin; an alien shot flying along +z (identity axes), tested where it is after its move. Box in the shot's axes: ±1024 sideways (right), ±256 up and ±256 along the flight, limits included. It moves 1,024 units per frame, so a shot tested at −512 and next at +512 has passed through you without a hit (Authentic A3).

shot positionhit
(0, 0, -512)no
(0, 0, -256)yes
(0, 0, 0)yes
(0, 0, 256)yes
(0, 0, 257)no
(0, 0, 512)no
(1024, 0, 0)yes
(1025, 0, 0)no
(0, 256, 0)yes
(0, 257, 0)no

Radar marks (chapter 15)

You at the origin, identity axes; the object at the given position. Screen pixels (origin included); the stalk runs from the radar-plane point to the mark; the plus is centred on the mark. Zoom −1 is the start value.

object atkindzoomstalkplus centrecolour
(300, -500, 2000)alien2(556, 270)–(556, 262)(556, 262)10
(300, -500, 2000)alien-1(552, 284)–(552, 283)(552, 283)10
(300, -500, 2000)pod-1(552, 284)–(552, 283)(552, 283)13
(-3000, 1000, -6000)satellite-1(546, 291)–(546, 292)(546, 292)15
(-3000, 1000, -6000)enemy_missile0(540, 297)–(540, 300)(540, 300)14
(20000, 0, 0)alien-1(591, 285)–(591, 285)(591, 285)10
(20000, 0, 0)alien-2(571, 285)–(571, 285)(571, 285)10
(40000, 0, 0)alien-6(554, 285)–(554, 285)(554, 285)10

A Fighter, one frame (chapter 7, chapter 17 4.4)

You at the origin. Fighter: speed 175 = its top speed, accel 0, turn limit 24, rates 0 before; "nose on you" = fwd (0, 0, −16384), right (−16384, 0, 0), up (0, 16384, 0). The display exponent is the one the renderer left in the previous frame.

casedisplay exp. beforestate afterpitch, yaw, roll ratespeedposition afterfwd after (Q14)fires
3000 ahead of you, nose on you, frame 43attack0, 0, 0175(0, 0, 2825)(0, 0, -16384)yes
the same, frame 53attack0, 0, 0175(0, 0, 2825)(0, 0, -16384)no
1500 away, nose on you (attack falls through to retreat)4retreat24, 0, 0175(0, 12.8814697265625, 1325.469970703125)(0, 1206, -16340)yes
3000 away, you 45° to its right3attack1, -24, 0175(-2987.1185302734375, 0.54473876953125, 2825.469970703125)(1206, 51, -16340)no
retreating, 9000 away, facing away (turns back)1attack0, 0, 0175(0, 0, 9175)(0, 0, 16384)no

A Pirate escaping with a pod (chapter 7, chapter 17 4.3)

Pirate in state "escape" at (−1500, 0, 0) flying along −x at 125 units per frame with pod 0 in tow; aliens left 8, pods left 6. The escape test uses the display exponent of the previous frame (< 0 = escaped). "–": the slot was freed (its record keeps leftovers that nothing reads).

casedisplay exp. beforealien existsstatedisplay exp. afterposition afteraliens leftpods leftpod 0 existsmessagesounds
you 40000 units away: escapes-1no–––75noPOD DESTROYED[]
you 20000 units away: keeps fleeing0yesescape0(-1625, 0, 0)86yes–[]

Your missile: a hit and the score wrap (chapter 6, chapter 17 5.4, 9.2)

Your missile homing at the origin along +z, speed 400, accel 25, turn 128; the target is a Commander (8 hit points, 400 points). A hit is the steering exponent missile → target ≥ 6 (every axis within [−256, 256)). The score wraps at 1,000,000. In the hit frame the missile slot is processed again at once: age 2, no move. "Exp. / age" is the display exponent while the missile flies and the explosion age once it explodes (the same field).

casemissile statemissile exp. / agemissile positionspeedtarget explodingtarget hit pointstarget agescoresounds
Commander 200 ahead, score 999950exploding2(0, 0, 0)400yes01350[0]
Commander 600 aheadhoming5(0, 0, 400)400no80999950[]

A Pirate's missile (speed 100, turn 8) flying along +z toward you at the origin. Its hit test is its display exponent to you ≥ 6 (scale 0: every axis within [−256, 256)), after its move. "Exp. / age" as above: display exponent while homing, explosion age while exploding.

casestateexp. / agepositionshieldsdeath countdownflashsounds
300 behind you, closing, shields 1exploding0(0, 0, -200)064hit[1]
300 behind you, shields 0 (dead)homing6(0, 0, -200)00–[]
700 behind you, shields 5homing4(0, 0, -600)50–[]

Level budgets (chapter 7, chapter 17 4.2)

Single player, Polygons mode, at the start of the level; "pods before" = pods left from the previous level (all six or none). Counts are Pirates, Fighters, Guardians, Commanders still to come.

levelpods beforealiens at oncecountsaliens leftpods leftPirate top speedexplosion sparks
164[8, 0, 0, 0]8612538
564[8, 8, 6, 2]24612538
1064[8, 8, 8, 8]32617538
1364[8, 8, 8, 8]32625038
1667[8, 8, 8, 8]32625038
1768[8, 8, 8, 8]32625038
704[0, 0, 0, 30]30012538

Satellite appearance (chapter 7, chapter 17 8.1)

The every-128th-frame spawn with the given counter and rand() values (x, y, z in that order). Kinds: 1 shields, 2 missiles, 3 extra thrust, 4 fire power. The counter is a signed 16-bit number.

counter beforerand()one already outcounter afterkindposition
5[0, 16384, 32767]no64(-10000, 0, 9999)
0[1, 2, 3]no13(-10000, -9999, -9999)
2[32767, 32767, 32767]no31(9999, 9999, 9999)
32767[100, 200, 300]no-327682(-9939, -9878, -9817)
-1[16383, 16384, 16385]no02(-1, 0, 0)
2[5000, 5000, 5000]yes2––

Overlapping sound effects (chapter 10)

One row per timer tick; an effect started in a row starts just before that row's tick. Effect 2 (pick-up) is cut by 5 (laser), which is cut by 1 (hit); the start of 0 at shields 0 is ignored; the option "None" freezes the sequencer for two ticks. Divisor = the PIT channel-2 divisor; frequency = 1,193,182 ÷ divisor Hz.

tickstartshieldsoptiondivisor sounding
0232PC Speaker1664
1–32PC Speaker1664
2532PC Speaker5120
3–32PC Speaker1536
4–32PC Speaker6144
5–32PC Speaker10240
6–32PC Speaker14336
7–32PC Speaker18432
8–32PC Speaker22528
9132PC Speaker1024
10–32PC Speaker2048
11–32PC Speaker4096
12–32PC Speaker8192
1300PC Speaker16384
14–0PC Speaker32768
15–32PC Speaker36864
16–32PC Speaker40960
17–32None40960
18–32None40960
19–32PC Speakeroff
20–32PC Speakeroff
21–32PC Speakeroff

One whole frame (chapter 2, chapter 17 1.1)

Level 1 just set up (six idle pods 1000 units out on the axes, 8 Pirates to come, 4 at once), you at the origin at rest with identity axes, 16 missiles, frame counter 63, satellite counter 0; Space and Shift held; rand() returns 1000, 2000, … Everything the frame changed. The shot hit pod 3 in its first test: "explosion −8" is its state word 0xFFF8 read as a signed number (chapter 17, 7.1), counting up to 0. For the pod, "display exponent / age" is the explosion age once it explodes (the same field).

whatafter the frame
frame counter63 → 64
throttle, velocity, position8, (0, 0, 2), (0, 0, 2)
fire cooldown2
shot (slot 0)position (0, 64, 1024), velocity (0, 0, 1024), explosion -8
pod 3 (home (0, 0, 1000))exploding, display exponent / age 1
alien spawnedslot 0, pirate, state attack, position (16374.7989501953125, 0.38909912109375, 126.664306640625), speed 125, hit points 2, display exponent 1
counts still to come, spawn direction, type rotation[7, 0, 0, 0], 1, 1
aliens left, pods left8, 5
sounds, message, flash, rand() values used[5, 0], –, –, 0

Shots against a pod over several frames (Authentic A1, A2)

Same world without the frame-63 spawn (counter starts at 1), Space held from the first frame, one pod moved straight ahead of you; the other pods stay at their homes. Columns: in which frame (1 = the first) the first shot hits the pod, if at all within the shot's 24 frames.

casehit in frame
pod 1000 ahead, at rest1
pod 400 ahead, at rest (too close: A2)never
pod 1750 ahead, full throttle (skipped over: A1)never
pod 2400 ahead, full throttle2

Testing Authentic mode

Chapter 20 defines Authentic as "every rule, bugs included, at the original step rates". The cases above already pin several of its bugs: the laser that skips a target at full throttle (A1) and cannot hit one 400 units ahead (A2), the alien shot that passes through you (A3), the score wrap, the satellite counter wrap. Beyond single functions, test whole runs:

  1. Same inputs, same random numbers, same states. Seed Borland's rand() (chapter 17, 1.4) with a fixed value, feed a recorded key script frame by frame (which keys are latched at the top of each frame), and run N frames. Two runs must give identical states; a hash of the state per frame makes the first difference easy to find.
  2. Against the original. The same script and seed in the original program (or its code in an emulator, as here) must give the same states frame by frame. The frame of the first difference and the variable that differs point to the rule to read again.
  3. Step clock. 60 seconds of single player are about 1,092 steps (18.2065 per second: 1,092 or 1,093 depending on the tick phase); a multiplayer session steps at its agreed rate (chapter 20).
  4. Modern mode passes the same tests except the rows that chapter 20 marks "fix" or whose option is changed; each fix gets its own test of the new behaviour.
What to log per frame

Log in the game's own units, so values can be compared exactly: the frame counter; the keys latched; how many rand() values were drawn; your position and velocity (raw 64-bit), axes (Q14), turn rates, throttle, extra thrust, shields, death countdown, bump immunity, tumble, score, missiles, fire power; for every alien, missile, pod, satellite and shot slot: type, state, position, axes, speed, rates, display exponent, hit points, target; the counters (aliens left, pods left, budgets, spawn rotations, satellite counter); and the frame's side effects: message and its timer, flash colour, sounds started. A difference in a side effect with equal states usually means an order problem inside the frame (chapter 17, 1.1).

How to rerun the check

The tools live in the private reconstruction repository, because they need the original program (its unpacked load image) to run the oracle (tools/doccheck/README.md):

.venv/bin/python -I tools/doccheck/compare.py path/to/impl.py [--only fn1,fn2] [--out report.md]
.venv/bin/python -I tools/doccheck/compare.py tools/doccheck/oracle.py      # self-check: 100 %
.venv/bin/python -I tools/doccheck/ref_cases.py --write                     # regenerate the tables above
.venv/bin/python -I tests/test_ref_cases.py                                 # page equals generator

The function descriptions an implementer gets are in tools/doccheck/API.md; the oracle's conversions and replaced routines in tools/doccheck/oracle_notes.md; every round's implementations, notes and reports, and the analysis of round 3, in evidence/doccheck/. A whole comparison takes about a minute.

What a rebuild should test first

For a rebuild: a checklist
  1. The integer helpers of chapter 17, 2.1–2.2: dot with its 32-bit wrap, cross with the lost borrow, rotate, and the distance exponent (first table above, all rows). Everything else is built on them.
  2. Your ship from rest for a few frames with each key (second table), then with tumble.
  3. The box tests: laser, alien laser, contact (exponent ≥ 7), missile contact (≥ 6), at their exact limits.
  4. One Fighter and one Pirate through all their states; a missile hit in the same frame as the explosion start; the score wrap.
  5. Level budgets for levels 1, 5, 10, 13, 16, 17 and the no-pods level; the spawn rotation; the satellite cycle from a fresh program start (first kind: extra thrust).
  6. The frame order (chapter 17, 1.1) with one whole frame (the frame table above), then hundreds of frames against a recording with a fixed seed.
  7. The renderer's numbers that the rules use (display exponent, camera coordinates, the view test) before the picture; then the picture.
  8. Sound: the sequencer table, with an effect cut by another.