sourcegames/horse-race/horse-race.xtl
1⍝!/usr/bin/env xetal
2⍝# Horse race: a scripted race (seed 1) with the rules of HorseRace.xtl.
3ʰʳ⁼u̲se< "HorseRace"
4
5⍝ One round from the start, step by step: the rolls, the new positions,
6⍝ the track.
7p ← ʰʳn̲ew 5
8r ← ʰʳr̲oll p
9r
10p ← p ʰʳm̲ove r
11p
12ʰʳv̲iew p
13
14⍝# A whole race: a round at a time until a horse finishes; each round
15⍝# printed as its rolls, then the track.
16ᵘr̲ace ← { p →
17 r ← p̲rint! ʰʳr̲oll p
18 q ← p ʰʳm̲ove r
19 shown ← p̲rint! ʰʳv̲iew q
20 1 = ʰʳs̲tatus q ? q◆ ᵘr̲ace q
21}
22final ← ᵘr̲ace ʰʳn̲ew 5
23final
24(ʰʳw̲inners final) s̲elect ʰʳn̲ames @
25
26⍝ What the game guarantees, checked by a_ssert< (the condition as
27⍝ written; silent when it holds, a line on standard error, which fails
28⍝ the tests, when it does not).
29ok ← "1 = hr:s_tatus final" a̲ssert< "the race ends with a winner"
30ok ← "0 < t_ally hr:w_inners final" a̲ssert< "someone wins"
a̲ssert< expands to
({ @ → (1 = ʰʳs̲tatus final) ? @◆ ⎕E̲RR "assertion failed: 1 = hr:s_tatus final (the race ends with a winner) [games/horse-race/horse-race.xtl:29]"◆ @ } @)