sourcegames/robot-chase/play.xtl
1⍝!/usr/bin/env xetal
2⍝# Robot chase at the terminal, as the COR24 BASIC game plays it: move with the numeric keypad (7 8 9 up,
3⍝# 4 6 sideways, 5 waits, 1 2 3 down), 0 teleports (3 a game), 10 scans
4⍝# the board in 4 by 4 regions, 99 resigns. Make the robots crash into
5⍝# each other or into wrecks; clear them all to win. The rules are those
6⍝# of RobotChase.xtl.
7ʳ⁼u̲se< "RobotChase"
8ᵖ⁼u̲se< "Play"
9said ← p̲rint! ""
10said ← p̲rint! "*** ROBOT CHASE ***"
11said ← p̲rint! "EVADE THE ROBOTS - MAKE THEM COLLIDE."
12
13⍝# A command: the first number on the line; one that is not a command
14⍝# is asked for again.
15ᵘa̲sk ← { s →
16 said ← p̲rint! ""
17 said ← p̲rint! "1-9=MOVE(5=WAIT) 0=TELE 10=LRS 99=QUIT"
18 c ← ᵖn̲umber "COMMAND ?"
19 (c m̲ember? 0 1 2 3 4 5 6 7 8 9 10 99) ? c◆ ᵘa̲sk s
20}
21
22⍝# The board and its header, as the BASIC prints them each turn.
23ᵘs̲how ← { s →
24 said ← p̲rint! ""
25 pic ← ⎕S̲HOW ʳp̲icture s
26 said ← p̲rint! @ f̲ormat< "TURN {r:t_urn s} ROBOTS {'+ r_/ r:a_live s} TELE {r:t_ele s}"
27 ʳv̲iew s
28}
29
30⍝# A turn: show, read, move (or scan), say what happened, until the end.
31ᵘt̲urn ← { s →
32 shown ← p̲rint! ᵘs̲how s
33 c ← ᵘa̲sk s
34 c = 10 ? ᵘt̲urn ᵘs̲can s
35 t ← s ʳm̲ove c
36 0 = ʳe̲vent t ? ᵘa̲fter t◆ ᵘa̲fter ᵘs̲ay t
37}
38ᵘs̲ay ← { t →
39 told ← p̲rint! ʳm̲essage t
40 t
41}
42ᵘa̲fter ← { t → 0 < ʳs̲tatus t ? ᵘe̲nd t◆ ᵘt̲urn t }
43ᵘs̲can ← { s →
44 said ← p̲rint! ""
45 said ← p̲rint! "LRS: ROBOTS, WRECKS, YOU IN EACH 4X4 REGION"
46 shown ← p̲rint! ʳl̲rs s
47 s
48}
49⍝# The end: (unless you resigned) the board once more, then the verdict.
50ᵘe̲nd ← { s →
51 9 = ʳe̲vent s ? "GAME OVER"
52 shown ← p̲rint! ᵘs̲how s
53 said ← p̲rint! ""
54 1 = ʳs̲tatus s ? @ f̲ormat< "*** YOU WIN IN {r:t_urn s} TURNS! ***"◆ "*** YOU WERE CAUGHT. ***"
55}
56ᵘt̲urn ʳn̲ew 0
f̲ormat< expands to
("TURN " c̲at (f̲ormat (ʳt̲urn s)) c̲at " ROBOTS " c̲at (f̲ormat ('+ r̲/ ʳa̲live s)) c̲at " TELE " c̲at (f̲ormat (ʳt̲ele s)))