sourcegames/trek-adventure/trek-adventure.xtl
1⍝!/usr/bin/env xetal
2⍝# Trek adventure, scripted, with the rules of TrekAdventure.xtl.
3ᵗ⁼u̲se< "TrekAdventure"
4
5⍝ The text is one table of 157 lines; its four columns (text, key,
6⍝ condition item, condition value) have one entry per line.
7(t̲ally ᵗt̲ext @) c̲at (t̲ally ᵗk̲eys @) c̲at (t̲ally ᵗf̲lags @) c̲at t̲ally ᵗv̲alues @
8
9⍝ A room is the rows whose key it is and whose condition holds: one mask
10⍝ over the whole table. Storage (room 5) at the start, then after the
11⍝ toolkit and the coupler are taken: their rows drop out.
12s ← ᵗn̲ew 0
13s ← s ᵗu̲pdate 1 5
14s ᵗl̲ines 5
15said ← s ᵗs̲ay 5
16taken ← s ᵗu̲pdate 5 1 6 1
17taken ᵗl̲ines 5
18said ← taken ᵗs̲ay 5
19
20⍝ The exits are a 9 by 9 table: from the corridor (room 3) you can reach
21⍝ rooms 2, 4, 5, 7 and 9.
22ᵗe̲xits @
23w̲here 3 s̲elect ᵗe̲xits @
24
25⍝ The state is one vector of 12; an update changes several items at once
26⍝ (here: the room to 6 and the event to 0).
27s
28s ᵗu̲pdate 1 6 12 0
29
30⍝ The winning walkthrough as a table of commands (command, argument),
31⍝ played a row at a time: each turn a command, then the clock. Every
32⍝ state is kept, so the whole game is a table: a row per turn, a column
33⍝ per state item.
34moves ← 11 2 r̲eshape 3 2 3 3 3 5 4 3 4 4 4 5 3 3 3 2 3 6 5 1 5 2
35ᵘp̲lay ← { s m →
36 0 = t̲ally m ? (1 c̲at t̲ally s) r̲eshape s
37 next ← ᵗc̲lock s ᵗm̲ove f̲irst m
38 ((1 c̲at t̲ally s) r̲eshape s) c̲at next ᵘp̲lay 1 d̲rop m
39}
40game ← (ᵗn̲ew 0) ᵘp̲lay moves
41game
42last ← r̲avel -1 t̲ake game
43ᵗs̲tatus last ⍝ 1: won
44said ← last ᵗs̲ay 201
45
46⍝ Two ways to lose: fire the phaser at the boarders in the shuttle bay
47⍝ (2: dead), or let the turns run out (3: too late). Throwing the
48⍝ tribble instead makes the boarders retreat.
49bay ← 8 20 1 0 0 0 1 0 1 0 0 0
50ᵗs̲tatus bay ᵗm̲ove 7 0
51said ← bay ᵗs̲ay ᵗs̲aid bay ᵗm̲ove 6 0
529 s̲elect bay ᵗm̲ove 6 0 ⍝ the boarders: gone
53ᵘw̲ait ← { s → ᵗc̲lock s ᵗm̲ove 1 0 }
54ᵗs̲tatus 30 'ᵘw̲ait p̲ower ᵗn̲ew 0
55
56⍝ Nothing carried: the inventory says so.
57said ← (ᵗn̲ew 0) ᵗs̲ay ᵗs̲aid (ᵗn̲ew 0) ᵗm̲ove 2 0
58
59⍝ What the game guarantees, checked by a_ssert< (the condition as
60⍝ written; silent when it holds, a line on standard error, which fails
61⍝ the tests, when it does not).
62ok ← "1 = t:s_tatus last" a̲ssert< "the scripted moves win"