The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Relay — Game Master</title><link rel="icon" href="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22256%22%20height%3D%22256%22%20viewBox%3D%220%200%2096%2096%22%3E%0A%20%20%3Ctitle%3EGame%20Master%20%E2%80%94%20opposing%20teams%2C%20one%20relay%3C%2Ftitle%3E%0A%20%20%3Crect%20x%3D%224%22%20y%3D%224%22%20width%3D%2288%22%20height%3D%2288%22%20rx%3D%2223%22%20fill%3D%22%231d2d37%22%2F%3E%0A%20%20%3Cpath%20d%3D%22m19%2031%2013-13%2024%2024-13%2013Z%22%20fill%3D%22%23ed9075%22%2F%3E%0A%20%20%3Cpath%20d%3D%22m40%2054%2013-13%2024%2024-13%2013Z%22%20fill%3D%22%2381c8c4%22%2F%3E%0A%20%20%3Cpath%20d%3D%22m48%2036%2012%2012-12%2012-12-12Z%22%20fill%3D%22%231d2d37%22%20stroke%3D%22%23eed5a0%22%20stroke-width%3D%224%22%2F%3E%0A%20%20%3Ccircle%20cx%3D%2224%22%20cy%3D%2270%22%20r%3D%225%22%20fill%3D%22%23ed9075%22%2F%3E%0A%20%20%3Ccircle%20cx%3D%2272%22%20cy%3D%2226%22%20r%3D%225%22%20fill%3D%22%2381c8c4%22%2F%3E%0A%3C%2Fsvg%3E%0A"><style>:root{font-family:Inter,ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;color:#213c34;background:#f3f0e7;font-synthesis:none}*{box-sizing:border-box}body{margin:0}button,input,textarea,select{font:inherit}button{border:1px solid #c3cbbf;border-radius:7px;padding:9px 12px;background:#fffcf5;color:inherit;cursor:pointer;font-size:12px;font-weight:600}button:hover{background:#e7eddf}button:disabled{opacity:.45;cursor:default}button.primary{background:#284d3d;border-color:#284d3d;color:#fff8e9}input,textarea,select{max-width:100%;border:1px solid #c7cec1;border-radius:5px;padding:8px;background:#fffdf7;color:inherit}input[type=number]{width:85px}textarea{width:100%;resize:vertical}label{font-size:12px;display:block}label>input,label>textarea,label>select{display:block;width:100%;margin-top:5px}h1,h2,h3,p{margin-top:0}h1{font-family:Georgia,serif;font-weight:400;font-size:42px;letter-spacing:-1px;margin-bottom:10px}h2{font-size:20px}h3{font-size:16px}p{line-height:1.55}small,.muted{color:#69776b}.eyebrow{font-size:10px;letter-spacing:1.5px;font-weight:700;color:#718169;margin-bottom:15px}.row{display:flex;gap:7px;align-items:end;flex-wrap:wrap}[hidden]{display:none!important}.top{display:flex;align-items:center;justify-content:space-between;gap:20px;padding:18px 28px;border-bottom:1px solid #cdd3c4;background:#faf7ef}.brand{display:flex;gap:10px;align-items:center;font-size:20px;letter-spacing:3px;font-weight:800}.brand small{display:block;font-size:8px;letter-spacing:1.7px;margin-top:4px}.logo{display:block;width:35px}.logo svg{width:35px;height:35px}.top nav,.top-actions{display:flex;gap:5px}.top nav button{border-color:transparent;background:none;color:#73806e}.top nav button.active{color:#284d3d;border-bottom-color:#284d3d;border-radius:0}.workspace{display:grid;grid-template-columns:235px minmax(400px,1fr) 255px;min-height:calc(100vh - 78px)}.library,.inspector{padding:27px 20px;border-right:1px solid #d1d6c9;min-width:0}.inspector{border-right:0;border-left:1px solid #d1d6c9}.library h2{font-family:Georgia,serif;font-size:23px;font-weight:400}.library p{font-size:12px}.library .row{margin-bottom:22px}.component-row{width:100%;display:flex;align-items:center;gap:10px;text-align:left;padding:10px 8px;margin:6px 0;background:none;border-color:transparent}.component-row.active{background:#e1e8d9;border-color:#b4c2a7}.component-row .swatch{width:26px;height:35px;border-radius:3px;display:grid;place-content:center;flex-shrink:0}.component-row small{display:block;font-size:10px;margin-top:4px}.rule-settings{border-top:1px solid #cdd3c4;margin-top:24px;padding-top:20px}.rule-settings label{margin:12px 0}.rule-settings input{width:100%}.table-area{padding:28px;min-width:0}.game-heading{display:flex;gap:20px;justify-content:space-between}.game-heading p{font-size:13px;max-width:440px;color:#6d7b6b}.edition{font-size:10px;flex-shrink:0;text-align:right;color:#6d7b6b}.edition .row{margin-top:12px;justify-content:end}.edition button{padding:6px;font-size:10px}.play-toolbar{display:flex;gap:7px;align-items:end;flex-wrap:wrap;margin:17px 0}.play-toolbar input{width:145px;font-size:12px}.play-toolbar label{font-size:10px}.tabletop{position:relative;border-radius:16px;background:#e3e9d9;border:1px solid #c6d1ba;padding:25px;min-height:445px;overflow:hidden;box-shadow:0 12px 30px #344f3210}.turn-heading{display:flex;justify-content:space-between;gap:10px;margin:22px 0}.turn-heading h2{font-family:Georgia,serif;font-weight:400;font-size:25px;margin:0 0 8px}.turn-heading p{font-size:12px;max-width:510px;margin:0}.turn-heading span{font-size:10px;white-space:nowrap}#scores{display:flex;gap:10px;flex-wrap:wrap}#scores>div{background:#f4f6eb;border:1px solid #ccd5bf;padding:9px 15px;border-radius:8px;min-width:110px;font-size:10px;color:#5d6e58}#scores strong{font-size:22px;display:block;color:#28452e;margin-top:5px}.zone{border-top:1px solid #c4ceb7;padding-top:15px;margin-top:20px}.zone h3{font-size:11px;text-transform:uppercase;letter-spacing:1px;color:#65735c;margin:0 0 13px}.cards{display:flex;flex-wrap:wrap;gap:10px;min-height:35px}.game-piece{border:0;padding:0;background:transparent;position:relative;border-radius:7px;transition:transform .15s;box-shadow:0 3px 5px #1b3b3019;width:98px;max-width:100%}.game-piece svg{display:block;width:100%;height:auto;border-radius:5px}.game-piece[data-move]:hover{transform:translateY(-6px);background:transparent;box-shadow:0 6px 9px #1b3b3030}.badge{position:absolute;bottom:2px;right:2px;background:#fff8e6;color:#213c34;padding:2px 4px;font-size:10px;border-radius:3px}.board{display:grid;gap:4px;max-width:410px;padding:8px;background:#d8ddcb;border:1px solid #9ba98e;border-radius:7px}.board-cell{min-width:0;aspect-ratio:1;display:flex;flex-direction:column;align-items:center;justify-content:center;position:relative;border:1px solid #c3cbbb;border-radius:4px}.board-cell>small{font-size:9px;position:absolute;top:3px;left:4px}.board .game-piece{width:85%;box-shadow:none}.board .game-piece svg{border-radius:0}.rotation{position:relative}.rotation .turn-arrow{font-size:11px;display:block}#actions{display:flex;gap:6px;flex-wrap:wrap;margin-top:22px}#actions button{background:#fff8e9;font-size:11px}#curtain{position:absolute;inset:0;background:#244b3e;z-index:5;color:#fff7e6;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;padding:30px}#curtain h2{font:32px Georgia,serif}#curtain p{max-width:330px;font-size:13px}#curtain .eyebrow{color:#b2c6a3}#curtain .primary{background:#dce7c7;color:#244b3e}#curtain small{margin-top:28px;color:#b4c4ad;max-width:350px;font-size:10px}.playtesting{margin-top:27px;border-top:1px solid #cdd3c4;padding-top:24px}.playtesting .eyebrow{margin-bottom:8px}.playtesting h3{margin:0 0 6px}.playtesting p{font-size:12px;margin:0 0 12px}.playtesting label{font-size:10px}.playtesting .row{align-items:end}.playtesting select{font-size:12px}.simulation-stats{display:flex;gap:18px;flex-wrap:wrap;padding:15px 0;font-size:12px}.simulation-stats strong{display:block;font-size:21px}.inspector #component-preview{max-width:140px;margin:20px auto 24px}.inspector svg{width:100%;height:auto;filter:drop-shadow(0 8px 8px #263d2a30)}#component-form label{margin:13px 0}#component-form .row>label{flex:1}#component-form input{width:100%}#component-form textarea{font-size:12px;line-height:1.5}.danger{color:#9b4d40}.document-view{max-width:1050px;padding:48px 35px;margin:0 auto}.document-view textarea{margin:6px 0 18px;line-height:1.6}.rule-section{border-bottom:1px solid #cdd3c4;margin-bottom:25px;padding-bottom:10px}.lead{font-family:Georgia,serif;font-size:21px}.delivery-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:20px;margin:35px 0}.delivery-grid article{background:#fffcf4;border:1px solid #c8d1bd;border-radius:10px;padding:24px}.delivery-grid article>span{font-size:10px;letter-spacing:1px;color:#6b7d5d}.delivery-grid h2{font:26px Georgia,serif;margin:20px 0 12px}.delivery-grid p{font-size:13px}.delivery-grid button{margin:4px 0}#print-preview{display:flex;gap:15px;overflow:auto;margin-bottom:25px;padding-bottom:20px}#print-preview svg{width:210px;height:297px;flex-shrink:0;border:1px solid #d1d6c9;background:white}#notice{position:fixed;bottom:22px;left:50%;transform:translateX(-50%);max-width:90vw;background:#244b3e;color:white;padding:13px 22px;font-size:13px;border-radius:10px;z-index:50;box-shadow:0 6px 30px #0003}#notice.error{background:#913f32}.source-notice,#edition-notice{background:#f5deb0;padding:13px 20px;display:flex;align-items:center;gap:10px;flex-wrap:wrap;font-size:12px}#edition-notice{margin-bottom:12px;border-radius:8px}dialog{width:min(820px,92vw);max-height:85vh;overflow:auto;background:#faf7ed;border:1px solid #b7c3ac;border-radius:15px;padding:30px;color:#213c34}dialog::backdrop{background:#142c2490}.close{float:right;border:0;background:none;font-size:24px;padding:0}dialog h2{font:28px Georgia,serif}dialog label{margin:15px 0}dialog textarea.code{font-family:ui-monospace,monospace;font-size:12px;white-space:pre;min-height:360px}dialog p{font-size:12px}#editor-apply{margin-top:15px}
@media(min-width:1550px){.workspace{grid-template-columns:255px minmax(450px,1fr) 295px}.table-area{padding:38px}.tabletop{padding:30px}.game-piece{width:113px}}
@media(max-width:1180px){.workspace{grid-template-columns:205px minmax(340px,1fr)}.inspector{grid-column:1/-1;border-top:1px solid #cdd3c4;display:grid;grid-template-columns:180px 1fr;gap:20px}.inspector .eyebrow{grid-column:1/-1}.inspector #component-preview{margin:0 auto}#component-form{display:grid;grid-template-columns:1fr 1fr;gap:0 20px}.top{flex-wrap:wrap}.game-heading{display:block}.edition{text-align:left}.edition .row{justify-content:start}.table-area{padding:23px}}
@media(max-width:720px){.top{padding:15px;gap:15px;display:grid;grid-template-columns:1fr}.top nav{order:3;overflow:auto}.top-actions{flex-wrap:wrap}.workspace{display:block}.library{padding:20px;border-right:0;border-bottom:1px solid #cdd3c4}.library .muted,.library>h2{display:none}#component-list{display:flex;overflow:auto;gap:5px}.component-row{width:145px;flex-shrink:0}.rule-settings{margin-top:15px}.rule-settings #settings{display:flex;gap:12px;flex-wrap:wrap}.rule-settings label{max-width:140px}.table-area{padding:22px 15px}h1{font-size:35px}.tabletop{padding:18px;min-height:430px}.game-piece{width:85px}.inspector{display:block;padding:22px}.inspector #component-preview{max-width:140px;margin-bottom:20px}#component-form{display:block}.document-view{padding:30px 18px}.delivery-grid{grid-template-columns:1fr}.play-toolbar button{font-size:10px}.turn-heading{flex-wrap:wrap}#curtain h2{font-size:27px}.cards{gap:8px}.board{max-width:100%}}
.game-piece:disabled{opacity:1;cursor:default}
.table-piece{width:125px;min-width:0}.table-piece .game-piece{width:100%}.piece-label{font-size:12px;line-height:1.35;display:block;margin-top:8px;font-weight:600}.piece-label small{font-weight:400;font-size:11px;display:block;margin-top:4px}.table-piece details{font-size:11px;margin-top:5px}.table-piece details p{background:#f6f7ef;border-radius:5px;padding:8px;margin-top:6px}.table-piece summary{cursor:pointer;color:#5c7252}.board .table-piece{width:88%}.board .game-piece{width:100%}@media(max-width:720px){.table-piece{width:95px}.piece-label{font-size:11px}.piece-label small{font-size:10px}}
</style></head><body>
<header class="top"><div class="brand"><span class="logo"><svg xmlns="http://www.w3.org/2000/svg" width="256" height="256" viewBox="0 0 96 96">
<title>Game Master — opposing teams, one relay</title>
<rect x="4" y="4" width="88" height="88" rx="23" fill="#1d2d37"/>
<path d="m19 31 13-13 24 24-13 13Z" fill="#ed9075"/>
<path d="m40 54 13-13 24 24-13 13Z" fill="#81c8c4"/>
<path d="m48 36 12 12-12 12-12-12Z" fill="#1d2d37" stroke="#eed5a0" stroke-width="4"/>
<circle cx="24" cy="70" r="5" fill="#ed9075"/>
<circle cx="72" cy="26" r="5" fill="#81c8c4"/>
</svg>
</span><span>RELAY<small>GAME WORKSHOP</small></span></div><nav aria-label="Workspace"><button data-tab="workbench" class="active">Workbench</button><button data-tab="rules">Rulebook</button><button data-tab="print">Print & keep</button></nav><div class="top-actions"><button id="open-project">Open game</button><button id="save-source">Save source</button><button class="primary" id="export-kit">Export kit ↗</button></div></header>
<div id="notice" role="status" hidden></div><div id="source-notice" class="source-notice" hidden><span>The source changed while this edition was open.</span><button id="keep-draft">Download my draft</button><button id="load-source">Keep both & load source</button></div>
<main id="workbench" class="workspace"><aside class="library"><div class="eyebrow">YOUR GAME / COMPONENTS</div><h2 id="library-title"></h2><p class="muted">Edit the things people hold.</p><div class="row"><button id="add-component">+ Component</button><button id="edit-metadata">Game details</button></div><div id="component-list"></div><div class="rule-settings"><h3>Rule settings</h3><div id="settings"></div><button id="edit-rules">Edit rules module</button></div></aside>
<section class="table-area"><div class="game-heading"><div><div class="eyebrow">PLAY YOUR CREATION</div><h1 id="game-title"></h1><p id="game-subtitle"></p></div><div class="edition"><span id="source-state">Opening…</span><div class="row"><button id="undo-edit">Undo edit</button><button id="redo-edit">Redo</button></div></div></div><div class="play-toolbar"><label>Seed <input id="seed" value="first-game" maxlength="128"></label><button id="restart">Restart</button><button id="undo-turn">Undo turn</button><button id="save-replay">Save replay</button><button id="open-replay">Open replay</button></div><div id="edition-notice" hidden><span>The table is playing the previous edition.</span><button id="apply-edition">Keep playtest & apply edits</button></div><div class="tabletop"><div id="scores"></div><div class="turn-heading"><div><h2 id="turn-title"></h2><p id="turn-message"></p></div><span id="turn-count"></span></div><div id="zones"></div><div id="actions" aria-label="Legal moves"></div><div id="curtain" hidden><div class="eyebrow">PASS THE TABLE</div><h2 id="curtain-title"></h2><p>Hand the screen to the next player before revealing their view.</p><button class="primary" id="reveal">I’m ready · reveal my turn</button><small>This curtain conceals casual views. Source files and replays contain the game.</small></div></div><section class="playtesting"><div><div class="eyebrow">CHECK THE RULES</div><h3>What happens over many games?</h3><p>Find dead ends and compare outcomes under a named policy.</p></div><div class="row"><label>Games<input id="simulation-count" type="number" min="1" max="200" value="50"></label><label>Policy<select id="policy"><option value="uniform">Uniform legal choices</option><option value="authored">Authored policy</option></select></label><button id="simulate">Run playtest</button></div><div id="simulation-report"></div></section></section>
<aside class="inspector"><div class="eyebrow">COMPONENT STUDIO</div><div id="component-preview"></div><form id="component-form"></form></aside></main>
<main id="rules" class="document-view" hidden><div class="eyebrow">THE GAME PEOPLE WILL PLAY</div><h1>Write the rulebook</h1><p class="muted">Explain setup, each decision, scoring and the end of the game. Keep these words in step with your rules module.</p><div id="rulebook-editor"></div><button id="add-section">+ Section</button><button id="print-rules">Open printable rulebook</button></main>
<main id="print" class="document-view" hidden><div class="eyebrow">FROM SCREEN TO TABLE</div><h1>Keep the whole game.</h1><p class="lead">A playable file, editable source, and the things you can print and hold.</p><div class="delivery-grid"><article><span>01 / PLAY</span><h2>Offline game</h2><p>Open it in a browser. Play, edit components and save your edition.</p><button id="export-html">Download game HTML</button><button id="export-project">Download project</button></article><article><span>02 / MAKE</span><h2>Print & play</h2><p>A4 component sheets at physical size, separate SVGs and board sheets. Print at 100% and check the calibration line.</p><button id="print-components">Open component sheets</button><button id="print-rulebook">Open rulebook</button></article><article><span>03 / KEEP</span><h2>Complete kit</h2><p>Game, source, rulebook, components, boards and the current playtest replay in one ZIP.</p><button id="export-kit-secondary">Download complete kit</button></article></div><div id="print-preview"></div><p class="muted">Card backs are supplied separately for gluing or opaque sleeves. No duplex alignment is assumed. Save PDF from the print dialog; command-line export also produces PDFs.</p></main>
<dialog id="editor-dialog"><form method="dialog"><button class="close" aria-label="Close editor">×</button></form><h2 id="editor-title"></h2><div id="editor-content"></div><button id="editor-apply" class="primary">Apply changes</button></dialog>
<input id="face-file" type="file" accept="image/png,image/jpeg,image/webp,image/svg+xml" hidden><input id="project-file" type="file" accept=".json,.relay.json" hidden><input id="replay-file" type="file" accept=".json" hidden>
<script id="relay-data" type="application/json">{"project":{"spec":1,"id":"pocket-conservatory","title":"Pocket Conservatory","subtitle":"Grow a garden. Pass a possibility. A tiny drafting game for two.","players":2,"settings":[{"id":"rounds","label":"Cards in each starting hand","value":6,"min":3,"max":8,"step":1},{"id":"pair_bonus","label":"Flower + water pair bonus","value":4,"min":0,"max":10,"step":1},{"id":"variety_bonus","label":"Points per different plant group","value":1,"min":0,"max":5,"step":1}],"components":[{"id":"fern","name":"Silver fern","body":"A quiet beginning.","kind":"card","widthMm":63,"heightMm":88,"quantity":4,"color":"#244c40","ink":"#fff8e9","symbol":"✦","values":{"group":"leaf","points":2},"locked":false},{"id":"poppy","name":"Coral poppy","body":"Pairs with water for a flourishing garden.","kind":"card","widthMm":63,"heightMm":88,"quantity":4,"color":"#a44736","ink":"#fff8e9","symbol":"✿","values":{"group":"flower","points":2},"locked":false},{"id":"pond","name":"Rain pool","body":"Each flower + water pair earns the pair bonus.","kind":"card","widthMm":63,"heightMm":88,"quantity":4,"color":"#365e7a","ink":"#fff8e9","symbol":"≈","values":{"group":"water","points":1},"locked":false},{"id":"herb","name":"Wild thyme","body":"A little color and a different kind of leaf.","kind":"card","widthMm":63,"heightMm":88,"quantity":4,"color":"#62642f","ink":"#fff8e9","symbol":"❋","values":{"group":"herb","points":3},"locked":false},{"id":"aster","name":"Evening aster","body":"A second flower for a generous garden.","kind":"card","widthMm":63,"heightMm":88,"quantity":4,"color":"#795c79","ink":"#fff8e9","symbol":"✳","values":{"group":"flower","points":3},"locked":false},{"id":"moss","name":"Velvet moss","body":"Make room for small beginnings.","kind":"card","widthMm":63,"heightMm":88,"quantity":4,"color":"#3e6d53","ink":"#fff8e9","symbol":"⋆","values":{"group":"moss","points":1},"locked":false}],"boards":[],"rulebook":[{"heading":"A garden for two","body":"Pocket Conservatory is a two-player drafting game. Build a little garden by choosing one card at a time from a hand that you will pass to the other gardener. You need the printed deck and a way to note scores."},{"heading":"Set up","body":"Shuffle all printed cards. Deal each gardener the number of cards shown in the rule settings. Put the rest aside face down without looking. Each gardener keeps their hand private. Gardener 1 chooses first each round."},{"heading":"Plant and pass","body":"Each round, Gardener 1 chooses one card and places it face up in their garden, then Gardener 2 does the same. Neither gardener takes another card until both have planted. Swap the remaining hands. Begin the next round. When both hands are empty, the game ends."},{"heading":"Score your garden","body":"Add each planted card’s printed points. Earn the flower + water pair bonus for every pair you can make; each card counts in one pair. Add the variety bonus once per distinct group in your garden. The gardener with the highest score wins; tied scores share the win. The settings and component values printed with this rulebook define this edition."},{"heading":"At the same screen","body":"The hand curtain lets gardeners pass the computer between turns. It conceals the hand from casual view; the offline file and replay are not secret from someone who can inspect the browser or source. Undo is a playtesting tool: it can reveal previous hands. For physical play, reveal only each planted card."}],"rules":"// Pocket Conservatory: original two-player simultaneous-hand drafting rules.\nconst setting=(p,id)=>p.settings.find(s=>s.id===id).value;\nconst component=(p,id)=>p.components.find(c=>c.id===id);\nexport function score(cards,p){let points=cards.reduce((n,id)=>n+component(p,id).values.points,0);const counts={};for(const id of cards){const group=component(p,id).values.group;counts[group]=(counts[group]??0)+1;}points+=Math.min(counts.water??0,counts.flower??0)*setting(p,'pair_bonus');points+=Object.keys(counts).length*setting(p,'variety_bonus');return points;}\nexport function initial(p,ctx){const rounds=setting(p,'rounds'),deck=p.components.flatMap(c=>Array(c.quantity).fill(c.id));if(deck.length\u003crounds*2)throw new Error('Print enough cards to deal both hands.');const shuffled=ctx.shuffle(deck,'deal');return{player:0,round:1,done:false,hands:[shuffled.slice(0,rounds),shuffled.slice(rounds,rounds*2)],tableaux:[[],[]],picked:[false,false]};}\nexport function legal(s,p){return s.done?[]:s.hands[s.player].map((id,i)=>({id:'draft-'+i,label:'Plant '+component(p,id).name,index:i}));}\nexport function apply(s,a,p){const n=JSON.parse(JSON.stringify(s)),who=n.player,[card]=n.hands[who].splice(a.index,1);n.tableaux[who].push(card);n.picked[who]=true;if(n.picked.every(Boolean)){if(!n.hands[0].length)n.done=true;else{n.hands.reverse();n.round++;n.picked=[false,false];}n.player=0;}else n.player=1;return n;}\nexport function observe(s,player,p){return{title:'Round '+s.round+' · Gardener '+(player+1),message:s.done?'Compare your planted gardens.':'Choose one plant, then pass the remaining hand after both gardeners choose.',private:!s.done,scores:s.tableaux.map((cards,i)=>({label:'Gardener '+(i+1),value:score(cards,p)})),zones:[...(!s.done?[{id:'hand',label:'Your hand · choose a plant below',items:s.hands[player].map((id,i)=>({key:'hand-'+i,component:id,action:'draft-'+i}))}]:[]),...s.tableaux.map((cards,i)=>({id:'garden-'+i,label:'Gardener '+(i+1)+' · planted',items:cards.map((id,j)=>({key:i+'-'+j,component:id}))}))]};}\nexport function outcome(s,p){if(!s.done)return null;const scores=s.tableaux.map(c=>score(c,p)),high=Math.max(...scores),winners=scores.flatMap((n,i)=>n===high?[i]:[]);return{title:winners.length===2?'Both gardens flourish':'Gardener '+(winners[0]+1)+' wins',winners,scores};}\nexport function validate(s,p){if(p.players!==2||!Number.isInteger(setting(p,'rounds')))return 'This game needs two players and a whole number of cards per hand.';if(!Array.isArray(s.hands)||s.hands.length!==2||!Array.isArray(s.tableaux)||s.tableaux.length!==2)return'Keep both hands and gardens.';if(s.hands.flat().length+s.tableaux.flat().length!==setting(p,'rounds')*2)return'Card conservation failed.';const counts={};for(const id of [...s.hands.flat(),...s.tableaux.flat()]){const c=component(p,id);if(!c)return'Unknown card.';counts[id]=(counts[id]??0)+1;if(counts[id]>c.quantity)return'Too many copies of a card.';}return true;}\nexport function bot(view,actions){return actions[0].id;}\n","revision":"2f4205c5e659441828f3a6a45906052be2a2846d458a5791518c3f4d7eae2961"},"worker":"(()=>{var c=n=>JSON.parse(JSON.stringify(n)),f=(n,e=160)=>typeof n==\"string\"&&n.length>0&&n.length\u003c=e,v=n=>typeof n==\"string\"&&/^[a-z][a-z0-9_-]{0,63}$/.test(n),N=n=>typeof n==\"string\"&&/^#[a-f0-9]{6}$/i.test(n),m=(n,e,s)=>Number.isFinite(n)&&n>=e&&n\u003c=s;function o(n,e){if(!n)throw new Error(e)}function U(n){o(n&&JSON.stringify(n).length\u003c=3e6,\"Keep the project below 3 MB.\");let e=c(n);o(e.spec===1&&v(e.id)&&f(e.title)&&f(e.subtitle,400),\"Use a version 1 Relay project with an id, title and subtitle.\"),o(Number.isInteger(e.players)&&e.players>=1&&e.players\u003c=6,\"Choose 1\\u20136 players.\"),o(f(e.rules,2e5),\"Include the complete rules module.\"),o(Array.isArray(e.rulebook)&&e.rulebook.length>=1&&e.rulebook.length\u003c=40,\"Include 1\\u201340 rulebook sections.\");for(let t of e.rulebook)o(f(t.heading)&&f(t.body,1e4),\"Rulebook sections need a heading and body.\");o(Array.isArray(e.components)&&e.components.length>0&&e.components.length\u003c=160,\"Create 1\\u2013160 component designs.\");let s=new Set,r=0;for(let t of e.components){o(v(t.id)&&!s.has(t.id),\"Component ids must be unique.\"),s.add(t.id),o(f(t.name,80)&&typeof t.body==\"string\"&&t.body.length\u003c=700,\"Use short, readable component names and text.\"),o([\"card\",\"token\",\"tile\"].includes(t.kind),\"Component kind must be card, token or tile.\"),o(m(t.widthMm,12,190)&&m(t.heightMm,12,273),\"Component dimensions must fit A4 within 10 mm margins.\"),o(Number.isInteger(t.quantity)&&t.quantity>=1&&t.quantity\u003c=100,\"Component quantity must be 1\\u2013100.\"),r+=t.quantity,o(N(t.color)&&N(t.ink),\"Use six-digit hex colors.\"),o(typeof t.symbol==\"string\"&&t.symbol.length\u003c=8,\"Use a short symbol.\"),t.face!==void 0&&o(typeof t.face==\"string\"&&t.face.length\u003c=7e5&&/^data:image\\/(png|jpeg|webp|svg\\+xml);base64,[A-Za-z0-9+/=]+$/.test(t.face),\"Use an embedded PNG, JPEG, WebP or SVG face below 700 KB.\"),o(t.values&&typeof t.values==\"object\"&&!Array.isArray(t.values),\"Component values must be an object.\");for(let[u,a]of Object.entries(t.values))o(v(u)&&(typeof a==\"number\"&&Number.isFinite(a)||typeof a==\"boolean\"||typeof a==\"string\"&&a.length\u003c160),\"Values must be finite numbers, short text or booleans.\");o(Object.keys(t.values).length\u003c=20,\"Keep at most 20 values per component.\")}o(r\u003c=600,\"Keep the kit within 600 physical components.\"),o(Array.isArray(e.settings)&&e.settings.length\u003c=30,\"Keep at most 30 rule settings.\");let i=new Set;for(let t of e.settings)o(v(t.id)&&!i.has(t.id)&&f(t.label),\"Settings need unique ids and labels.\"),i.add(t.id),o(m(t.min,-1e4,1e4)&&m(t.max,t.min,1e4)&&m(t.value,t.min,t.max)&&m(t.step,.001,1e3),\"Setting values must lie inside their declared bounds.\");o(Array.isArray(e.boards)&&e.boards.length\u003c=8,\"Keep at most eight board sheets.\");let l=new Set;for(let t of e.boards){o(v(t.id)&&!l.has(t.id)&&f(t.name),\"Boards need unique ids and names.\"),l.add(t.id),o(m(t.widthMm,30,277)&&m(t.heightMm,30,190),\"Boards must fit landscape A4 within 10 mm margins.\"),o(Number.isInteger(t.cols)&&t.cols>0&&t.cols\u003c=20&&Number.isInteger(t.rows)&&t.rows>0&&t.rows\u003c=20,\"Boards support 1\\u201320 rows and columns.\"),o(Array.isArray(t.cells)&&t.cells.length===t.cols*t.rows,\"Define every board cell.\");for(let u of t.cells)o(typeof u.label==\"string\"&&u.label.length\u003c=30&&N(u.color),\"Board cells need a short label and hex color.\")}return delete e.revision,e}function R(n){let e=c(n);return delete e.rules,delete e.revision,e}function g(n){return n===null||typeof n!=\"object\"?JSON.stringify(n):Array.isArray(n)?\"[\"+n.map(g).join(\",\")+\"]\":\"{\"+Object.keys(n).sort().map(e=>JSON.stringify(e)+\":\"+g(n[e])).join(\",\")+\"}\"}async function q(n){let e=new TextEncoder().encode(typeof n==\"string\"?n:g(n));return[...new Uint8Array(await crypto.subtle.digest(\"SHA-256\",e))].map(s=>s.toString(16).padStart(2,\"0\")).join(\"\")}function y(n){return n&&typeof n==\"object\"&&(Object.values(n).forEach(y),Object.freeze(n)),n}function S(n,e){let s=new Set;function r(i){typeof i==\"number\"?o(Number.isFinite(i),e+\" has a non-finite number.\"):i&&typeof i==\"object\"?(o(!s.has(i),e+\" contains a cycle.\"),s.add(i),o(Array.isArray(i)||Object.getPrototypeOf(i)===Object.prototype,e+\" must be plain JSON.\"),Object.values(i).forEach(r),s.delete(i)):o(i===null||[\"string\",\"boolean\"].includes(typeof i),e+\" must be plain JSON.\")}return r(n),o(JSON.stringify(n).length\u003c1e6,e+\" exceeds 1 MB.\"),n}function k(n){let e=2166136261;for(let s of String(n))e^=s.codePointAt(0),e=Math.imul(e,16777619);return()=>{e+=1831565813;let s=e;return s=Math.imul(s^s>>>15,s|1),s^=s+Math.imul(s^s>>>7,s|61),((s^s>>>14)>>>0)/4294967296}}function x(n,e){return Object.freeze({random:s=>k(n+\"|\"+e+\"|\"+String(s)),shuffle:(s,r)=>{let i=c(s),l=k(n+\"|\"+e+\"|\"+r);for(let t=i.length-1;t>0;t--){let u=Math.floor(l()*(t+1));[i[t],i[u]]=[i[u],i[t]]}return i}})}var b=class{constructor(e,s,r=\"first-game\"){for(let l of[\"initial\",\"legal\",\"apply\",\"observe\",\"outcome\",\"validate\"])o(typeof s[l]==\"function\",\"Rules must export \"+l+\"().\");o(typeof r==\"string\"&&r.length\u003c=128,\"Use a seed of at most 128 characters.\"),this.project=y(R(e)),this.rules=s,this.seed=r,this.actions=[],this.states=[];let i=s.initial(this.project,x(r,0));this.check(i),this.states.push(c(i)),this.verifyTurn()}get state(){return y(c(this.states.at(-1)))}check(e){S(e,\"Game state\"),o(Number.isInteger(e.player)&&e.player>=0&&e.player\u003cthis.project.players,\"State must identify the current player.\");let s=this.rules.validate(y(c(e)),this.project);o(s===!0,typeof s==\"string\"?s:\"Rule validation failed.\")}outcome(){let e=this.rules.outcome(this.state,this.project);return o(e===null||e&&typeof e==\"object\"&&typeof e.title==\"string\"&&Array.isArray(e.winners)&&e.winners.every(s=>Number.isInteger(s)&&s>=0&&s\u003cthis.project.players),\"Outcome must be null or {title,winners,...}.\"),e===null?null:S(e,\"Outcome\")}legal(){let e=this.rules.legal(this.state,this.project);o(Array.isArray(e)&&e.length\u003c=500,\"Rules must offer at most 500 legal actions.\"),S(e,\"Legal actions\");let s=new Set;for(let r of e)o(r&&typeof r.id==\"string\"&&r.id.length\u003c=180&&!s.has(r.id)&&typeof r.label==\"string\"&&r.label.length\u003c=200,\"Legal actions need unique ids and readable labels.\"),s.add(r.id);return c(e)}verifyTurn(){let e=this.outcome(),s=this.legal();return o(e!==null||s.length>0,\"Dead end: the game has no legal action and no outcome.\"),o(e===null||s.length===0,\"Finished games must not offer actions.\"),{end:e,a:s}}view(){let{end:e,a:s}=this.verifyTurn(),r=this.rules.observe(this.state,this.state.player,this.project);return S(r,\"Observation\"),o(r&&typeof r.title==\"string\"&&Array.isArray(r.zones)&&Array.isArray(r.scores),\"Observation needs title, zones and scores.\"),{view:r,actions:s,outcome:e,player:this.state.player,step:this.actions.length,seed:this.seed}}step(e){o(this.actions.length\u003c2e3,\"This playtest reached the 2,000-turn limit. Save its replay and revise the rules.\");let s=this.legal().find(l=>l.id===e);o(s&&!this.outcome(),\"That action is not legal now.\");let r=this.state,i=this.rules.apply(r,y(c(s)),this.project,x(this.seed,this.actions.length+1));this.check(i),o(g(r)!==g(i),\"An action must change the game state.\"),this.states.push(c(i)),this.actions.push(e);try{this.verifyTurn()}catch(l){throw this.states.pop(),this.actions.pop(),l}return this.view()}undo(){return this.actions.length&&(this.states.pop(),this.actions.pop()),this.view()}replay(){return{spec:1,seed:this.seed,actions:c(this.actions),state:g(this.state)}}restore(e){o(e?.spec===1&&Array.isArray(e.actions)&&e.actions.length\u003c=2e3,\"Use a version 1 replay within 2,000 turns.\"),o(e.seed===this.seed,\"Replay seed differs.\");for(let s of e.actions)this.step(s);return o(g(this.state)===e.state,\"Replay state does not match its actions and rules.\"),this.view()}};function I(n,e,{count:s=50,start:r=0,policy:i=\"uniform\",maxTurns:l=400}={}){o(Number.isInteger(s)&&s>=1&&s\u003c=200,\"Simulate 1\\u2013200 games.\"),o(Number.isInteger(l)&&l>=1&&l\u003c=2e3,\"Use a 1\\u20132,000 turn cap.\"),o([\"uniform\",\"authored\"].includes(i),\"Select uniform or authored policy.\"),i===\"authored\"&&o(typeof e.bot==\"function\",\"This rules module has no authored policy.\");let t=[];for(let a=0;a\u003cs;a++){let p=\"playtest-\"+(r+a);try{let h=new b(n,e,p),M=k(p+\"|policy\");for(;!h.outcome()&&h.actions.length\u003cl;){let O=h.view(),J=i===\"uniform\"?O.actions[Math.floor(M()*O.actions.length)].id:e.bot(y(c(O.view)),y(c(O.actions)),{random:M});h.step(J)}t.push({seed:p,turns:h.actions.length,outcome:h.outcome(),capped:!h.outcome(),replay:h.replay()})}catch(h){t.push({seed:p,error:h.message})}}let u=Array(n.players).fill(0);for(let a of t)for(let p of a.outcome?.winners??[])u[p]++;return{spec:1,policy:i,count:s,start:r,maxTurns:l,wins:u,completed:t.filter(a=>a.outcome).length,capped:t.filter(a=>a.capped).length,errors:t.filter(a=>a.error).length,meanTurns:t.reduce((a,p)=>a+(p.turns??0),0)/s,scope:\"Outcomes under the named policy and seeds. These simulations do not establish fun, fairness or human play balance.\",games:t}}var w,j,d,A;self.onmessage=async({data:{id:n,type:e,payload:s}})=>{try{let r;if(e===\"load\"){w=U(s.project),A=await q(w);let i=URL.createObjectURL(new Blob([w.rules],{type:\"text/javascript\"}));try{j=await import(i)}finally{URL.revokeObjectURL(i)}d=new b(w,j,s.seed??\"first-game\"),r={...d.view(),revision:A}}else{if(!d)throw new Error(\"Open a game first.\");if(e===\"step\")r=d.step(s.id);else if(e===\"undo\")r=d.undo();else if(e===\"restart\")d=new b(w,j,s.seed),r=d.view();else if(e===\"replay\")r={...d.replay(),revision:A};else if(e===\"restore\"){if(s.revision!==A)throw new Error(\"This replay belongs to different rules or components. Open its matching game file.\");let i=new b(w,j,s.seed);r=i.restore(s),d=i}else if(e===\"simulate\")r={...I(w,j,s),revision:A};else throw new Error(\"Unknown game operation.\")}self.postMessage({id:n,result:r})}catch(r){self.postMessage({id:n,error:r.message})}};})();\n"}</script><script>(()=>{var $=e=>JSON.parse(JSON.stringify(e)),U=(e,t=160)=>typeof e=="string"&&e.length>0&&e.length<=t,_=e=>typeof e=="string"&&/^[a-z][a-z0-9_-]{0,63}$/.test(e),ae=e=>typeof e=="string"&&/^#[a-f0-9]{6}$/i.test(e),C=(e,t,n)=>Number.isFinite(e)&&e>=t&&e<=n;function p(e,t){if(!e)throw new Error(t)}function v(e){p(e&&JSON.stringify(e).length<=3e6,"Keep the project below 3 MB.");let t=$(e);p(t.spec===1&&_(t.id)&&U(t.title)&&U(t.subtitle,400),"Use a version 1 Relay project with an id, title and subtitle."),p(Number.isInteger(t.players)&&t.players>=1&&t.players<=6,"Choose 1\u20136 players."),p(U(t.rules,2e5),"Include the complete rules module."),p(Array.isArray(t.rulebook)&&t.rulebook.length>=1&&t.rulebook.length<=40,"Include 1\u201340 rulebook sections.");for(let i of t.rulebook)p(U(i.heading)&&U(i.body,1e4),"Rulebook sections need a heading and body.");p(Array.isArray(t.components)&&t.components.length>0&&t.components.length<=160,"Create 1\u2013160 component designs.");let n=new Set,r=0;for(let i of t.components){p(_(i.id)&&!n.has(i.id),"Component ids must be unique."),n.add(i.id),p(U(i.name,80)&&typeof i.body=="string"&&i.body.length<=700,"Use short, readable component names and text."),p(["card","token","tile"].includes(i.kind),"Component kind must be card, token or tile."),p(C(i.widthMm,12,190)&&C(i.heightMm,12,273),"Component dimensions must fit A4 within 10 mm margins."),p(Number.isInteger(i.quantity)&&i.quantity>=1&&i.quantity<=100,"Component quantity must be 1\u2013100."),r+=i.quantity,p(ae(i.color)&&ae(i.ink),"Use six-digit hex colors."),p(typeof i.symbol=="string"&&i.symbol.length<=8,"Use a short symbol."),i.face!==void 0&&p(typeof i.face=="string"&&i.face.length<=7e5&&/^data:image\/(png|jpeg|webp|svg\+xml);base64,[A-Za-z0-9+/=]+$/.test(i.face),"Use an embedded PNG, JPEG, WebP or SVG face below 700 KB."),p(i.values&&typeof i.values=="object"&&!Array.isArray(i.values),"Component values must be an object.");for(let[c,u]of Object.entries(i.values))p(_(c)&&(typeof u=="number"&&Number.isFinite(u)||typeof u=="boolean"||typeof u=="string"&&u.length<160),"Values must be finite numbers, short text or booleans.");p(Object.keys(i.values).length<=20,"Keep at most 20 values per component.")}p(r<=600,"Keep the kit within 600 physical components."),p(Array.isArray(t.settings)&&t.settings.length<=30,"Keep at most 30 rule settings.");let o=new Set;for(let i of t.settings)p(_(i.id)&&!o.has(i.id)&&U(i.label),"Settings need unique ids and labels."),o.add(i.id),p(C(i.min,-1e4,1e4)&&C(i.max,i.min,1e4)&&C(i.value,i.min,i.max)&&C(i.step,.001,1e3),"Setting values must lie inside their declared bounds.");p(Array.isArray(t.boards)&&t.boards.length<=8,"Keep at most eight board sheets.");let s=new Set;for(let i of t.boards){p(_(i.id)&&!s.has(i.id)&&U(i.name),"Boards need unique ids and names."),s.add(i.id),p(C(i.widthMm,30,277)&&C(i.heightMm,30,190),"Boards must fit landscape A4 within 10 mm margins."),p(Number.isInteger(i.cols)&&i.cols>0&&i.cols<=20&&Number.isInteger(i.rows)&&i.rows>0&&i.rows<=20,"Boards support 1\u201320 rows and columns."),p(Array.isArray(i.cells)&&i.cells.length===i.cols*i.rows,"Define every board cell.");for(let c of i.cells)p(typeof c.label=="string"&&c.label.length<=30&&ae(c.color),"Board cells need a short label and hex color.")}return delete t.revision,t}function N(e){return e===null||typeof e!="object"?JSON.stringify(e):Array.isArray(e)?"["+e.map(N).join(",")+"]":"{"+Object.keys(e).sort().map(t=>JSON.stringify(t)+":"+N(e[t])).join(",")+"}"}function X(e,t=80){let n=[$(e)],r=0;return{get value(){return $(n[r])},get canUndo(){return r>0},get canRedo(){return r<n.length-1},push(o){return n=n.slice(0,r+1),n.push($(o)),n.length>t&&n.shift(),r=n.length-1,this.value},undo(){return r=Math.max(0,r-1),this.value},redo(){return r=Math.min(n.length-1,r+1),this.value}}}var d=e=>String(e??"").replace(/[&<>"']/g,t=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[t]),E=e=>e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,70)||"game",re=(e,t)=>{let n=[];for(let r of String(e).split(`
`)){let o="";for(let s of r.split(/\s+/))if(s)if(s.length>t){o&&n.push(o);for(let i=0;i<s.length;i+=t)n.push(s.slice(i,i+t));o=""}else(o+" "+s).trim().length>t?(n.push(o),o=s):o=(o+" "+s).trim();n.push(o)}return n},se=(e,t,n,r,o)=>e.map((s,i)=>`<text x="${t}" y="${n+i*r*1.35}" font-size="${r}" fill="${o}">${d(s)}</text>`).join("");function be(e,{back:t=!1}={}){let n=e.widthMm,r=e.heightMm,o=Math.min(5,n*.08),s=e.kind==="card"?3:e.kind==="token"?Math.min(n,r)/2:1;if(t)return`<rect width="${n}" height="${r}" rx="${s}" fill="#203a34"/><path d="M${n*.2} ${r*.5}h${n*.6}M${n*.5} ${r*.2}v${r*.6}" stroke="#e2bd74" stroke-width="1"/><text x="${n/2}" y="${r*.84}" text-anchor="middle" font-size="${Math.min(4,n*.1)}" fill="#fff7e7">RELAY</text>`;if(e.face)return`<rect width="${n}" height="${r}" fill="${e.color}"/><image width="${n}" height="${r}" preserveAspectRatio="xMidYMid meet" href="${d(e.face)}"/>`;let i=n-o*2,c=Math.min(5,n*.075),u=re(e.name,Math.floor(i/(c*.57))),b=Object.entries(e.values).map(([Y,K])=>Y.replace(/_/g," ")+": "+K).join(" \xB7 "),y=Math.min(3.1,n*.048),A=re(e.body,Math.floor(i/(y*.56))),f=Math.min(3,n*.05),H=re(b,Math.floor(i/(f*.56))),w=o+c,B=Math.max(r*.3,w+u.length*c*1.35+2),g=B+Math.min(r*.13,12)+y+2,ee=r-o-H.length*f*1.35+f;p(g+Math.max(0,A.length-1)*y*1.35+2<ee||e.kind!=="card","Text does not fit "+e.name+". Shorten it or enlarge the card.");let z=`<text x="${n/2}" y="${B+Math.min(r*.1,9)}" text-anchor="middle" font-size="${Math.min(r*.23,22)}" fill="${e.ink}">${d(e.symbol)}</text>`;if(e.kind==="tile"&&typeof e.values.ports=="string"){let Y=n/2,K=r/2;return z='<g stroke="'+e.ink+'" stroke-width="'+Math.min(n,r)*.14+'" stroke-linecap="round">'+[...e.values.ports].map(Te=>{let ie={N:[Y,0],E:[n,K],S:[Y,r],W:[0,K]}[Te];return ie?`<path d="M${Y} ${K}L${ie[0]} ${ie[1]}"/>`:""}).join("")+"</g>",`<rect width="${n}" height="${r}" rx="1" fill="${e.color}"/>${z}<text x="3" y="${r-3}" font-size="2.5" fill="${e.ink}">${d(e.name)}</text>`}return e.kind==="token"?`<rect width="${n}" height="${r}" rx="${s}" fill="${e.color}"/>${z}<text x="${n/2}" y="${r*.85}" text-anchor="middle" font-size="${Math.min(3,n*.07)}" fill="${e.ink}">${d(e.name)}</text>`:`<rect width="${n}" height="${r}" rx="${s}" fill="${e.color}"/><rect x="1.5" y="1.5" width="${n-3}" height="${r-3}" rx="${Math.max(0,s-1)}" fill="none" stroke="${e.ink}" stroke-opacity=".3" stroke-width=".25"/>${se(u,o,w,c,e.ink)}${z}${se(A,o,g,y,e.ink)}${se(H,o,ee,f,e.ink)}`}function te(e,t={}){return`<svg xmlns="http://www.w3.org/2000/svg" width="${e.widthMm}mm" height="${e.heightMm}mm" viewBox="0 0 ${e.widthMm} ${e.heightMm}" font-family="Arial, sans-serif" role="img" aria-label="${d(t.back?"Card back":e.name)}">${be(e,t)}</svg>`}function Ae(e,t,n,r){return[[e,t],[e+n,t],[e,t+r],[e+n,t+r]].map(([i,c])=>`<path d="M${i-2.2-1.2} ${c}h${2.2}M${i+1.2} ${c}h${2.2}M${i} ${c-2.2-1.2}v${2.2}M${i} ${c+1.2}v${2.2}"/>`).join("")}function Q(e){v(e);let t=[],n=[],r=10,o=14,s=0,i=()=>{n.length&&t.push(n),n=[],r=10,o=14,s=0};for(let c of e.components)for(let u=0;u<c.quantity;u++)r+c.widthMm>200&&(r=10,o+=s+6,s=0),o+c.heightMm>287&&i(),p(o+c.heightMm<=287,"Component too tall for the print sheet."),n.push({id:c.id,copy:u+1,x:r,y:o,width:c.widthMm,height:c.heightMm}),r+=c.widthMm+6,s=Math.max(s,c.heightMm);return i(),t}function Z(e,t,n,{back:r=!1}={}){return`<svg xmlns="http://www.w3.org/2000/svg" width="210mm" height="297mm" viewBox="0 0 210 297" font-family="Arial, sans-serif"><rect width="210" height="297" fill="white"/><text x="10" y="7" font-size="2.6">${d(e.title)} \xB7 ${r?"optional backs":"components"} \xB7 sheet ${n+1} \xB7 actual size</text>${t.map(o=>{let s=e.components.find(c=>c.id===o.id),i="clip-"+e.id+"-"+n+"-"+o.id+"-"+o.copy+"-"+r;return`<defs><clipPath id="${i}"><rect width="${o.width}" height="${o.height}"/></clipPath></defs><g transform="translate(${o.x} ${o.y})" clip-path="url(#${i})">${be(s,{back:r})}</g>`}).join("")}<g fill="none" stroke="#333" stroke-width=".15">${t.map(o=>Ae(o.x,o.y,o.width,o.height)).join("")}</g><path d="M10 293h50m-50-1v2m50-2v2" stroke="#333" stroke-width=".2"/><text x="65" y="294" font-size="2.2">50 mm calibration \xB7 cut along component edges</text></svg>`}function le(e){let t=e.widthMm,n=e.heightMm,r=t/e.cols,o=(n-12)/e.rows;return`<svg xmlns="http://www.w3.org/2000/svg" width="${t}mm" height="${n}mm" viewBox="0 0 ${t} ${n}" font-family="Arial, sans-serif"><rect width="${t}" height="${n}" fill="#f5eedf"/><text x="4" y="8" font-size="4">${d(e.name)}</text>${e.cells.map((s,i)=>`<g transform="translate(${i%e.cols*r} ${12+Math.floor(i/e.cols)*o})"><rect x=".2" y=".2" width="${r-.4}" height="${o-.4}" fill="${s.color}" stroke="#637669" stroke-width=".3"/><text x="${r/2}" y="${o/2}" text-anchor="middle" font-size="${Math.min(3.5,r/8)}" fill="#203a34">${d(s.label)}</text></g>`).join("")}</svg>`}function ce(e){let t=Q(e);return`<!doctype html><html><head><meta charset="utf-8"><title>${d(e.title)} \u2014 print components</title><style>@page{size:A4;margin:0}body{margin:0;font-family:Arial,sans-serif}.screen{padding:20px;background:#f4efe4}.page{width:210mm;height:297mm;break-after:page;overflow:hidden}.page:last-child{break-after:auto}.page>svg{display:block;width:210mm;height:297mm}@media print{.screen{display:none}}</style></head><body><div class="screen"><h1>${d(e.title)}</h1><p>Print at 100% / actual size on A4. Disable browser headers and footers. Check the 50 mm calibration line. Print card backs separately and glue them to fronts or use opaque sleeves; duplex alignment is not assumed. The separate SVG files keep exact physical dimensions.</p><button onclick="print()">Print components / save PDF</button></div>${t.map((n,r)=>`<section class="page">${Z(e,n,r)}</section>`).join("")}</body></html>`}function de(e){return`<!doctype html><html lang="en"><head><meta charset="utf-8"><title>${d(e.title)} \u2014 rulebook</title><style>@page{size:A4;margin:17mm;@bottom-center{content:counter(page);font-size:9pt}}body{font:11pt/1.5 Arial,sans-serif;color:#203a34;max-width:760px;margin:35px auto}h1{font-size:28pt;line-height:1.1}h2{font-size:15pt;break-after:avoid}p{white-space:pre-line;orphans:3;widows:3}table{border-collapse:collapse;width:100%;font-size:10pt}td,th{padding:6px;border-bottom:1px solid #b6c8b8;text-align:left;vertical-align:top}tr,li{break-inside:avoid}.settings{break-inside:avoid}.print{background:#edf3e7;padding:15px}@media print{body{margin:0;max-width:none}.print{display:none}}</style></head><body><div class="print"><button onclick="print()">Print rulebook / save PDF</button></div><h1>${d(e.title)}</h1><p>${d(e.subtitle)}</p><p>${e.players} player${e.players===1?"":"s"} \xB7 ${e.components.reduce((t,n)=>t+n.quantity,0)} physical components</p>${e.rulebook.map(t=>`<h2>${d(t.heading)}</h2><p>${d(t.body)}</p>`).join("")}<section class="settings"><h2>This edition\u2019s rule settings</h2><table>${e.settings.map(t=>`<tr><th>${d(t.label)}</th><td>${t.value}</td></tr>`).join("")}</table></section><h2>Component inventory and values</h2><table><thead><tr><th>Component</th><th>Copies / size</th><th>Rules values</th></tr></thead><tbody>${e.components.map(t=>`<tr><td>${d(t.name)}</td><td>${t.quantity} \xD7 ${t.widthMm} \xD7 ${t.heightMm} mm</td><td>${Object.entries(t.values).map(([n,r])=>d(n)+": "+d(r)).join("<br>")}</td></tr>`).join("")}</tbody></table><h2>Print and keep</h2><p>Print components at actual size on A4 and check the 50 mm calibration line. Cut at the component edges. Optional backs can be printed separately and glued on or used in opaque sleeves; duplex alignment is not assumed. Board SVGs preserve their dimensions. The kit includes the editable JSON project and complete rules module, plus a playable offline HTML file. Rule or component revisions create a new edition: recheck the physical rulebook when mechanics change.</p></body></html>`}function ye(e,t,n=null,r=null){let o=v(e),s=$(o);delete s.rules;let i={"game.html":t,"project.relay.json":JSON.stringify(o,null,2),"source/project.json":JSON.stringify(s,null,2),"source/rules.mjs":o.rules,"print/components.html":ce(o),"print/rulebook.html":de(o),"README.txt":`${o.title}
Open game.html in a modern desktop browser to play and edit without a server. Open project.relay.json within Relay to restore its source. The source/rules.mjs file defines this game\u2019s mechanics. Project files contain gameplay JavaScript; open work you intend to run.
Print print/components.html at 100% / actual size on A4, no browser headers or footers. Check the 50 mm calibration line. Board SVGs have explicit physical sizes. Optional card backs are separate for gluing or opaque sleeves; no duplex alignment is assumed.
Pass-and-play conceals private views from casual observation, not from browser inspection or saved source/replays. Simulations measure the named policy and seeds, not fun or human balance. No online multiplayer or native game-engine importer is claimed.
Relay source and original artwork: Autonomous, MIT license.
`,"LICENSE.txt":`MIT License
Copyright (c) 2026 Autonomous
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
`};Q(o).forEach((c,u)=>{i[`print/sheet-${u+1}.svg`]=Z(o,c,u),i[`print/backs-${u+1}.svg`]=Z(o,c,u,{back:!0})});for(let c of o.components)i[`components/${c.id}.svg`]=te(c);for(let c of o.boards)i[`boards/${c.id}.svg`]=le(c);return n&&(i["playtest/replay.json"]=JSON.stringify(n,null,2)),r&&(i["playtest/simulation.json"]=JSON.stringify(r,null,2)),i}function pe(e){Array.isArray(e)||(e=Object.entries(e));let t=new TextEncoder,n=[],r=[],o=0;for(let[u,b]of e){let y=t.encode(u),A=typeof b=="string"?t.encode(b):new Uint8Array(b),f=4294967295;for(let ee of A){f^=ee;for(let z=0;z<8;z++)f=f>>>1^3988292384&-(f&1)}f=(f^4294967295)>>>0;let H=new Uint8Array(30+y.length),w=new DataView(H.buffer);w.setUint32(0,67324752,!0),w.setUint16(4,20,!0),w.setUint16(6,2048,!0),w.setUint16(12,33,!0),w.setUint32(14,f,!0),w.setUint32(18,A.length,!0),w.setUint32(22,A.length,!0),w.setUint16(26,y.length,!0),H.set(y,30);let B=new Uint8Array(46+y.length),g=new DataView(B.buffer);g.setUint32(0,33639248,!0),g.setUint16(4,20,!0),g.setUint16(6,20,!0),g.setUint16(8,2048,!0),g.setUint16(14,33,!0),g.setUint32(16,f,!0),g.setUint32(20,A.length,!0),g.setUint32(24,A.length,!0),g.setUint16(28,y.length,!0),g.setUint32(42,o,!0),B.set(y,46),n.push(H,A),r.push(B),o+=H.length+A.length}let s=r.reduce((u,b)=>u+b.length,0),i=new Uint8Array(22),c=new DataView(i.buffer);return c.setUint32(0,101010256,!0),c.setUint16(8,e.length,!0),c.setUint16(10,e.length,!0),c.setUint32(12,s,!0),c.setUint32(16,o,!0),new Blob([...n,...r,i],{type:"application/zip"})}var a=e=>document.getElementById(e),ne=JSON.parse(a("relay-data").textContent),Oe=`<!doctype html>
`+document.documentElement.outerHTML,l=v(ne.project),F=ne.project.revision,ue=!1,J=!1,I=null,L=X(l),x=l.components[0].id,O=$(l),ve="",h=null,k=null,q=null,Ne=0,R=new Map,G=!1,we,ke,Ee,oe="relay-draft:"+location.href,P=(e,t,n="application/octet-stream")=>{let r=URL.createObjectURL(t instanceof Blob?t:new Blob([t],{type:n})),o=document.createElement("a");o.href=r,o.download=e,o.click(),setTimeout(()=>URL.revokeObjectURL(r),1e4)};function M(e,t=!1){clearTimeout(we),a("notice").textContent=e,a("notice").hidden=!1,a("notice").classList.toggle("error",t),we=setTimeout(()=>a("notice").hidden=!0,t?14e3:6500)}var m=e=>async(...t)=>{try{return await e(...t)}catch(n){M(n.message,!0)}};function V(){try{localStorage.setItem(oe,JSON.stringify({baseRevision:F,project:l}))}catch{M("Browser draft storage is full. Download the project to keep this edition.",!0)}}function Re(){q&&q.terminate();for(let t of R.values())clearTimeout(t.timer),t.reject(new Error("The previous rules worker stopped."));R.clear();let e=URL.createObjectURL(new Blob([ne.worker],{type:"text/javascript"}));q=new Worker(e),URL.revokeObjectURL(e),q.onmessage=({data:t})=>{let n=R.get(t.id);n&&(R.delete(t.id),clearTimeout(n.timer),t.error?n.reject(new Error(t.error)):n.resolve(t.result))},q.onerror=t=>{for(let n of R.values())clearTimeout(n.timer),n.reject(new Error(t.message||"Rules worker failed."));R.clear()}}function T(e,t={}){return new Promise((n,r)=>{let o=++Ne,s=setTimeout(()=>{q.terminate(),J=!1,S();for(let i of R.values())clearTimeout(i.timer),i.reject(new Error("Rules exceeded the time limit. Your source is kept; revise it and apply again."));R.clear()},e==="simulate"?3e4:4e3);R.set(o,{resolve:n,reject:r,timer:s}),q.postMessage({id:o,type:e,payload:t})})}function me(e){let t=JSON.stringify({project:e,worker:ne.worker}).replace(/</g,"\\u003c");return Oe.replace(/(<script id="relay-data" type="application\/json">)[\s\S]*?(<\/script>)/,(n,r,o)=>r+t+o)}async function he(e,{seed:t=a("seed").value,curtain:n=!0}={}){J=!1,S(),Re();let r=await T("load",{project:e,seed:t});J=!0,O=$(e),ve=r.revision,h=r,k=null,a("simulation-report").replaceChildren(),W(n),S()}async function fe(){if(!h)return;let e=null;try{e=await T("replay")}catch{}P(E(O.title)+"-previous-playtest.zip",pe({"game.html":me(O),"project.relay.json":JSON.stringify(O,null,2),"replay.json":JSON.stringify(e,null,2)}))}function j(e){let t=$(l);e(t),l=v(t),L.push(l),V(),D(),S()}function S(){let e=N(l)!==N(O);a("edition-notice").hidden=!e&&J,a("restart").disabled=!J,a("edition-notice").querySelector("span").textContent=J?"The table is playing the previous edition.":"Apply a valid edition to start the table.",a("game-title").textContent=l.title,a("game-subtitle").textContent=l.subtitle,a("source-state").textContent=(ue?"Workspace source":"Portable game")+(I?" \xB7 source changed":e?" \xB7 draft edition":" \xB7 playing current edition"),a("undo-edit").disabled=!L.canUndo,a("redo-edit").disabled=!L.canRedo,a("save-source").disabled=!ue,document.title=l.title+" \u2014 Relay"}function D(){a("library-title").textContent=l.title,a("component-list").innerHTML=l.components.map(n=>`<button class="component-row ${n.id===x?"active":""}" data-component="${d(n.id)}"><span class="swatch" style="background:${n.color};color:${n.ink}">${d(n.symbol)}</span><span>${d(n.name)}${n.locked?" \xB7 locked":""}<small>${n.quantity} ${d(n.kind)}${n.quantity===1?"":"s"} \xB7 ${n.widthMm} \xD7 ${n.heightMm} mm</small></span></button>`).join(""),a("component-list").querySelectorAll("button").forEach(n=>n.onclick=()=>{x=n.dataset.component,D()}),a("settings").innerHTML=l.settings.map(n=>`<label>${d(n.label)}<input data-setting="${n.id}" type="number" min="${n.min}" max="${n.max}" step="${n.step}" value="${n.value}"></label>`).join(""),a("settings").querySelectorAll("input").forEach(n=>n.onchange=m(()=>j(r=>r.settings.find(o=>o.id===n.dataset.setting).value=Number(n.value))));let e=l.components.find(n=>n.id===x)??l.components[0];x=e.id;try{a("component-preview").innerHTML=te(e)}catch(n){a("component-preview").textContent=n.message}let t=e.locked?"disabled":"";a("component-form").innerHTML=`<label>Name<input name="name" maxlength="80" value="${d(e.name)}" ${t}></label><label>Card text<textarea name="body" rows="4" maxlength="700" ${t}>${d(e.body)}</textarea></label><div class="row"><label>Color<input name="color" type="color" value="${e.color}" ${t}></label><label>Ink<input name="ink" type="color" value="${e.ink}" ${t}></label></div><label>Symbol<input name="symbol" maxlength="8" value="${d(e.symbol)}" ${t}></label><div class="row"><label>Width \xB7 mm<input name="widthMm" type="number" min="12" max="190" step=".5" value="${e.widthMm}" ${t}></label><label>Height \xB7 mm<input name="heightMm" type="number" min="12" max="273" step=".5" value="${e.heightMm}" ${t}></label></div><label>Copies<input name="quantity" type="number" min="1" max="100" value="${e.quantity}" ${t}></label><div class="row"><button type="button" id="import-face" ${t}>Import face artwork</button>${e.face?`<button type="button" id="reset-face" ${t}>Use generated face</button>`:""}</div>${e.face?'<p class="muted" style="font-size:11px">Custom artwork owns the printed face. Update its text when you change rules values.</p>':""}<h3>Rules values</h3>${Object.entries(e.values).map(([n,r])=>`<label>${d(n)}<input data-value="${d(n)}" data-type="${typeof r}" value="${d(r)}" ${t}></label>`).join("")}<div class="row"><button type="button" id="lock-component">${e.locked?"Unlock":"Lock"} component</button><button type="button" id="duplicate-component">Duplicate</button></div><p class="muted" style="font-size:10px;margin-top:14px">Rules read component ids and values. Editing this draft keeps the running playtest intact until you apply it.</p>`,a("component-form").onsubmit=n=>n.preventDefault(),a("component-form").querySelectorAll("input,textarea").forEach(n=>n.onchange=m(()=>j(r=>{let o=r.components.find(s=>s.id===x);if(o.locked)throw new Error("Unlock this approved component before editing.");if(n.dataset.value){let s=n.dataset.type;if(s==="boolean"&&!["true","false"].includes(n.value))throw new Error("Enter true or false.");o.values[n.dataset.value]=s==="number"?Number(n.value):s==="boolean"?n.value==="true":n.value}else o[n.name]=["widthMm","heightMm","quantity"].includes(n.name)?Number(n.value):n.value}))),a("import-face").onclick=()=>a("face-file").click(),a("reset-face")&&(a("reset-face").onclick=m(()=>j(n=>delete n.components.find(r=>r.id===x).face))),a("lock-component").onclick=m(()=>j(n=>n.components.find(r=>r.id===x).locked=!e.locked)),a("duplicate-component").onclick=m(()=>{let n=$(e);n.id="piece-"+Date.now().toString(36),n.name=e.name+" copy",n.locked=!1,x=n.id,j(r=>r.components.push(n))})}function W(e=!1){if(!h)return;let t=O;a("scores").innerHTML=h.view.scores.map(o=>`<div>${d(o.label)}<strong>${d(o.value)}</strong></div>`).join(""),a("turn-title").textContent=h.outcome?.title??h.view.title,a("turn-message").textContent=h.view.message??"",a("turn-count").textContent="Turn "+h.step,a("undo-turn").disabled=!h.step;let n=o=>{let s=t.components.find(i=>i.id===o.component);if(o={...o,action:h.actions.some(i=>i.id===o.action)?o.action:null},!s)throw new Error("Observation refers to unknown component "+o.component);return`<div class="table-piece"><button class="game-piece" ${o.action?`data-move="${d(o.action)}"`:""} aria-label="${d(o.faceDown?"Face-down piece":s.name)}" ${o.action?"":"disabled"}><div style="transform:rotate(${Number(o.rotation)||0}deg)">${te(s,{back:!!o.faceDown})}</div>${o.badge!==void 0?`<span class="badge">${d(o.badge)}</span>`:""}</button>${s.kind==="card"&&!o.faceDown?`<span class="piece-label">${d(s.name)}<small>${Object.entries(s.values).map(([i,c])=>d(i)+": "+d(c)).join(" \xB7 ")}</small></span><details><summary>Read card</summary><p>${d(s.body)}</p></details>`:""}</div>`};a("zones").innerHTML=h.view.zones.map(o=>{let s;if(o.board){let i=t.boards.find(c=>c.id===o.board);if(!i)throw new Error("Unknown board "+o.board);s=`<div class="board" style="grid-template-columns:repeat(${i.cols},1fr)">${i.cells.map((c,u)=>`<div class="board-cell" style="background:${c.color}"><small>${d(c.label)}</small>${o.items.filter(b=>b.cell===u).map(n).join("")}</div>`).join("")}</div>`}else s=`<div class="cards">${o.items.map(n).join("")||"<small>No components here yet.</small>"}</div>`;return`<section class="zone"><h3>${d(o.label)}</h3>${s}</section>`}).join(""),a("actions").innerHTML=h.actions.map(o=>`<button data-move="${d(o.id)}">${d(o.label)}</button>`).join(""),document.querySelectorAll("[data-move]").forEach(o=>o.onclick=m(()=>Ue(o.dataset.move)));let r=!h.outcome&&!!h.view.private;a("curtain").hidden=!(e&&r);for(let o of["scores","zones","actions"])a(o).inert=!a("curtain").hidden;a("curtain-title").textContent="Player "+(h.player+1)+", your turn."}async function Ue(e){if(!G){G=!0;try{let t=h.player;h=await T("step",{id:e}),W(h.player!==t),xe()}finally{G=!1}}}async function xe(){try{let e=await T("replay");localStorage.setItem(oe+":replay",JSON.stringify({project:O,replay:e}))}catch{}}function je(){a("rulebook-editor").innerHTML=l.rulebook.map((e,t)=>`<section class="rule-section"><label>Section heading<input data-heading="${t}" maxlength="160" value="${d(e.heading)}"></label><label>Instructions<textarea data-body="${t}" rows="5" maxlength="10000">${d(e.body)}</textarea></label></section>`).join(""),a("rulebook-editor").querySelectorAll("input,textarea").forEach(e=>e.onchange=m(()=>j(t=>{let n=Number(e.dataset.heading??e.dataset.body);t.rulebook[n][e.dataset.heading===void 0?"body":"heading"]=e.value})))}function Se(e){let t=URL.createObjectURL(new Blob([e],{type:"text/html"}));window.open(t,"_blank","noopener"),setTimeout(()=>URL.revokeObjectURL(t),6e4)}function ge(e,t,n){a("editor-title").textContent=e,a("editor-content").innerHTML=t,ke=n,a("editor-dialog").showModal()}a("editor-apply").onclick=m(()=>{ke(),a("editor-dialog").close()});a("edit-rules").onclick=()=>ge("Author this game\u2019s rules",`<p>The complete JavaScript module defines mechanics. Export initial, legal, apply, observe, outcome and validate; optional bot supplies a named policy. Use only local code. An edited module becomes a new edition when you apply it to the table.</p><textarea id="rules-code" class="code" spellcheck="false">${d(l.rules)}</textarea>`,()=>j(e=>e.rules=a("rules-code").value));a("edit-metadata").onclick=()=>ge("Game details",`<label>Title<input id="game-name-edit" value="${d(l.title)}" maxlength="160"></label><label>Subtitle<textarea id="game-subtitle-edit" maxlength="400">${d(l.subtitle)}</textarea></label><label>Players<input id="game-players-edit" type="number" min="1" max="6" value="${l.players}"></label><p>Player count must match the authored rules.</p>`,()=>j(e=>{e.title=a("game-name-edit").value,e.subtitle=a("game-subtitle-edit").value,e.players=Number(a("game-players-edit").value)}));a("add-component").onclick=()=>ge("Add a component",'<label>Name<input id="new-name" value="New card" maxlength="80"></label><label>Kind<select id="new-kind"><option value="card">Card</option><option value="tile">Tile</option><option value="token">Token</option></select></label><p>Adding a design does not invent its behavior. Reference its id and values in the rules module.</p>',()=>{let e="piece-"+Date.now().toString(36),t=a("new-kind").value;x=e,j(n=>n.components.push({id:e,name:a("new-name").value,body:"",kind:t,widthMm:t==="card"?63:35,heightMm:t==="card"?88:35,quantity:1,color:"#365948",ink:"#fff8e9",symbol:"\u2726",values:{},locked:!1}))});a("undo-edit").onclick=()=>{l=L.undo(),V(),D(),S()};a("redo-edit").onclick=()=>{l=L.redo(),V(),D(),S()};a("apply-edition").onclick=m(async()=>{await fe(),await he(l),M("Previous game and replay downloaded. Playing the edited edition.")});a("restart").onclick=m(async()=>{await fe(),h=await T("restart",{seed:a("seed").value}),W(!0),M("A fresh playtest is ready. The previous game was kept.")});a("undo-turn").onclick=m(async()=>{h=await T("undo"),W(!0),xe()});a("reveal").onclick=()=>{a("curtain").hidden=!0;for(let e of["scores","zones","actions"])a(e).inert=!1};a("save-replay").onclick=m(async()=>P(E(O.title)+"-replay.json",JSON.stringify(await T("replay"),null,2),"application/json"));a("open-replay").onclick=()=>a("replay-file").click();a("replay-file").onchange=m(async e=>{let t=e.target.files[0];if(t){if(t.size>5e6)throw new Error("Choose a replay below 5 MB.");h=await T("restore",JSON.parse(await t.text())),a("seed").value=h.seed,W(!0),M("Replay verified against its rules and actions."),e.target.value=""}});a("simulate").onclick=m(async()=>{if(!G){G=!0,a("simulate").disabled=!0,a("simulate").textContent="Testing\u2026";try{k=await T("simulate",{count:Number(a("simulation-count").value),policy:a("policy").value,maxTurns:400}),a("simulation-report").innerHTML=`<div class="simulation-stats"><span><strong>${k.completed}/${k.count}</strong>completed</span><span><strong>${k.errors}</strong>errors</span><span><strong>${k.capped}</strong>turn caps</span><span><strong>${k.meanTurns.toFixed(1)}</strong>mean turns</span>${k.wins.map((e,t)=>`<span><strong>${e}</strong>Player ${t+1} wins</span>`).join("")}</div><p>${d(k.scope)}</p><button id="save-simulation">Download seeds, outcomes & replays</button>`,a("save-simulation").onclick=()=>P(E(O.title)+"-simulation.json",JSON.stringify(k,null,2),"application/json")}finally{G=!1,a("simulate").disabled=!1,a("simulate").textContent="Run playtest"}}});async function Me(){if(v(l),Q(l),!(N(l)===N(O))||!J)throw new Error("Apply this edition to the table before exporting its complete kit. Your draft project can always be downloaded.");let t=await T("replay");P(E(l.title)+"-print-and-play.zip",pe(ye(l,me(l),t,k))),M("Complete playable and printable game exported.")}a("export-kit").onclick=m(Me);a("export-kit-secondary").onclick=m(Me);a("export-html").onclick=m(()=>P(E(l.title)+".html",me(v(l)),"text/html"));a("export-project").onclick=()=>P(E(l.title)+".relay.json",JSON.stringify(l,null,2),"application/json");a("print-components").onclick=m(()=>Se(ce(l)));a("print-rulebook").onclick=a("print-rules").onclick=m(()=>Se(de(l)));a("add-section").onclick=m(()=>{j(e=>e.rulebook.push({heading:"New section",body:"Describe the next part of the game."})),je()});a("face-file").onchange=m(async e=>{let t=e.target.files[0];if(!t)return;if(!["image/png","image/jpeg","image/webp","image/svg+xml"].includes(t.type)||t.size>5e5)throw new Error("Use a PNG, JPEG, WebP or SVG face below 500 KB.");let r=new Uint8Array(await t.arrayBuffer()),o="";for(let c of r)o+=String.fromCharCode(c);let s="data:"+t.type+";base64,"+btoa(o),i=new Image;i.src=s,await i.decode(),j(c=>{let u=c.components.find(b=>b.id===x);if(u.locked)throw new Error("Unlock the component before replacing its artwork.");u.face=s}),e.target.value=""});a("open-project").onclick=()=>a("project-file").click();a("project-file").onchange=m(async e=>{let t=e.target.files[0];if(!t)return;if(t.size>3e6)throw new Error("Choose a game project below 3 MB.");let n=v(JSON.parse(await t.text()));await fe(),l=n,L=X(l),x=l.components[0].id,V(),D(),S(),await he(l),e.target.value="",M("Game source opened. Save source to replace the workspace edition.")});async function Ce(){let e=await fetch("/api/project",{method:"PUT",headers:{"content-type":"application/json","if-match":F},body:JSON.stringify(l)}),t=await e.json();if(e.status===409)throw I=t.project,a("source-notice").hidden=!1,new Error("The agent changed the source. Keep both editions before choosing.");if(!e.ok)throw new Error(t.error);F=t.project.revision,I=null,a("source-notice").hidden=!0,V(),S(),M("Source saved with the previous edition in workspace history.")}a("save-source").onclick=m(Ce);a("keep-draft").onclick=()=>P(E(l.title)+"-draft.relay.json",JSON.stringify(l,null,2),"application/json");a("load-source").onclick=m(async()=>{I&&(P(E(l.title)+"-before-source.relay.json",JSON.stringify(l,null,2),"application/json"),l=v(I),F=I.revision,I=null,a("source-notice").hidden=!0,L=X(l),V(),D(),S(),M("Both source editions kept. Apply the new edition when ready to restart the playtest."))});async function $e(){try{let e=await fetch("/api/project",{cache:"no-store"});if(!e.ok)return;let t=await e.json();ue=!0,t.project.revision!==F&&(I=t.project,a("source-notice").hidden=!1),S()}catch{}}for(let e of document.querySelectorAll("[data-tab]"))e.onclick=m(()=>{for(let t of["workbench","rules","print"])a(t).hidden=t!==e.dataset.tab;document.querySelectorAll("[data-tab]").forEach(t=>t.classList.toggle("active",t===e)),e.dataset.tab==="rules"&&je(),e.dataset.tab==="print"&&(a("print-preview").innerHTML=Q(l).slice(0,8).map((t,n)=>Z(l,t,n)).join("")+l.boards.map(le).join(""))});try{let e=JSON.parse(localStorage.getItem(oe)??"null");e?.project&&N(e.project)!==N(l)&&(l=v(e.project),F=e.baseRevision,L=X(l),M("Restored the last browser draft."))}catch{}D();S();m(async()=>{await he(l),["http:","https:"].includes(location.protocol)&&(await $e(),Ee=setInterval($e,5e3));let e=JSON.parse(localStorage.getItem(oe+":replay")??"null");e?.replay&&e.replay.revision===ve&&(h=await T("restore",e.replay),W(!0),M("Restored and verified the previous playtest."))})();})();
</script></body></html>