sourcegames/dungeon/Crawl.xtl
1⍝│ The dungeon's rules, a library: dungeon.xtl (scripted), play.xtl (the
2⍝│ game: arrow keys) and the web page all use these. Built on lib/Ecs: a
3⍝│ world is a matrix, a row per entity, and every rule is a system, one
4⍝│ expression over every entity with the components it needs. You, the
5⍝│ monsters and the things to pick up are entities; what each one is
6⍝│ comes from its components (dungeon.toml gives each kind its own), so
7⍝│ a new kind of monster or item is a new table there, not new code here.
8⍝│ A game's state is a tuple: (the world, the gold found, the turns
9⍝│ taken, what just happened, the map it is played on). Each new game
10⍝│ picks a map and places you, the way out, the monsters and the items
11⍝│ on its floor at random, from its seed.
12
13"ec:" u̲se< "Ecs"
14"sv:" u̲se< "Svg"
15"t:" u̲se< "Text"
16
17⍝━━ The data
18
19⍝│ The layout: where it is, how much it can take and how hard it hits,
20⍝│ its kind, whether it comes after you, and what it gives when picked up
21⍝│ (or drops when beaten), you, and the way out.
22"h" ᵉᶜc̲omponents< "pos:2 hp atk kind chase heal gold player goal"
23⍝│ A cell's first character, and a column of the kinds' table as numbers.
24ʰf̲irstChar ← { x → f̲irst d̲isclose x }
25ʰc̲olumn ← { j → 'ˢᵛn̲um e̲ach j s̲elect₂ kinds }
26⍝│ The maps: 9 rows of 25 each, one after another in dungeon.toml.
27cells ← ᵗj̲oin "dungeon.toml" ⎕L̲IST "maps"
28maps ← (t̲ally cells) d̲iv 225
29⍝│ Map lv's cells (225, row by row), and its walls.
30ʰg̲rid ← { lv → 225 t̲ake (225 × lv − 1) d̲rop cells }
31ʰw̲alls ← { lv → (ʰg̲rid lv) = f̲irst "#" }
32kinds ← ("dungeon.toml" "kind") ⎕T̲ABLE ("kinds" "fields")
33glyphs ← 'ʰf̲irstChar e̲ach 1 s̲elect₂ kinds
34colors ← 7 s̲elect₂ kinds
35⍝│ Your numbers, then each kind's (you are kind 1, the kinds 2 on): hit
36⍝│ points, attack, chase, heal, gold.
37you ← 'ˢᵛn̲um e̲ach "dungeon.toml" ⎕L̲IST "player"
38HP ← (f̲irst you) c̲at ʰc̲olumn 2
39AT ← (2 s̲elect you) c̲at ʰc̲olumn 3
40CH ← 0.0 c̲at ʰc̲olumn 4
41HE ← 0.0 c̲at ʰc̲olumn 5
42GO ← 0.0 c̲at ʰc̲olumn 6
43
44⍝━━ A new game
45
46⍝│ Steps between cell a and every cell of c (rows and columns apart).
47ʰs̲teps ← { a c → (a̲bs ((a − 1) d̲iv 25) − (c − 1) d̲iv 25) + a̲bs ((a − 1) m̲od 25) − (c − 1) m̲od 25 }
48⍝ :: (Any a, Num b, Num c) => a -> (Float, b, c, Char, Int)
49⍝│ A new game on a map drawn at random: you on a random floor cell, the
50⍝│ way out on the floor cell farthest from you, and the map's monsters
51⍝│ and items (it says how many of each kind) on random floor cells at
52⍝│ least 4 steps from you; every entity given its kind's components, all
53⍝│ at once (a kind with no heal has no heal component, and so on).
54ˡn̲ew ← { x →
55 lv ← r̲oll! maps
56 g ← ʰg̲rid lv
57 ents ← w̲here g m̲ember? glyphs
58 kk ← glyphs i̲ndexOf ents s̲elect g
59 floor ← w̲here g ≠ f̲irst "#"
60 order ← (g̲rade r̲oll! (t̲ally floor) r̲eshape 1000000) s̲elect floor
61 me ← f̲irst order
62 goal ← f̲irst (g̲rade n̲eg me ʰs̲teps floor) s̲elect floor
63 far ← ((4 ≤ me ʰs̲teps order) ∧ order ≠ goal) r̲eplicate order
64 at ← me c̲at goal c̲at (t̲ally ents) t̲ake far
65 (spawned, ids) ← (ʰw̲orld 32) ᵉᶜs̲pawn t̲ally at
66 cell ← f̲loat o̲\ (2 c̲at t̲ally at) r̲eshape ((at − 1) d̲iv 25) c̲at (at − 1) m̲od 25
67 placed ← (spawned ʰs̲etPos (ids, cell)) ʰs̲etGoal (2 s̲elect ids, 1.0)
68 mob ← ((r̲ange t̲ally ids) ≠ 2) r̲eplicate ids
69 k ← 1 c̲at 1 + kk
70 named ← (placed ʰs̲etKind (mob, f̲loat k − 1)) ʰs̲etPlayer (f̲irst ids, 1.0)
71 armed ← ((named ʰp̲utSome (mob, k, HP, 1)) ʰp̲utSome (mob, k, AT, 2)) ʰp̲utSome (mob, k, CH, 3)
72 W ← (armed ʰp̲utSome (mob, k, HE, 4)) ʰp̲utSome (mob, k, GO, 5)
73 (W, 0, 0, "Find the way out (>). Arrow keys or WASD to move; walk into a monster to fight.", lv)
74}
75⍝│ Component c (1 hp, 2 atk, 3 chase, 4 heal, 5 gold) for the entities
76⍝│ ids whose kind k gives it a value above 0, every one at once.
77ʰp̲utSome ← { W (ids, k, v, c) →
78 x ← k s̲elect v
79 on ← w̲here x > 0
80 c = 1 ? W ʰs̲etHp (on s̲elect ids, on s̲elect x)
81 c = 2 ? W ʰs̲etAtk (on s̲elect ids, on s̲elect x)
82 c = 3 ? W ʰs̲etChase (on s̲elect ids, on s̲elect x)
83 c = 4 ? W ʰs̲etHeal (on s̲elect ids, on s̲elect x)
84 W ʰs̲etGold (on s̲elect ids, on s̲elect x)
85}
86
87⍝━━ The systems
88
89⍝│ The sign of each number: 1, 0 or -1.
90ʰs̲ign ← { x → (x > 0) − x < 0 }
91⍝│ A cell's number (1 to 225) from its row and column (from 0), many at
92⍝│ once (rows of a matrix, row then column).
93ʰc̲ell ← { P → 1 + (25 × f̲loor 1 s̲elect₂ P) + f̲loor 2 s̲elect₂ P }
94⍝│ Which entities are at the point p (a row and a column).
95ʰa̲t ← { W p → '∧ r̲/₂ (ʰp̲os W) = ((t̲ally W) c̲at 2) r̲eshape p }
96⍝│ The fighters other than you, alive.
97ʰf̲oes ← { W → w̲here (ᵉᶜa̲live W) ∧ (ʰh̲asHp W) ∧ 0 = ʰp̲layer W }
98⍝│ Your entity.
99ʰm̲e ← { W → f̲irst w̲here 0 < ʰp̲layer W }
100
101⍝ :: (Num a, Any b) => (Float, Int, a, b, Int) -> Float -> (Float, Int, a, Char, Int)
102⍝│ A turn: you move by d (a row and a column step) or hit the monster in
103⍝│ the way, then pick up what lies where you stand, the beaten monsters
104⍝│ drop their gold and go, and every monster that sees you comes a step
105⍝│ closer or hits you: each a system over every entity at once.
106ˡt̲urn ← { (W, g, n, m, lv) d →
107 me ← ʰm̲e W
108 to ← (me s̲elect ʰp̲os W) + d
109 foe ← w̲here (ᵉᶜa̲live W) ∧ (ʰh̲asHp W) ∧ (0 = ʰp̲layer W) ∧ W ʰa̲t to
110 wall ← (ʰc̲ell 1 2 r̲eshape to) s̲elect ʰw̲alls lv
111 (stepped, said) ← ʰy̲ou (W, me, to, foe, f̲irst wall)
112 (looted, found, picked) ← ʰp̲ickUp (stepped, g, me)
113 (cleared, gold, beaten) ← ʰb̲eaten (looted, found)
114 (after, hurt) ← ʰm̲onsters (cleared, me, lv)
115 (after, gold, n + 1, ᵗj̲oin (e̲nclose said) c̲at picked c̲at beaten c̲at e̲nclose hurt, lv)
116}
117⍝│ You: a hit on the monster in the way, else a step (not into a wall).
118ʰy̲ou ← { (W, me, to, foe, wall) →
119 0 < t̲ally foe ? (W ʰs̲etHp (foe, (foe s̲elect ʰh̲p W) − me s̲elect ʰa̲tk W), "You hit it. ")
120 wall ? (W, "A wall. ")
121 (W ʰs̲etPos (me, to), "")
122}
123⍝│ What lies where you stand, picked up: hit points back, gold found;
124⍝│ the items go.
125ʰp̲ickUp ← { (W, g, me) →
126 here ← w̲here (ᵉᶜa̲live W) ∧ (n̲ot ʰh̲asHp W) ∧ ((ʰh̲asHeal W) ∨ ʰh̲asGold W) ∧ W ʰa̲t me s̲elect ʰp̲os W
127 0 = t̲ally here ? (W, g, 0 r̲eshape e̲nclose "")
128 heal ← '+ r̲/ here s̲elect ʰh̲eal W
129 gold ← '+ r̲/ here s̲elect ʰg̲old W
130 healed ← W ʰs̲etHp (me, heal + me s̲elect ʰh̲p W)
131 (healed ᵉᶜd̲espawn here, g + f̲loor gold, e̲nclose @ f̲ormat< "You pick up {f_loor heal} hp and {f_loor gold} gold. ")
132}
133⍝│ The beaten monsters (no hit points left) drop their gold and go.
134ʰb̲eaten ← { (W, g) →
135 dead ← ((ʰf̲oes W) s̲elect 0 ≥ ʰh̲p W) r̲eplicate ʰf̲oes W
136 0 = t̲ally dead ? (W, g, 0 r̲eshape e̲nclose "")
137 (W ᵉᶜd̲espawn dead, g + f̲loor '+ r̲/ dead s̲elect ʰg̲old W, e̲nclose "You beat it. ")
138}
139⍝│ Every monster that chases and is within 6 steps comes a step closer
140⍝│ (the longer way first), all at once: not into a wall, nor into
141⍝│ another, nor two into one cell; one next to you hits you instead.
142ʰm̲onsters ← { (W, me, lv) →
143 ms ← ((ʰf̲oes W) s̲elect ʰh̲asChase W) r̲eplicate ʰf̲oes W
144 0 = t̲ally ms ? (W, "")
145 P ← ms s̲elect ʰp̲os W
146 d ← (((t̲ally ms) c̲at 2) r̲eshape me s̲elect ʰp̲os W) − P
147 far ← '+ r̲/₂ a̲bs d
148 next ← far = 1
149 hit ← '+ r̲/ next r̲eplicate ms s̲elect ʰa̲tk W
150 struck ← W ʰs̲etHp (me, (me s̲elect ʰh̲p W) − hit)
151 go ← (far > 1) ∧ far ≤ 6
152 rowFirst ← (a̲bs 1 s̲elect₂ d) ≥ a̲bs 2 s̲elect₂ d
153 step ← o̲\ (2 c̲at t̲ally ms) r̲eshape (rowFirst × ʰs̲ign 1 s̲elect₂ d) c̲at (n̲ot rowFirst) × ʰs̲ign 2 s̲elect₂ d
154 want ← P + f̲loat step × go '× t̲able 1 1
155 c ← ʰc̲ell want
156 taken ← ʰc̲ell (w̲here (ᵉᶜa̲live struck) ∧ ʰh̲asHp struck) s̲elect ʰp̲os struck
157 ok ← go ∧ (n̲ot c s̲elect ʰw̲alls lv) ∧ (n̲ot c m̲ember? taken) ∧ (c i̲ndexOf c) = r̲ange t̲ally c
158 Q ← (P × f̲loat n̲ot ok '× t̲able 1 1) + want × f̲loat ok '× t̲able 1 1
159 (struck ʰs̲etPos (ms, Q), ʰo̲uch hit)
160}
161⍝│ What a monster's hit says.
162ʰo̲uch ← { hit →
163 0 = hit ? ""
164 @ f̲ormat< "It hits you for {f_loor hit}."
165}
166
167⍝━━ What it shows
168
169⍝ :: (Num a, Any b, Any c, Any d, Any e, Num f) => (a, b, c, d, e) -> f
170⍝│ 0 playing, 1 you found the way out, 2 you were beaten.
171ˡs̲tatus ← { (W, g, n, m, lv) →
172 me ← ʰm̲e W
173 0 ≥ me s̲elect ʰh̲p W ? 2
174 goal ← f̲irst w̲here 0 < ʰg̲oal W
175 '∧ r̲/ (me s̲elect ʰp̲os W) = goal s̲elect ʰp̲os W ? 1
176 0
177}
178⍝ :: (Num a, Any b, Any c) => (a, Int, Int, b, c) -> Int
179⍝│ Your hit points, gold and turns.
180ˡy̲ou ← { (W, g, n, m, lv) → (f̲loor (ʰm̲e W) s̲elect ʰh̲p W) c̲at g c̲at n }
181⍝│ A cell's fill: a wall or the floor.
182ʰf̲ill ← { c → d̲isclose (1 + c = f̲irst "#") s̲elect "#22223b" "#4a4e69" }
183⍝│ A cell of the map: x, y and its character.
184ʰs̲quare ← { (x, y, c) → e̲nclose @ f̲ormat< "<rect x=\"{sv:w_hole x}\" y=\"{sv:w_hole y}\" width=\"100\" height=\"100\" fill=\"{h:f_ill c}\" stroke=\"#000000\" stroke-width=\"2\"/>" }
185⍝│ Map lv drawn once: 225 cells of 100 units, below a row for words.
186ʰl̲ayer ← { lv →
187 g ← ʰg̲rid lv
188 ᵗj̲oin '{ k → ʰs̲quare (100.0 × f̲loat (k − 1) m̲od 25, 100.0 + 100.0 × f̲loat (k − 1) d̲iv 25, k s̲elect g) } e̲ach r̲ange 225
189}
190layers ← 'ʰl̲ayer m̲ap r̲ange maps
191⍝│ An entity's glyph and color: you an @, a kind its own.
192ʰg̲lyph ← { k → 0 = k ? "@"◆ (k s̲elect glyphs) c̲at "" }
193ʰc̲olor ← { k → 0 = k ? "#ffffff"◆ d̲isclose k s̲elect colors }
194⍝│ An entity as SVG: the way out a teal cell with >, the others a glyph.
195ʰe̲ntity ← { (x, y, k, goal) →
196 goal ? @ f̲ormat< "<rect x=\"{sv:w_hole x}\" y=\"{sv:w_hole y + 100}\" width=\"100\" height=\"100\" fill=\"#2a9d8f\"/><text class=\"entity\" x=\"{sv:w_hole x + 50}\" y=\"{sv:w_hole y + 180}\" font-size=\"84\" text-anchor=\"middle\" font-family=\"monospace\" font-weight=\"bold\" fill=\"#ffffff\">></text>"
197 @ f̲ormat< "<text class=\"entity\" x=\"{sv:w_hole x + 50}\" y=\"{sv:w_hole y + 180}\" font-size=\"84\" text-anchor=\"middle\" font-family=\"monospace\" font-weight=\"bold\" fill=\"{h:c_olor k}\">{h:g_lyph k}</text>"
198}
199⍝ :: (Float, Int, Int, a, Int) -> Char
200⍝│ The picture, as SVG text: what you have and what just happened, the
201⍝│ map, and every entity alive (the way out first, under the others).
202ˡd̲raw ← { (W, g, n, m, lv) →
203 v ← 0.0 0.0 2500.0 1000.0
204 y ← ˡy̲ou (W, g, n, m, lv)
205 top ← (20.0, 70.0, 44.0) ˢᵛw̲ords @ f̲ormat< "HP {f_irst y} Gold {2 s_elect y} Turn {3 s_elect y} {m}"
206 alive ← w̲here ᵉᶜa̲live W
207 live ← (g̲rade n̲eg alive s̲elect ʰg̲oal W) s̲elect alive
208 P ← live s̲elect ʰp̲os W
209 k ← f̲loor live s̲elect ʰk̲ind W
210 o ← live s̲elect ʰg̲oal W
211 ents ← '{ i → e̲nclose ʰe̲ntity (100.0 × i s̲elect 2 s̲elect₂ P, 100.0 × i s̲elect 1 s̲elect₂ P, i s̲elect k, 0 < i s̲elect o) } e̲ach r̲ange t̲ally live
212 v ˢᵛp̲icture (v ˢᵛr̲ect "fill=\"#0b0b14\"") c̲at (e̲nclose d̲isclose lv s̲elect layers) c̲at ents c̲at top
213}
214⍝ :: (Num a, Any b, Any c, Any d, Any e, Num f, Truthy f) => (a, b, c, d, e) -> f
215⍝│ Which components each living entity has, a row each: hit points,
216⍝│ attack, chase, heal, gold (1 where it has it), from the masks the
217⍝│ macro wrote.
218ˡh̲as ← { (W, g, n, m, lv) →
219 M ← o̲\ (5 c̲at t̲ally W) r̲eshape 0 + (ʰh̲asHp W) c̲at (ʰh̲asAtk W) c̲at (ʰh̲asChase W) c̲at (ʰh̲asHeal W) c̲at ʰh̲asGold W
220 (w̲here ᵉᶜa̲live W) s̲elect M
221}
ᵉᶜc̲omponents< expands to
ʰw̲orld ← { n → (n c̲at 20) r̲eshape 0.0 } ʰp̲os ← { W → (3 4) s̲elect₂ W } ʰh̲asPos ← { W → 0 < 2 s̲elect₂ W } ʰs̲etPos ← { W (ids, v) → i ← r̲avel ids V ← (((t̲ally i) c̲at 1) r̲eshape 1.0) c̲at₂ ((t̲ally i) c̲at 2) r̲eshape v R ← f̲loat (r̲ange t̲ally W) '= t̲able i C ← f̲loat (2 3 4) '= t̲able r̲ange 20 M ← 0 < R '+ '× i̲nner (((t̲ally i) c̲at 3) r̲eshape 1.0) '+ '× i̲nner C (W × f̲loat n̲ot M) + R '+ '× i̲nner V '+ '× i̲nner C } ʰd̲ropPos ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 2 = r̲ange 20 } ʰh̲p ← { W → (6) s̲elect₂ W } ʰh̲asHp ← { W → 0 < 5 s̲elect₂ W } ʰs̲etHp ← { W (ids, v) → i ← r̲avel ids V ← (((t̲ally i) c̲at 1) r̲eshape 1.0) c̲at₂ ((t̲ally i) c̲at 1) r̲eshape v R ← f̲loat (r̲ange t̲ally W) '= t̲able i C ← f̲loat (5 6) '= t̲able r̲ange 20 M ← 0 < R '+ '× i̲nner (((t̲ally i) c̲at 2) r̲eshape 1.0) '+ '× i̲nner C (W × f̲loat n̲ot M) + R '+ '× i̲nner V '+ '× i̲nner C } ʰd̲ropHp ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 5 = r̲ange 20 } ʰa̲tk ← { W → (8) s̲elect₂ W } ʰh̲asAtk ← { W → 0 < 7 s̲elect₂ W } ʰs̲etAtk ← { W (ids, v) → i ← r̲avel ids V ← (((t̲ally i) c̲at 1) r̲eshape 1.0) c̲at₂ ((t̲ally i) c̲at 1) r̲eshape v R ← f̲loat (r̲ange t̲ally W) '= t̲able i C ← f̲loat (7 8) '= t̲able r̲ange 20 M ← 0 < R '+ '× i̲nner (((t̲ally i) c̲at 2) r̲eshape 1.0) '+ '× i̲nner C (W × f̲loat n̲ot M) + R '+ '× i̲nner V '+ '× i̲nner C } ʰd̲ropAtk ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 7 = r̲ange 20 } ʰk̲ind ← { W → (10) s̲elect₂ W } ʰh̲asKind ← { W → 0 < 9 s̲elect₂ W } ʰs̲etKind ← { W (ids, v) → i ← r̲avel ids V ← (((t̲ally i) c̲at 1) r̲eshape 1.0) c̲at₂ ((t̲ally i) c̲at 1) r̲eshape v R ← f̲loat (r̲ange t̲ally W) '= t̲able i C ← f̲loat (9 10) '= t̲able r̲ange 20 M ← 0 < R '+ '× i̲nner (((t̲ally i) c̲at 2) r̲eshape 1.0) '+ '× i̲nner C (W × f̲loat n̲ot M) + R '+ '× i̲nner V '+ '× i̲nner C } ʰd̲ropKind ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 9 = r̲ange 20 } ʰc̲hase ← { W → (12) s̲elect₂ W } ʰh̲asChase ← { W → 0 < 11 s̲elect₂ W } ʰs̲etChase ← { W (ids, v) → i ← r̲avel ids V ← (((t̲ally i) c̲at 1) r̲eshape 1.0) c̲at₂ ((t̲ally i) c̲at 1) r̲eshape v R ← f̲loat (r̲ange t̲ally W) '= t̲able i C ← f̲loat (11 12) '= t̲able r̲ange 20 M ← 0 < R '+ '× i̲nner (((t̲ally i) c̲at 2) r̲eshape 1.0) '+ '× i̲nner C (W × f̲loat n̲ot M) + R '+ '× i̲nner V '+ '× i̲nner C } ʰd̲ropChase ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 11 = r̲ange 20 } ʰh̲eal ← { W → (14) s̲elect₂ W } ʰh̲asHeal ← { W → 0 < 13 s̲elect₂ W } ʰs̲etHeal ← { W (ids, v) → i ← r̲avel ids V ← (((t̲ally i) c̲at 1) r̲eshape 1.0) c̲at₂ ((t̲ally i) c̲at 1) r̲eshape v R ← f̲loat (r̲ange t̲ally W) '= t̲able i C ← f̲loat (13 14) '= t̲able r̲ange 20 M ← 0 < R '+ '× i̲nner (((t̲ally i) c̲at 2) r̲eshape 1.0) '+ '× i̲nner C (W × f̲loat n̲ot M) + R '+ '× i̲nner V '+ '× i̲nner C } ʰd̲ropHeal ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 13 = r̲ange 20 } ʰg̲old ← { W → (16) s̲elect₂ W } ʰh̲asGold ← { W → 0 < 15 s̲elect₂ W } ʰs̲etGold ← { W (ids, v) → i ← r̲avel ids V ← (((t̲ally i) c̲at 1) r̲eshape 1.0) c̲at₂ ((t̲ally i) c̲at 1) r̲eshape v R ← f̲loat (r̲ange t̲ally W) '= t̲able i C ← f̲loat (15 16) '= t̲able r̲ange 20 M ← 0 < R '+ '× i̲nner (((t̲ally i) c̲at 2) r̲eshape 1.0) '+ '× i̲nner C (W × f̲loat n̲ot M) + R '+ '× i̲nner V '+ '× i̲nner C } ʰd̲ropGold ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 15 = r̲ange 20 } ʰp̲layer ← { W → (18) s̲elect₂ W } ʰh̲asPlayer ← { W → 0 < 17 s̲elect₂ W } ʰs̲etPlayer ← { W (ids, v) → i ← r̲avel ids V ← (((t̲ally i) c̲at 1) r̲eshape 1.0) c̲at₂ ((t̲ally i) c̲at 1) r̲eshape v R ← f̲loat (r̲ange t̲ally W) '= t̲able i C ← f̲loat (17 18) '= t̲able r̲ange 20 M ← 0 < R '+ '× i̲nner (((t̲ally i) c̲at 2) r̲eshape 1.0) '+ '× i̲nner C (W × f̲loat n̲ot M) + R '+ '× i̲nner V '+ '× i̲nner C } ʰd̲ropPlayer ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 17 = r̲ange 20 } ʰg̲oal ← { W → (20) s̲elect₂ W } ʰh̲asGoal ← { W → 0 < 19 s̲elect₂ W } ʰs̲etGoal ← { W (ids, v) → i ← r̲avel ids V ← (((t̲ally i) c̲at 1) r̲eshape 1.0) c̲at₂ ((t̲ally i) c̲at 1) r̲eshape v R ← f̲loat (r̲ange t̲ally W) '= t̲able i C ← f̲loat (19 20) '= t̲able r̲ange 20 M ← 0 < R '+ '× i̲nner (((t̲ally i) c̲at 2) r̲eshape 1.0) '+ '× i̲nner C (W × f̲loat n̲ot M) + R '+ '× i̲nner V '+ '× i̲nner C } ʰd̲ropGoal ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 19 = r̲ange 20 }
f̲ormat< expands to
("You pick up " c̲at (f̲ormat (f̲loor heal)) c̲at " hp and " c̲at (f̲ormat (f̲loor gold)) c̲at " gold. ")
f̲ormat< expands to
("<rect x=\"" c̲at (f̲ormat (ˢᵛw̲hole x)) c̲at "\" y=\"" c̲at (f̲ormat (ˢᵛw̲hole y)) c̲at "\" width=\"100\" height=\"100\" fill=\"" c̲at (f̲ormat (ʰf̲ill c)) c̲at "\" stroke=\"#000000\" stroke-width=\"2\"/>")
f̲ormat< expands to
("<rect x=\"" c̲at (f̲ormat (ˢᵛw̲hole x)) c̲at "\" y=\"" c̲at (f̲ormat (ˢᵛw̲hole y + 100)) c̲at "\" width=\"100\" height=\"100\" fill=\"#2a9d8f\"/><text class=\"entity\" x=\"" c̲at (f̲ormat (ˢᵛw̲hole x + 50)) c̲at "\" y=\"" c̲at (f̲ormat (ˢᵛw̲hole y + 180)) c̲at "\" font-size=\"84\" text-anchor=\"middle\" font-family=\"monospace\" font-weight=\"bold\" fill=\"#ffffff\">></text>")
f̲ormat< expands to
"<text class=\"entity\" x=\"" c̲at (f̲ormat (ˢᵛw̲hole x + 50)) c̲at "\" y=\"" c̲at (f̲ormat (ˢᵛw̲hole y + 180)) c̲at "\" font-size=\"84\" text-anchor=\"middle\" font-family=\"monospace\" font-weight=\"bold\" fill=\"" c̲at (f̲ormat (ʰc̲olor k)) c̲at "\">" c̲at (f̲ormat (ʰg̲lyph k)) c̲at "</text>"
f̲ormat< expands to
("HP " c̲at (f̲ormat (f̲irst y)) c̲at " Gold " c̲at (f̲ormat (2 s̲elect y)) c̲at " Turn " c̲at (f̲ormat (3 s̲elect y)) c̲at " " c̲at (f̲ormat (m)))