sourcegames/racer/racer.xtl

1⍝!/usr/bin/env xetal 2⍝│ The racer, scripted (seed 1), with the rules of Race.xtl on lib/Ecs: 3⍝│ the cars as rows of one matrix, and driving, the grass, bumping, laps 4⍝│ and places as systems over every car at once. 5"rc:" u̲se< "Race" 6"ec:" u̲se< "Ecs" 7 8⍝ A new race: a car for each paint in racer.toml (yours is the first), 9⍝ on the grid behind the start line. The world: a row per slot (8) and a 10⍝ column per field. 11start ← ʳᶜn̲ew 0 12(W, t, st, pl) ← start 13s̲hape W 14ᵉᶜc̲ount W 15 16⍝ Every car: laps done, the point of the track it heads for, its place 17⍝ (one more than the cars ahead of it, every pair compared at once). 18ʳᶜc̲ars start 19 20⍝ The lights go after two seconds; then the rivals steer for the points 21⍝ of the track. Twelve seconds in (240 ticks), every car again: 22ᵘw̲ait ← { s n → n = 0 ? s◆ (s ʳᶜt̲ick 0.05) ᵘw̲ait n − 1 } 23later ← start ᵘw̲ait 240 24ʳᶜc̲ars later 25 26⍝ Your car never moved (no keys): still on the grid, heading right at 27⍝ speed 0, the second point of the track ahead. Your lap, your place and 28⍝ the seconds: 29f̲loor 0.5 + 100 × ʳᶜc̲ar later 30ʳᶜy̲ou later 31 32⍝ Up three times: your speed, then a second later where you are. 33sped ← ((later ʳᶜk̲ey "UP") ʳᶜk̲ey "UP") ʳᶜk̲ey "UP" 344 s̲elect ʳᶜc̲ar sped 35moved ← sped ᵘw̲ait 20 36f̲loor 0.5 + 100 × 2 t̲ake ʳᶜc̲ar moved 37_ ← ⎕S̲HOW ʳᶜd̲raw moved 38 39⍝ What the race guarantees, checked by a_ssert< (silent when it holds). 40ᵘw̲orld ← { (W, t, st, pl) → W } 41_ ← "4 = ec:c_ount u:w_orld rc:n_ew 0" a̲ssert< "four cars in a new race"
a̲ssert< expands to
({ @ → (4 = ᵉᶜc̲ount ᵘw̲orld ʳᶜn̲ew 0) ? @◆ ⎕E̲RR "assertion failed: 4 = ec:c_ount u:w_orld rc:n_ew 0 (four cars in a new race) [games/racer/racer.xtl:41]"◆ @ } @)
42_ ← "'& r_/ 1 2 3 4.0 = s_ort 3 s_elect_2 rc:c_ars moved" a̲ssert< "the places are one to four"
a̲ssert< expands to
({ @ → ('∧ r̲/ 1 2 3 4.0 = s̲ort 3 s̲elect₂ ʳᶜc̲ars moved) ? @◆ ⎕E̲RR "assertion failed: '& r_/ 1 2 3 4.0 = s_ort 3 s_elect_2 rc:c_ars moved (the places are one to four) [games/racer/racer.xtl:42]"◆ @ } @)
43_ ← "0 = rc:s_tatus moved" a̲ssert< "still racing"
a̲ssert< expands to
({ @ → (0 = ʳᶜs̲tatus moved) ? @◆ ⎕E̲RR "assertion failed: 0 = rc:s_tatus moved (still racing) [games/racer/racer.xtl:43]"◆ @ } @)