sourcegames/trek/trek.xtl
1⍝!/usr/bin/env xetal
2⍝# Star Trek, scripted (seed 1), with the rules of StarTrek.xtl.
3ᵗ⁼u̲se< "StarTrek"
4
5⍝ A new game. The galaxy was made all at once: three 8 by 8 planes, the
6⍝ Klingons, the bases and the stars in every quadrant.
7s ← ᵗn̲ew 0
8s ᵗg̲alaxy 1
9s ᵗg̲alaxy 2
10s ᵗg̲alaxy 3
11ᵗk̲lingons s
12s ← ᵗs̲rs s
13s ← ᵗl̲rs s
14
15⍝ A course is a step from the compass table; a path is every step at
16⍝ once: course 3 (east) for 5 sectors from where the Enterprise is.
17ᵗc̲ourses @
18P ← s ᵗp̲ath 3 5
19P
20ᵗi̲nside P
21(ᵗc̲ells P) s̲elect r̲avel ᵗg̲rid s ⍝ what lies on each step
22
23⍝ Warp east into the next quadrant, then fight: phasers hit every
24⍝ Klingon at once, a torpedo flies its whole track at once.
25s ← s ᵗc̲ommand 3 3 1
26s ← s ᵗc̲ommand 6 6
27s ← s ᵗc̲ommand 5 10
28s ← s ᵗc̲ommand 8
29ᵗs̲tatus s
30
31⍝# The game ends when the stardate runs out: warp is one stardate a
32⍝# factor.
33ᵘf̲ar ← { s → s ᵗc̲ommand 3 5 8 }
34s ← 4 'ᵘf̲ar p̲ower s
35ᵗs̲tatus s ⍝ 2: out of time
36ᵗe̲nd s
37
38⍝ What the game guarantees, checked by a_ssert< (the condition as
39⍝ written; silent when it holds, a line on standard error, which fails
40⍝ the tests, when it does not).
41ok ← "2 = t:s_tatus s" a̲ssert< "the long voyage runs out of time"
42ok ← "0 <= t:k_lingons s" a̲ssert< "never fewer than no Klingons"
a̲ssert< expands to
({ @ → (2 = ᵗs̲tatus s) ? @◆ ⎕E̲RR "assertion failed: 2 = t:s_tatus s (the long voyage runs out of time) [games/trek/trek.xtl:41]"◆ @ } @)a̲ssert< expands to
({ @ → (0 ≤ ᵗk̲lingons s) ? @◆ ⎕E̲RR "assertion failed: 0 <= t:k_lingons s (never fewer than no Klingons) [games/trek/trek.xtl:42]"◆ @ } @)