sourcegames/stargazer/stargazer.xtl

1⍝!/usr/bin/env xetal 2⍝# Stargazer, scripted (seed 1), with the rules and the drawing of 3⍝# Sky.xtl: the named stars and the sky read from TOML, bands of 4⍝# brightness, the sky drawn as SVG, and a round played by clicks. 5ᵏ⁼u̲se< "Sky" 6 7⍝ The parts of the sky, and how many named stars each holds (0 is all). 8ᵏp̲arts @ 9'{ a → t̲ally ᵏp̲ool a } e̲ach 0 1 2 3 4 5 6 10 11⍝ Sirius: its point on the sky (sky units: hundredths of a degree, right 12⍝ ascension growing to the left) and its choices: Sirius and one star 13⍝ from each brightness band, picked by the round's number (here 7). 14i ← f̲irst w̲here '{ j → "Sirius" m̲atch ᵏn̲ame j } e̲ach ᵏp̲ool 0 15f̲loor 0 ᵏa̲t i 16'{ j → e̲nclose ᵏn̲ame j } e̲ach 7 ᵏc̲hoices i 17 18⍝ A round in the winter sky (seed 1): five named stars, mixed bright, 19⍝ middling and faint, and the picture X_eTaL draws for it. 20s ← ᵏn̲ew 1 21'{ j → e̲nclose ᵏn̲ame j } e̲ach ᵏm̲arks s 22pic ← ⎕S̲HOW ᵏd̲raw s 23 24⍝ A click on the first ringed star opens its menu; a click on the right 25⍝ name (the middle of its button) answers it. 26j ← f̲irst ᵏm̲arks s 27t ← s ᵏc̲lick 1 ᵏa̲t j 28ᵏs̲ay t 29c ← f̲irst w̲here (ᵏo̲ffered t) = j 30b ← c s̲elect ᵏm̲enu t 31t ← t ᵏc̲lick ((f̲irst b) + 0.5 × 3 s̲elect b) c̲at (2 s̲elect b) + 0.5 × 4 s̲elect b 32ᵏs̲ay t 33pic ← ⎕S̲HOW ᵏd̲raw t 34ᵏs̲core t 35 36⍝ What the game guarantees, checked by a_ssert< (the condition as 37⍝ written; silent when it holds, a line on standard error, which fails 38⍝ the tests, when it does not). 39ok ← "i m_ember? 7 k:c_hoices i" a̲ssert< "a star is among its own choices"
a̲ssert< expands to
({ @ → (i m̲ember? 7 ᵏc̲hoices i) ? @◆ ⎕E̲RR "assertion failed: i m_ember? 7 k:c_hoices i (a star is among its own choices) [games/stargazer/stargazer.xtl:39]"◆ @ } @)
40ok ← "4 = t_ally u_nique 7 k:c_hoices i" a̲ssert< "four different stars to choose from"
a̲ssert< expands to
({ @ → (4 = t̲ally u̲nique 7 ᵏc̲hoices i) ? @◆ ⎕E̲RR "assertion failed: 4 = t_ally u_nique 7 k:c_hoices i (four different stars to choose from) [games/stargazer/stargazer.xtl:40]"◆ @ } @)