(Adaptive Loop) Pass 3
(Adaptive Loop) Record freeze commit hash in context manifest
This commit is contained in:
1 parent
816a0d8e14
commit
00f4c34da0
1079 files changed
+1131878
No files matched your search
+95
@@ -0,0 +1,95 @@
|
||||
(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))i(r);new MutationObserver(r=>{for(const p of r)if(p.type==="childList")for(const u of p.addedNodes)u.tagName==="LINK"&&u.rel==="modulepreload"&&i(u)}).observe(document,{childList:!0,subtree:!0});function n(r){const p={};return r.integrity&&(p.integrity=r.integrity),r.referrerPolicy&&(p.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?p.credentials="include":r.crossOrigin==="anonymous"?p.credentials="omit":p.credentials="same-origin",p}function i(r){if(r.ep)return;r.ep=!0;const p=n(r);fetch(r.href,p)}})();const ie={middle:12,outer:18},_={heat:"Heat Shield",hunger:"Dormancy",toxin:"Efflux",immunity:"Cloak"},H={heat:{label:"Heat",color:"#ff8a4c",icon:"sun",trait:"Heat Shield",response:"Heat sources add 3"},hunger:{label:"Hunger",color:"#b388ff",icon:"crescent",trait:"Dormancy",response:"Nutrient inlets add 1"},toxin:{label:"Toxin",color:"#7fd66b",icon:"skull",trait:"Efflux",response:"Toxin inlets add 3"},immunity:{label:"Immunity",color:"#5fd0ff",icon:"shield",trait:"Cloak",response:"Immune damage 3"}},F=6;function z(e,t,n){return e<t?t:e>n?n:e}function ae(){return{nutrient:0,heat:0,toxin:0,producer:0,grazer:0,phage:0}}function te(e){return{nutrient:e.nutrient,heat:e.heat,toxin:e.toxin,producer:e.producer,grazer:e.grazer,phage:e.phage}}function Ve(e){return{schemaVersion:1,mode:e.mode,scenarioId:e.scenarioId,turn:e.turn,rings:{inner:{direction:e.rings.inner.direction,tiles:e.rings.inner.tiles.map(te)},middle:{direction:e.rings.middle.direction,tiles:e.rings.middle.tiles.map(te)},outer:{direction:e.rings.outer.direction,tiles:e.rings.outer.tiles.map(te)}},lineage:{producer:{pressure:{...e.lineage.producer.pressure},unlocked:{...e.lineage.producer.unlocked}},grazer:{pressure:{...e.lineage.grazer.pressure},unlocked:{...e.lineage.grazer.unlocked}}},inheritedAtStart:{producer:[...e.inheritedAtStart.producer],grazer:[...e.inheritedAtStart.grazer]},consecutiveObjectiveTurns:e.consecutiveObjectiveTurns,environmentActive:{...e.environmentActive},outcome:e.outcome,actionLog:e.actionLog.map(t=>({ring:t.ring,dir:t.dir}))}}function be(e,t,n){return n==="cw"?(e+1)%t:(e+t-1)%t}function De(e,t){const n=e.length,i=new Array(n);for(let r=0;r<n;r++){const p=t==="cw"?(r+1)%n:(r+n-1)%n;i[p]=e[r]}return i}function ee(e,t){return e==="inner"?t:e==="middle"?2*t%ie.middle:3*t%ie.outer}function Be(e,t){return e==="inner"?t:e==="middle"?t%2===0?t/2:-1:t%3===0?t/3:-1}function y(e){const t=e[0];return{ring:t==="I"?"inner":t==="M"?"middle":"outer",index:parseInt(e.slice(1),10)}}function v(e,t,n,i,r,p,u){return{...y(e),chamber:{nutrient:t,producer:n,grazer:i,phage:r,heat:p,toxin:u}}}const _e=[{id:"s1-heat",index:1,name:"Cultivation Quota",subtitle:"Heat",turnLimit:8,starts:[v("O0",3,2,0,0,0,0),v("O6",3,2,0,0,0,0),v("M2",2,1,0,0,0,0),v("I0",1,0,0,0,0,0)],fixtures:[{kind:"nutrientInlet",...y("O0")},{kind:"nutrientInlet",...y("O6")},{kind:"heatSource",...y("O3")},{kind:"heatSource",...y("O9")}],teaches:"Ring rotation, gate alignment, inward nutrient flow, growth, preview, and the first pressure: heat."},{id:"s2-hunger",index:2,name:"Endurance",subtitle:"Hunger",turnLimit:10,starts:[v("O0",2,3,0,0,0,0),v("M2",1,2,1,0,0,0),v("M8",2,3,1,0,0,0),v("I4",0,2,2,0,0,0)],fixtures:[{kind:"nutrientInlet",...y("O0")}],teaches:"Competition, migration through gates, dormancy, and denying predator food."},{id:"s3-toxin",index:3,name:"Cleansing",subtitle:"Toxin",turnLimit:9,starts:[v("O0",3,3,0,0,0,0),v("O3",0,0,0,0,0,3),v("M4",2,3,0,0,0,0),v("O9",0,0,0,0,0,3),v("I5",2,2,1,0,0,0)],fixtures:[{kind:"nutrientInlet",...y("O0")},{kind:"drain",...y("I1")},{kind:"drain",...y("I3")}],teaches:"Routing contaminants inward to drains, resistance payment, and shared detoxification spillover."},{id:"s4-immunity",index:4,name:"Escort",subtitle:"Immunity",turnLimit:8,starts:[v("M2",2,3,0,0,0,0),v("M8",2,3,2,0,0,0),v("M0",3,3,1,0,0,0),v("I0",0,2,1,0,0,0),v("O5",0,0,0,1,0,0),v("O11",1,0,2,1,0,0)],fixtures:[{kind:"nutrientInlet",...y("O0")},{kind:"nutrientInlet",...y("O2")},{kind:"immuneNode",...y("I1")},{kind:"immuneNode",...y("I3")},{kind:"objective",...y("I0"),label:"sanctuary"}],teaches:"Immune targeting, cloak, retargeting spillover, and predator vulnerability."},{id:"s5-convergence",index:5,name:"Stable Equilibrium",subtitle:"Convergence",turnLimit:12,starts:[v("O0",3,3,0,0,0,0),v("O1",0,1,0,0,0,0),v("O17",0,1,0,0,0,0),v("O2",0,0,0,0,0,2),v("O8",0,0,0,0,2,0),v("M0",2,2,1,0,0,0),v("M1",0,1,0,0,0,0),v("M11",0,1,0,0,0,0),v("M2",2,2,1,0,0,0),v("M8",2,2,2,1,0,0),v("I0",0,2,1,0,0,0),v("I1",0,1,0,0,0,0),v("I3",0,0,0,0,0,1),v("I5",0,1,0,0,0,0)],fixtures:[{kind:"nutrientInlet",...y("O0")},{kind:"nutrientInlet",...y("O6")},{kind:"heatSource",...y("O3")},{kind:"heatSource",...y("O9")},{kind:"drain",...y("I3")},{kind:"immuneNode",...y("I2")},{kind:"objective",...y("I0"),label:"assay"},{kLine truncated
|
||||
<path d="M ${(e-n*.5).toFixed(1)} ${t} a ${(n*.5).toFixed(1)} ${(n*.32).toFixed(1)} 0 0 0 ${n.toFixed(1)} 0 a ${(n*.34).toFixed(1)} ${(n*.22).toFixed(1)} 0 0 0 ${(-n).toFixed(1)} 0 z" fill="#f3b34a" stroke="#c97f1e" stroke-width="${(n*.05).toFixed(1)}"/>
|
||||
<path d="M ${(e+n*.42).toFixed(1)} ${(t-n*.04).toFixed(1)} l ${(n*.14).toFixed(1)} ${(n*.1).toFixed(1)} l ${(-n*.14).toFixed(1)} ${(n*.1).toFixed(1)} z" fill="#7a4a08"/>
|
||||
${i.join("")}
|
||||
</g>`}function tt(e,t,n){const i=[];for(let p=0;p<6;p++){const u=(p*60+30)*Math.PI/180,k=e+Math.cos(u)*n*.5,I=t+Math.sin(u)*n*.5,b=e+Math.cos(u)*n*.78,M=t+Math.sin(u)*n*.78;i.push(`<line x1="${k.toFixed(1)}" y1="${I.toFixed(1)}" x2="${b.toFixed(1)}" y2="${M.toFixed(1)}" stroke="#ff6fae" stroke-width="${(n*.07).toFixed(1)}"/><circle cx="${b.toFixed(1)}" cy="${M.toFixed(1)}" r="${(n*.05).toFixed(1)}" fill="#ff6fae"/>`)}const r=[];for(let p=0;p<6;p++){const u=(90-60*p)*Math.PI/180;r.push(`${(e+Math.cos(u)*n*.45).toFixed(1)},${(t-Math.sin(u)*n*.45).toFixed(1)}`)}return`<g>${i.join("")}<polygon points="${r.join(" ")}" fill="#ff9ec7" stroke="#d63d86" stroke-width="${(n*.05).toFixed(1)}"/><polygon points="${r.slice(0,3).join(" ")}" fill="#ffd0e4" fill-opacity="0.7"/></g>`}function pe(e,t,n,i){return e==="producer"?Ze(t,n,i):e==="grazer"?et(t,n,i):tt(t,n,i)}function Me(e,t,n,i){switch(e){case"nutrientInlet":return`<g>
|
||||
<rect x="${(t-i*.14).toFixed(1)}" y="${(n-i*.5).toFixed(1)}" width="${(i*.28).toFixed(1)}" height="${(i*.5).toFixed(1)}" rx="${(i*.05).toFixed(1)}" fill="#3a6ea5" stroke="#8fb8e6"/>
|
||||
<polygon points="${(t-i*.14).toFixed(1)},${n} ${(t+i*.14).toFixed(1)},${n} ${t.toFixed(1)},${(n+i*.22).toFixed(1)}" fill="#6fa8dc"/>
|
||||
<circle cx="${t}" cy="${(n+i*.36).toFixed(1)}" r="${(i*.12).toFixed(1)}" fill="#9fd0ff"/>
|
||||
</g>`;case"heatSource":{const r=[];for(let p=0;p<8;p++){const u=p*45*Math.PI/180;r.push(`<line x1="${(t+Math.cos(u)*i*.55).toFixed(1)}" y1="${(n-Math.sin(u)*i*.55).toFixed(1)}" x2="${(t+Math.cos(u)*i*.8).toFixed(1)}" y2="${(n-Math.sin(u)*i*.8).toFixed(1)}" stroke="#ff7a3c" stroke-width="${(i*.05).toFixed(1)}"/>`)}return`<g>${r.join("")}<path d="M ${(t-i*.3).toFixed(1)} ${n} q ${(i*.3).toFixed(1)} ${(-i*.3).toFixed(1)} ${(i*.6).toFixed(1)} 0 q ${(i*.3).toFixed(1)} ${(i*.3).toFixed(1)} ${(i*.6).toFixed(1)} 0" fill="none" stroke="#ff9a5c" stroke-width="${(i*.09).toFixed(1)}"/><circle cx="${t}" cy="${n}" r="${(i*.13).toFixed(1)}" fill="#ffb347"/></g>`}case"toxinInlet":return`<g><polygon points="${(t-i*.22).toFixed(1)},${(n-i*.4).toFixed(1)} ${(t+i*.22).toFixed(1)},${(n-i*.4).toFixed(1)} ${t.toFixed(1)},${(n-i*.1).toFixed(1)}" fill="#6b8f3a" stroke="#a7d977"/><path d="M ${(t-i*.12).toFixed(1)} ${(n-i*.42).toFixed(1)} l ${(i*.24).toFixed(1)} 0 l 0 ${(-i*.18).toFixed(1)} l ${(-i*.24).toFixed(1)} 0 z" fill="#8a6fbf"/><circle cx="${t}" cy="${(n+i*.18).toFixed(1)}" r="${(i*.15).toFixed(1)}" fill="#9fe06a" stroke="#5e8a2e" stroke-width="${(i*.04).toFixed(1)}"/></g>`;case"drain":return`<g><polygon points="${(t-i*.34).toFixed(1)},${(n-i*.34).toFixed(1)} ${(t+i*.34).toFixed(1)},${(n-i*.34).toFixed(1)} ${t.toFixed(1)},${(n+i*.05).toFixed(1)}" fill="#445" stroke="#7d8aa0"/><rect x="${(t-i*.07).toFixed(1)}" y="${(n+i*.05).toFixed(1)}" width="${(i*.14).toFixed(1)}" height="${(i*.3).toFixed(1)}" fill="#6a7588"/><path d="M ${(t-i*.26).toFixed(1)} ${(n-i*.32).toFixed(1)} q ${(i*.26).toFixed(1)} ${(i*.16).toFixed(1)} ${(i*.52).toFixed(1)} 0" fill="none" stroke="#9fe06a" stroke-width="${(i*.06).toFixed(1)}"/></g>`;case"immuneNode":return`<g><ellipse cx="${t}" cy="${n}" rx="${(i*.4).toFixed(1)}" ry="${(i*.24).toFixed(1)}" fill="#10303a" stroke="#5fd0ff" stroke-width="${(i*.05).toFixed(1)}"/><circle cx="${t}" cy="${n}" r="${(i*.16).toFixed(1)}" fill="#5fd0ff"/><circle cx="${(t-i*.05).toFixed(1)}" cy="${(n-i*.05).toFixed(1)}" r="${(i*.06).toFixed(1)}" fill="#eafdff"/></g>`;case"objective":return`<g><circle cx="${t}" cy="${n}" r="${(i*.42).toFixed(1)}" fill="none" stroke="#ffd24a" stroke-width="${(i*.05).toFixed(1)}" stroke-dasharray="${(i*.14).toFixed(1)} ${(i*.1).toFixed(1)}"/><circle cx="${t}" cy="${n}" r="${(i*.1).toFixed(1)}" fill="#ffd24a"/><line x1="${(t-i*.55).toFixed(1)}" y1="${n}" x2="${(t-i*.2).toFixed(1)}" y2="${n}" stroke="#ffd24a" stroke-width="${(i*.04).toFixed(1)}"/><line x1="${(t+i*.2).toFixed(1)}" y1="${n}" x2="${(t+i*.55).toFixed(1)}" y2="${n}" stroke="#ffd24a" stroke-width="${(i*.04).toFixed(1)}"/><line x1="${t}" y1="${(n-i*.55).toFixed(1)}" x2="${t}" y2="${(n-i*.2).toFixed(1)}" stroke="#ffd24a" stroke-width="${(i*.04).toFixed(1)}"/><line x1="${t}" y1="${(n+i*.2).toFixed(1)}" x2="${t}" y2="${(n+i*.55).toFixed(1)}" stroke="#ffd24a" stroke-width="${(i*.04).toFixed(1)}"/></g>`}}function nt(e,t,n={}){const i=We(t),r=($,h)=>(i.get(`${$}:${h}`)??[]).map(s=>({kind:s.kind,label:s.label})),p=n.previewState,u=[];for(let $=0;$<6;$++){const h=U("inner",ue("inner",$));U("middle",ue("middle",$));const s=U("outer",ue("outer",$)),l=!!n.selectedRing;u.push(`<line x1="${s[0].toFixed(1)}" y1="${s[1].toFixed(1)}" x2="${h[0].toFixed(1)}" y2="${h[1].toFixed(1)}" stroke="url(#gateGlow)" stroke-width="${l?5:3}" stroke-linecap="round" opacity="0.55"/>`)}const k=[];for(const $ of["inner","middle","outer"]){const h=[];for(let s=0;s<6;s++){const l=(90-60*s)*Math.PI/180,o=Ee[$]+le[$]*.9;h.push(`${(V+o*Math.cos(l)).toFixed(1)},${(D-o*Math.sin(l)).toFixed(1)}`)}k.push(`<polygon points="${h.join(" ")}" fill="none" stroke="${Ie[$]}" stroke-width="1" stroke-dasharray="3 5" opacity="0.25"/>`)}const I=[];for(const $ of["outer","middle","inner"]){const h=le[$];for(let s=0;s<e.rings[$].tiles.length;s++){const[l,o]=U($,s),d=e.rings[$].tiles[s],f=Xe($,s),a=fe($,s),g=d.heat>0?'filter="url(#heatGlow)" ':"",x=$==="inner"?"#10243a":$==="middle"?"#152039":"#0f1c33",m=o+h*.55,w=h*1.1,S=d.nutrient/6*w,P=d.toxin/6*w,N=`clip-${$}-${s}`;let Q="";if(p){const G=p.rings[$].tiles[s],X=G.producer-d.producer,Z=G.grazer-d.grazer;(X!==0||Z!==0)&&(Q=`<text x="${l.toFixed(1)}" y="${(o-h-4).toFixed(1)}" text-anchor="middle" font-size="11" fill="#ffe08a" font-weight="700">${X!==0?`P${X>0?"+":""}${X}`:""}${Z!==0?` G${Z>0?"+":""}${Z}`:""}</text>`)}let T="";const j=h*.5;d.producer>0&&(T+=pe("producer",l-h*.32,o-h*.18,j)),d.grazer>0&&(T+=pe("grazer",l+h*.3,o-h*.18,j*.95)),d.phage>0&&(T+=pe("phage",l,o+h*.22,j*.85));const A=[];d.producer>0&&A.push(`<tspan fill="#7fff8a">P${d.producer}</tspan>`),d.grazer>0&&A.push(`<tspan fill="#ffc46a">V${d.grazer}</tspan>`),d.phage>0&&A.push(`<tspan fill="#ff9ec7">F${d.phage}</tspan>`);const He=A.length?`<text x="${l.toFixed(1)}" y="${(o+h*.95).toFixed(1)}" text-anchor="middle" font-size="${$==="inner"?12:10}" font-weight="700">${A.join(" ")}</text>`:"";let ve="";for(const G of r($,s))G.kind!=="objective"&&(ve+=Me(G.kind,l,o-h*0,h*.7));coLine truncated
|
||||
<g class="tile" data-ring="${$}" data-index="${s}">
|
||||
${qe}
|
||||
<polygon points="${de(l,o,h)}" ${g}fill="${x}" stroke="${f?Ie[$]:"#2a3b55"}" stroke-width="${f?2.2:1.2}"/>
|
||||
<defs><clipPath id="${N}"><polygon points="${de(l,o,h*.96)}"/></clipPath></defs>
|
||||
${S>0?`<rect x="${(l-h*.96).toFixed(1)}" y="${(m-S).toFixed(1)}" width="${(h*1.92).toFixed(1)}" height="${S.toFixed(1)}" fill="#1f6fd6" opacity="0.32" clip-path="url(#${N})"/>`:""}
|
||||
${P>0?`<rect x="${(l-h*.96).toFixed(1)}" y="${(m-P).toFixed(1)}" width="${(h*1.92).toFixed(1)}" height="${P.toFixed(1)}" fill="#5fbf4a" opacity="0.40" clip-path="url(#${N})"/>`:""}
|
||||
${d.heat>0?`<polygon points="${de(l,o,h)}" fill="none" stroke="#ff8a4c" stroke-width="${1+d.heat*.4}" opacity="${.3+d.heat*.1}"/>`:""}
|
||||
${ve}
|
||||
${T}
|
||||
${He}
|
||||
<text x="${(l-h*.78).toFixed(1)}" y="${(o-h*.82).toFixed(1)}" font-size="${$==="inner"?9:8}" fill="#6f86a8">${a}</text>
|
||||
${Q}
|
||||
</g>`)}}const b=`<circle cx="${V}" cy="${D}" r="34" fill="#0a1426" stroke="#2a3b55"/><text x="${V}" y="${(D+4).toFixed(1)}" text-anchor="middle" font-size="11" fill="#7d97bf">ADAPTIVE</text><text x="${V}" y="${(D+16).toFixed(1)}" text-anchor="middle" font-size="11" fill="#7d97bf">LOOP</text>`,M=[];if(n.flowEvents&&n.flowEvents.length){const $=h=>J(h);for(const h of n.flowEvents){const[s,l]=U(h.ring,h.index),o=le[h.ring],d=h.field==="nutrient"?"#5fb0ff":"#9fe06a";if(h.tangential>0){const a=$(h.ring)==="cw"?o*.5:-o*.5;M.push(`<path d="M ${(s-a).toFixed(1)} ${(l-o*.95).toFixed(1)} l ${a.toFixed(1)} ${(o*.5).toFixed(1)} l ${a.toFixed(1)} ${(-o*.5).toFixed(1)}" fill="none" stroke="${d}" stroke-width="2.2" stroke-linecap="round" opacity="0.95"><title>${h.field} tangential flow at ${fe(h.ring,h.index)}</title></path>`)}if(h.radial>0){const f=Math.atan2(D-l,V-s),a=s+Math.cos(f)*o*.4,g=l+Math.sin(f)*o*.4,x=s+Math.cos(f)*o*.95,m=l+Math.sin(f)*o*.95;M.push(`<line x1="${x.toFixed(1)}" y1="${m.toFixed(1)}" x2="${a.toFixed(1)}" y2="${g.toFixed(1)}" stroke="${d}" stroke-width="2.4" stroke-linecap="round" opacity="0.95" marker-end="url(#flowHead)"><title>${h.field} radial-inward flow at ${fe(h.ring,h.index)}</title></line>`)}}}function J($){return e.rings[$].direction}return`<svg viewBox="0 0 ${B} ${B}" role="img" aria-label="Culture board: three concentric hexagonal rings linked by six radial gates${n.flowEvents?.length?"; preview shows flow arrows":""}" class="board-svg">
|
||||
<defs>
|
||||
<linearGradient id="gateGlow" x1="0" y1="0" x2="1" y2="1">
|
||||
<stop offset="0%" stop-color="#7fffd6"/><stop offset="50%" stop-color="#9d7bff"/><stop offset="100%" stop-color="#5fd0ff"/>
|
||||
</linearGradient>
|
||||
<filter id="heatGlow" x="-50%" y="-50%" width="200%" height="200%">
|
||||
<feGaussianBlur stdDeviation="2.2" result="b"/><feMerge><feMergeNode in="b"/><feMergeNode in="SourceGraphic"/></feMerge>
|
||||
</filter>
|
||||
<marker id="flowHead" markerWidth="7" markerHeight="7" refX="3.5" refY="3.5" orient="auto"><path d="M0,0 L7,3.5 L0,7 z" fill="#9fe06a"/></marker>
|
||||
</defs>
|
||||
<rect x="0" y="0" width="${B}" height="${B}" fill="#070d18"/>
|
||||
${k.join("")}
|
||||
${u.join("")}
|
||||
${I.join("")}
|
||||
${M.join("")}
|
||||
${b}
|
||||
</svg>`}function it(e){const t=[];for(const n of["producer","grazer"]){const i=e.lineage[n],r=n==="producer"?"Lumiflora":"Vellea",p=["heat","hunger","toxin","immunity"].map(u=>{const k=i.pressure[u],I=i.unlocked[u],b="▰".repeat(k)+"▱".repeat(3-k);return`<span class="ptrack ${I?"adapted":""}" title="${u}: ${k}/3${I?" (adapted)":""}">${b}${I?"✓":""}</span>`});t.push(`<div class="lineage"><span class="lin-name">${r}</span>${p.join("")}</div>`)}return t.join("")}const re="adaptive-loop-save-v1",rt=1;function ot(e){const t={...e,savedAt:new Date().toISOString()};localStorage.setItem(re,JSON.stringify(t))}function st(){const e=localStorage.getItem(re);if(!e)return{ok:!1,reason:"No saved game found."};let t;try{t=JSON.parse(e)}catch{return{ok:!1,reason:"Saved game is corrupt (invalid JSON)."}}const n=t;return!n||typeof n!="object"?{ok:!1,reason:"Saved game is empty."}:n.schemaVersion!==rt?{ok:!1,reason:`Unsupported save version ${n.schemaVersion}.`}:!n.state||!n.scenarioId||!n.progress?{ok:!1,reason:"Saved game is missing required fields."}:at(n.state)?{ok:!0,env:n}:{ok:!1,reason:"Saved game state is invalid."}}function je(){localStorage.removeItem(re)}function Oe(){return!!localStorage.getItem(re)}function at(e){if(!e||typeof e!="object")return!1;const t=e;if(t.schemaVersion!==1||!t.rings||!["inner","middle","outer"].every(i=>Array.isArray(t.rings[i]?.tiles)))return!1;const n={inner:6,middle:12,outer:18};for(const i of["inner","middle","outer"]){if(t.rings[i].tiles.length!==n[i])return!1;for(const r of t.rings[i].tiles){const p=r;for(const u of["nutrient","heat","toxin","producer","grazer","phage"])if(typeof p[u]!="number"||p[u]<0||p[u]>6||!Number.isInteger(p[u]))return!1}}return!0}const Pe=[{ring:"inner",dir:"cw",label:"Inner ⟳",key:"1"},{ring:"inner",dir:"ccw",label:"Inner ⟲",key:"2"},{ring:"middle",dir:"cw",label:"Middle ⟳",key:"3"},{ring:"middle",dir:"ccw",label:"Middle ⟲",key:"4"},{ring:"outer",dir:"cw",label:"Outer ⟳",key:"5"},{ring:"outer",dir:"ccw",label:"Outer ⟲",key:"6"}];let c,R;function ct(e){R=e,c={view:"title",mode:"campaign",scenario:C[0],state:Le(C[0],"campaign"),progress:me(),selected:null,preview:null,lastEvents:[],announce:"",pendingNewTraits:[]},O()}function me(){return{unlocked:[C[0].id],inherited:{producer:[],grazer:[]},entrySnapshot:{producer:[],grazer:[]},victory:!1}}function O(){R.innerHTML=lt(),mt(),R.querySelector("#announce")?.setAttribute("aria-live","polite")}function lt(){return c.view==="title"?dt():c.view==="menu"?ut():c.view==="victory"?gt():c.view==="choice"?pt():ft()}function oe(e,t){return`<main class="app">
|
||||
<header class="topbar"><h1>${t}</h1>
|
||||
<nav class="topnav">
|
||||
<button id="btnMenu" class="btn ghost" aria-label="Return to menu">Menu</button>
|
||||
<button id="btnSaveQuit" class="btn ghost" aria-label="Save and quit to title">Save & Quit</button>
|
||||
<button id="btnHelp" class="btn ghost" aria-label="Open help and legend">Help</button>
|
||||
</nav>
|
||||
</header>
|
||||
<div id="announce" class="announce" role="status">${c.announce}</div>
|
||||
${e}
|
||||
<section id="helpPanel" class="help-panel hidden" aria-hidden="true">${ht()}</section>
|
||||
</main>`}function dt(){return`<main class="app title">
|
||||
<div id="announce" class="announce" role="status">${c.announce}</div>
|
||||
<h1>Adaptive Loop</h1>
|
||||
<p class="subtitle">A calm deterministic microfluidic strategy puzzle.</p>
|
||||
<p class="lede">Rotate the three concentric glass rings to align the six radial gates, route nutrient inward, and provoke — then exploit — the ecosystem's counter-adaptations.</p>
|
||||
<div class="actions">
|
||||
<button id="btnStart" class="btn primary">New Campaign</button>
|
||||
<button id="btnContinue" class="btn" ${Oe()?"":"disabled"}>Continue</button>
|
||||
<button id="btnReplay" class="btn">Replay Standalone</button>
|
||||
</div>
|
||||
<p class="hint">${Oe()?"A saved run is available.":"No saved run yet."}</p>
|
||||
</main>`}function ut(){const e=C.map(t=>{const n=c.progress.unlocked.includes(t.id);return`<li class="${n?"":"locked"}">
|
||||
<button class="btn scenario-btn" data-scid="${t.id}" ${n?"":"disabled"} aria-label="Play ${t.name}">
|
||||
<span class="scn-no">${t.index}</span>
|
||||
<span class="scn-name">${t.name}</span>
|
||||
<span class="scn-sub">${t.subtitle}</span>
|
||||
</button>
|
||||
</li>`}).join("");return oe(`<section class="menu"><h2>Campaign Scenarios</h2><ul class="scn-list">${e}</ul></section>`,"Adaptive Loop — Menu")}function ft(){const e=c.scenario,t=c.state,n=t.outcome!=="playing",i=(c.preview?.events??[]).filter(o=>o.phase==="flow").map(o=>({ring:o.ring,index:o.index,field:o.field,tangential:o.tangential,radial:o.radial})),r=nt(t,e,{previewState:c.preview?.state??null,selectedRing:c.selected?.ring??null,flowEvents:i}),p=Ft(e),u=`Turn ${t.turn}/${e.turnLimit}${t.outcome!=="playing"?` — ${xe(t.outcome)}`:""}`,k=Pe.map(o=>{const d=c.selected&&c.selected.ring===o.ring&&c.selected.dir===o.dir,f=d&&c.preview?` → ${Ne(c.preview.events)}`:"";return`<button class="btn rot ${d?"selected":""}" data-ring="${o.ring}" data-dir="${o.dir}" aria-label="Rotate ${o.ring} ${o.dir==="cw"?"clockwise":"counter-clockwise"}${f}"${n?" disabled":""}><span class="key">${o.key}</span> ${o.label}</button>`}).join(""),b=`<button id="btnCommit" class="btn primary" ${n||!c.selected?"disabled":""} aria-label="Commit selected rotation">Commit</button>`,M=`<button id="btnCancel" class="btn ghost" ${c.selected?"":"disabled"} aria-label="Cancel preview">Cancel (Esc)</button>`,J=t.outcome==="collapsed"||t.outcome==="expired"?'<button id="btnRetry" class="btn">Retry</button>':"",$=St(c.preview?.events??c.lastEvents),h=it(t),s=["heat","hunger","toxin","immunity"].filter(o=>t.environmentActive[o]).map(o=>`<span class="envflag">${H[o].label} Response</span>`).join(""),l=[...c.progress.inherited.producer.map(o=>`Lumiflora:${_[o]}`),...c.progress.inherited.grazer.map(o=>`Vellea:${_[o]}`)].join(", ")||"none";return oe(`<section class="play">
|
||||
<div class="board-wrap">${r}</div>
|
||||
<aside class="rail">
|
||||
<div class="panel obj">
|
||||
<h2>${e.index}. ${e.name} <span class="scn-sub">(${e.subtitle})</span></h2>
|
||||
<p class="obj-text">${p}</p>
|
||||
<p class="turn">${u}</p>
|
||||
${s?`<p class="env">${s}</p>`:""}
|
||||
<p class="inh">Inherited: ${l}</p>
|
||||
</div>
|
||||
<div class="panel controls">
|
||||
<h2>Rotate a ring</h2>
|
||||
<div class="rot-grid">${k}</div>
|
||||
<div class="commit-row">${b} ${M} ${J}</div>
|
||||
<p class="sel-status">${c.selected?`Selected: ${c.selected.ring} ${c.selected.dir}. Commit enabled.`:"Select a rotation to preview."}</p>
|
||||
</div>
|
||||
<div class="panel traits"><h2>Pressure tracks</h2>${h}<p class="legend-mini">▰ = track step · ✓ = adapted (benefit+cost active)</p></div>
|
||||
<div class="panel events"><h2>${c.preview?"Preview":"Last tick"}</h2><ol class="event-list">${$}</ol></div>
|
||||
</aside>
|
||||
</section>`,`Adaptive Loop — ${e.name}`)}function pt(){const e=c.pendingNewTraits.map((t,n)=>{const i=t.lin==="producer"?"Lumiflora":"Vellea",r=H[t.p];return`<button class="btn choice" data-i="${n}"><span class="ch-lin">${i}</span> · <span class="ch-trait">${_[t.p]}</span><br><span class="ch-meta">Benefit: prevents ${t.p} loss. Cost: ${zt(t.p)}. ${r.response}.</span></button>`}).join("");return oe(`<section class="choice">
|
||||
<h2>Scenario won — preserve a lineage trait?</h2>
|
||||
<p>The ecosystem unlocked new adaptations. Preserve one to carry its gift (and cost) forward, or decline.</p>
|
||||
<div class="choice-grid">${e}</div>
|
||||
<button id="btnDecline" class="btn ghost">Decline</button>
|
||||
</section>`,"Lineage choice")}function gt(){return oe('<section class="victory"><h2>Campaign Victory</h2><p>You stabilized the Adaptive Loop across all five scenarios.</p><button id="btnMenu" class="btn primary">Return to Menu</button></section>',"Victory")}function ht(){const e=`<li><b>Lumiflora</b> (producer, green diatom) — consumes nutrient, grows.</li>
|
||||
<li><b>Vellea</b> (grazer, amber crescent) — consumes producers, grows.</li>
|
||||
<li><b>Phage</b> (pink lander) — consumes grazers; starves without prey.</li>`,t=["heat","hunger","toxin","immunity"].map(n=>`<li><b>${H[n].label}</b> → trait <b>${_[n]}</b>. Response: ${H[n].response}.</li>`).join("");return`<h2>Help & Legend</h2><p>Rotate a ring (buttons or keys 1–6). A rotation moves that ring's payloads and re-aligns the gates; the tick then resolves flow, growth, feeding, migration, adaptation, and pressure. Select to preview exact deltas; Commit applies it.</p>
|
||||
<h3>Species</h3><ul>${e}</ul>
|
||||
<h3>Pressures & adaptations</h3><ul>${t}</ul>
|
||||
<p>Gate tiles glow in their ring color; nutrient fills the tile base blue, toxin green, heat warms the rim. <kbd>1</kbd>–<kbd>6</kbd> rotate, <kbd>Enter</kbd>/<kbd>Space</kbd> commits, <kbd>Esc</kbd> cancels.</p>`}function mt(){const e=(t,n,i)=>R.querySelector(t)?.addEventListener(n,i);e("#btnStart","click",xt),e("#btnContinue","click",vt),e("#btnReplay","click",()=>{c.view="menu",c.mode="standalone",c.progress={...me(),unlocked:C.map(t=>t.id)},O()}),e("#btnMenu","click",()=>{c.view="menu",O()}),e("#btnSaveQuit","click",yt),e("#btnHelp","click",wt),e("#btnDecline","click",()=>ge(null)),R.querySelectorAll(".rot").forEach(t=>{const n=t.dataset.ring,i=t.dataset.dir;t.addEventListener("click",()=>ne({ring:n,dir:i})),t.addEventListener("focus",()=>{(!c.selected||c.selected.ring!==n||c.selected.dir!==i)&&ne({ring:n,dir:i})}),t.addEventListener("mouseenter",()=>{c.selected||ne({ring:n,dir:i})})}),R.querySelectorAll(".scenario-btn").forEach(t=>{t.addEventListener("click",()=>{const n=t.dataset.scid;se(n,c.mode)})}),R.querySelectorAll(".choice").forEach(t=>{t.addEventListener("click",()=>{const n=+t.dataset.i;ge(c.pendingNewTraits[n]??null)})}),e("#btnCommit","click",Ce),e("#btnCancel","click",Re),e("#btnRetry","click",kt),document.onkeydown=$t}function $t(e){if(e.key==="Escape"){Re();return}if(c.view!=="play"||c.state.outcome!=="playing")return;const t="123456".indexOf(e.key);if(t>=0){ne(Pe[t]);return}(e.key==="Enter"||e.key===" ")&&c.selected&&(e.preventDefault(),Ce())}function xt(){c.mode="campaign",c.progress=me(),c.view="play",se(C[0].id,"campaign")}function vt(){const e=st();if(!e.ok){c.announce=e.reason,O();return}const t=e.env;c.mode=t.mode,c.progress=t.progress,c.scenario=he(t.scenarioId),c.state=t.state,c.selected=null,c.preview=null,c.lastEvents=[],c.view="play",c.announce="Resumed saved run.",O()}function se(e,t){const n=he(e);c.scenario=n,c.mode=t;const i=t==="standalone"?{producer:[],grazer:[]}:c.progress.inherited;c.state=Le(n,t,i),c.progress.entrySnapshot={producer:[...i.producer],grazer:[...i.grazer]},c.selected=null,c.preview=null,c.lastEvents=[],c.view="play",c.announce=`${n.name}: ${n.teaches}`,$e(),O()}function ne(e){if(c.state.outcome!=="playing")return;c.selected=e;const{state:t,events:n}=Ae(c.state,e,!0);c.preview={state:t,events:n},c.announce=`Previewing ${e.ring} ${e.dir}: ${Ne(n)}`,O(),R.querySelector(`.rot[data-ring="${e.ring}"][data-dir="${e.dir}"]`)?.focus()}function Re(){c.selected&&(c.selected=null,c.preview=null,c.announce="Preview cancelled.",O())}function Ce(){if(!c.selected||c.state.outcome!=="playing")return;const e=c.selected,{state:t,events:n}=Ae(c.state,e,!0);c.state=t,c.lastEvents=n,c.selected=null,c.preview=null,c.announce=`Turn ${t.turn}: ${xe(t.outcome)}.`,$e(),t.outcome==="won"?bt():O()}function bt(){if(c.mode==="standalone"){c.announce="Standalone scenario complete.",O();return}const e=c.state.inheritedAtStart,t=[];for(const r of["producer","grazer"])for(const p of["heat","hunger","toxin","immunity"])c.state.lineage[r].unlocked[p]&&!e[r].includes(p)&&!c.progress.inherited[r].includes(p)&&t.push({lin:r,p});const n=c.scenario.index,i=C[n];if(i&&!c.progress.unlocked.includes(i.id)&&c.progress.unlocked.push(i.id),!i){c.progress.victory=!0,c.view="victory",je(),O();return}if(t.length===0){ge(null);return}c.pendingNewTraits=t,c.view="choice",O()}function ge(e){e&&(c.progress.inherited[e.lin]=[...c.progress.inherited[e.lin],e.p]);const t=c.scenario.index,n=C[t];if(!n){c.progress.victory=!0,c.view="victory",je(),O();return}se(n.id,"campaign")}function kt(){c.progress.inherited={producer:[...c.progress.entrySnapshot.producer],grazer:[...c.progress.entrySnapshot.grazer]},se(c.scenario.id,c.mode)}function yt(){$e(),c.view="title",c.announce="Saved. Quit to title.",O()}function $e(){c.view==="play"&&ot({schemaVersion:1,mode:c.mode,scenarioId:c.scenario.id,state:c.state,progress:c.progress,actionLog:c.state.actionLog,outcome:c.state.outcome})}function wt(){const e=R.querySelector("#helpPanel");e&&(e.classList.toggle("hidden"),e.setAttribute("aria-hidden",e.classList.contains("hidden")?"true":"false"))}function Ft(e,t){return e.id==="s1-heat"?"Grow producers: producer at I0 ≥ 4 and total producer ≥ 12. (Tuned: see TUNING.md)":e.id==="s2-hunger"?"Endure to turn 10: total producer ≥ 8, grazer ≥ 4, across ≥3 producer tiles and ≥2 grazer tiles.":e.id==="s3-toxin"?"Cleanse: by turn 6–9 reach total toxin ≤ 4 and producer+grazer ≥ 8. (Tuned)":e.id==="s4-immunity"?"Escort: grazer at I0 (sanctuary) ≥ 3 and total producer ≥ 6. (Tuned)":e.id==="s5-convergence"?"Hold equilibrium: assay spoke + balanced ecosystem sustained for 2 consecutive turns. (Tuned)":e.teaches}function xe(e){return e==="won"?"Objective achieved":e==="collapsed"?"Ecosystem collapsed":e==="expired"?"Turn limit expired":"resolved"}function Ne(e){const t=[];for(const n of e)n.phase==="evolution"&&t.push(`unlocks ${_[n.pressure]}`),n.phase==="env"&&t.push(`${H[n.pressure].label} response`),n.phase==="Line truncated
|
||||
Reference in new issue
Block a user