sourcegames/capitals/capitals.xtl

1⍝!/usr/bin/env xetal 2⍝# Capitals, scripted (seed 1), with the rules and the drawing of 3⍝# Atlas.xtl: the places read from TOML, every distance at once, the 4⍝# map drawn as SVG, and a round played by clicks given as points. 5ᵃ⁼u̲se< "Atlas" 6 7⍝ The places: Natural Earth's national capitals, then any of your own 8⍝ from places.toml; how many in each region (0 is all of them). 9ᵃr̲egions @ 10'{ r → t̲ally ᵃp̲ool r } e̲ach 0 1 2 3 4 5 11 12⍝ Paris: its point on the map (map units: hundredths of a degree east 13⍝ of 180 W and south of the pole), and its four choices, the nearest 14⍝ cities with different names, west to east (the nearest is Paris). 15p ← f̲irst w̲here '{ i → "Paris, France" m̲atch ᵃn̲ame i } e̲ach ᵃp̲ool 0 16ᵃn̲ame p 17f̲loor ᵃa̲t p 18'{ k → e̲nclose ᵃt̲own k } e̲ach ᵃc̲hoices p 19 20⍝ What the map shows for Europe: x, y, width and height, around its 21⍝ capitals. 22f̲loor ᵃv̲iew 4 23 24⍝ A round in Europe (seed 1): five capitals drawn at random, and the 25⍝ picture X_eTaL draws for it. 26s ← ᵃn̲ew 4 27'{ i → e̲nclose ᵃn̲ame i } e̲ach ᵃd̲ots s 28pic ← ⎕S̲HOW ᵃd̲raw s 29 30⍝ A click on the first dot opens its menu; a click on the right name 31⍝ (the middle of its button) answers it. 32i ← f̲irst ᵃd̲ots s 33t ← s ᵃc̲lick ᵃa̲t i 34ᵃs̲ay t 35k ← f̲irst w̲here (ᵃc̲hoices i) = ᵃa̲nswer i 36b ← k s̲elect ᵃm̲enu t 37t ← t ᵃc̲lick ((f̲irst b) + 0.5 × 3 s̲elect b) c̲at (2 s̲elect b) + 0.5 × 4 s̲elect b 38ᵃs̲ay t 39pic ← ⎕S̲HOW ᵃd̲raw t 40ᵃs̲core t 41 42⍝ What the game guarantees, checked by a_ssert< (the condition as 43⍝ written; silent when it holds, a line on standard error, which fails 44⍝ the tests, when it does not). 45ok ← "\"Paris\" m_atch a:t_own a:a_nswer p" a̲ssert< "the nearest city to a capital is the capital"
a̲ssert< expands to
({ @ → ("Paris" m̲atch ᵃt̲own ᵃa̲nswer p) ? @◆ ⎕E̲RR "assertion failed: \"Paris\" m_atch a:t_own a:a_nswer p (the nearest city to a capital is the capital) [games/capitals/capitals.xtl:45]"◆ @ } @)
46ok ← "(a:a_nswer p) m_ember? a:c_hoices p" a̲ssert< "the answer is among the choices"
a̲ssert< expands to
({ @ → ((ᵃa̲nswer p) m̲ember? ᵃc̲hoices p) ? @◆ ⎕E̲RR "assertion failed: (a:a_nswer p) m_ember? a:c_hoices p (the answer is among the choices) [games/capitals/capitals.xtl:46]"◆ @ } @)