PageSourceSearch

https://nmonette.github.io/assets/double_oracle_playground-w14XTqZa.js

js nmonette.github.io collected 2026-10-03 09:41:27 UTC 7,158 bytes, 1 lines download raw bytes

1import{a as y,j as e,C as I}from"./index-DXbvyrii.js";import{P}from"./playground-CSYyeFEG.js";const b=5,M=Array.from({length:b+1},(a,l)=>Array.from({length:b-l+1},(n,s)=>[l,s,b-l-s])).flat();function N(a,l){return a.reduce((n,s,t)=>n+Math.sign(s-l[t]),0)}function R(a){return a.join("-")}function S(a,l){const n=R(l);return a.some(s=>R(s)===n)}function v(a){const l=a.reduce((n,s)=>n+s,0);return a.map(n=>n/l)}function C(a,l,n){const s=Array(a.length).fill(1),t=Array(l.length).fill(1);for(let r=0;r<n;r+=1){let o=0,i=-1/0,u=0,m=1/0;for(let x=0;x<a.length;x+=1){let h=0;for(let d=0;d<l.length;d+=1)h+=N(a[x],l[d])*t[d];h>i&&(i=h,o=x)}for(let x=0;x<l.length;x+=1){let h=0;for(let d=0;d<a.length;d+=1)h+=s[d]*N(a[d],l[x]);h<m&&(m=h,u=x)}s[o]+=1,t[u]+=1}return{rowStrategy:v(s),columnStrategy:v(t)}}function F(a,l,n){return l.reduce((s,t,r)=>s+n[r]*N(a,t),0)}function O(a,l,n){return a.reduce((s,t,r)=>s+l[r]*N(t,n),0)}function E(a,l,n,s){let t=M[0],r=-1/0,o=M[0],i=1/0;for(const u of M){const m=F(u,l,s);m>r&&(r=m,t=u);const x=O(a,n,u);x<i&&(i=x,o=u)}return{rowBestResponse:t,rowBestValue:r,columnBestResponse:o,columnBestValue:i}}function A(a,l){return a.map(n=>l.map(s=>N(n,s)))}function $({maxSteps:a=18,solverIterations:l=6e4}={}){const n=[[b,0,0]],s=[[b,0,0]],t=[];for(let r=0;r<a;r+=1){const{rowStrategy:o,columnStrategy:i}=C(n,s,l),u=E(n,s,o,i);t.push({step:r,rowPopulation:n.map(h=>[...h]),columnPopulation:s.map(h=>[...h]),matrix:A(n,s),rowStrategy:o,columnStrategy:i,exploitability:(u.rowBestValue-u.columnBestValue)/2});const m=!S(n,u.rowBestResponse),x=!S(s,u.columnBestResponse);if(!m&&!x)break;m&&n.push([...u.rowBestResponse]),x&&s.push([...u.columnBestResponse])}return t}const T=850;function B({value:a}){return e.jsx("span",{className:"oracle-allocation",children:a.map((l,n)=>e.jsx("i",{children:l},n))})}function V({snapshot:a}){const l=a.rowPopulation.length-1,n=a.columnPopulation.length-1;return e.jsx("div",{className:"oracle-matrix-stage",children:e.jsx("div",{className:"oracle-matrix-scroll",children:e.jsxs("table",{className:"oracle-matrix",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{"aria-hidden":"true"}),a.columnPopulation.map((s,t)=>e.jsxs("th",{className:t===n?"new-column":"",scope:"col",children:[e.jsxs("strong",{children:["b",e.jsx("sub",{children:t})]}),e.jsx(B,{value:s})]},s.join("-")))]})}),e.jsx("tbody",{children:a.rowPopulation.map((s,t)=>e.jsxs("tr",{className:t===l?"new-row":"",children:[e.jsxs("th",{scope:"row",children:[e.jsxs("strong",{children:["a",e.jsx("sub",{children:t})]}),e.jsx(B,{value:s})]}),a.matrix[t].map((r,o)=>e.jsx("td",{className:[r>0?"positive":r<0?"negative":"zero",o===n?"new-column":""].join(" "),children:r>0?`+${r}`:r},`${t}-${o}`))]},s.join("-")))})]})})})}function k({snapshots:a,currentIndex:l}){const t={top:28,right:23,bottom:57,left:62},r=560-t.left-t.right,o=570-t.top-t.bottom,i=Math.max(a.length-1,1),u=Math.ceil(Math.max(...a.map(c=>c.exploitability),.1)*10)/10,m=c=>t.left+c/i*r,x=c=>t.top+o-c/u*o,h=a.slice(0,l+1),d=h[h.length-1],f=h.map((c,p)=>`${p===0?"M":"L"} ${m(c.step).toFixed(2)} ${x(c.exploitability).toFixed(2)}`).join(" "),j=[...new Set([0,Math.round(i/3),Math.round(2*i/3),i])];return e.jsxs("svg",{className:"oracle-chart",viewBox:"0 0 560 570",role:"img","aria-label":`Exploitability ${d.exploitability.toFixed(3)} at Double Oracle step ${d.step}`,children:[j.map(c=>{const p=m(c);return e.jsxs("g",{children:[e.jsx("line",{x1:p,x2:p,y1:t.top,y2:t.top+o,className:"oracle-chart-grid"}),e.jsx("text",{x:p,y:540,className:"oracle-chart-tick",children:c})]},c)}),[0,.25,.5,.75,1].map(c=>{const p=u*c,g=x(p);return e.jsxs("g",{children:[e.jsx("line",{x1:t.left,x2:t.left+r,y1:g,y2:g,className:"oracle-chart-grid"}),e.jsx("text",{x:t.left-11,y:g,className:"oracle-chart-tick y",children:p.toFixed(2)})]},c)}),e.jsx("line",{x1:t.left,x2:t.left+r,y1:t.top+o,y2:t.top+o,className:"oracle-chart-axis"}),e.jsx("line",{x1:t.left,x2:t.left,y1:t.top,y2:t.top+o,className:"oracle-chart-axis"}),e.jsx("path",{d:f,className:"oracle-chart-halo"}),e.jsx("path",{d:f,className:"oracle-chart-line"}),h.map(c=>
1e.jsx("circle",{cx:m(c.step),cy:x(c.exploitability),r:c.step===d.step?5:3,className:c.step===d.step?"oracle-chart-point current":"oracle-chart-point"},c.step)),e.jsx("text",{x:t.left+r/2,y:565,className:"oracle-chart-label",children:"Double Oracle step"}),e.jsx("text",{x:"17",y:t.top+o/2,className:"oracle-chart-label",transform:`rotate(-90 17 ${t.top+o/2})`,children:"exploitability"})]})}function L(){const a=y.useMemo(()=>$(),[]),[l,n]=y.useState(0),[s,t]=y.useState(!1),r=y.useRef(0),o=y.useRef(null),i=Math.max(a.length-1,0),u=Math.min(Math.max(Number.isFinite(l)?Math.trunc(l):0,0),i),m=a[u]??a[0];y.useEffect(()=>{if(!s)return;const f=Math.min(Math.max(Number.isFinite(r.current)?r.current:0,0),i),j=window.performance.now(),c=p=>{const g=Math.max(0,Math.floor((p-j)/T)),w=Math.min(Math.max(f+g,0),i);if(w!==r.current&&(r.current=w,n(w)),w>=i){o.current=null,t(!1);return}o.current=window.requestAnimationFrame(c)};return o.current=window.requestAnimationFrame(c),()=>{o.current!==null&&(window.cancelAnimationFrame(o.current),o.current=null)}},[s,i]);const x=()=>{if(s){t(!1);return}u>=i?(r.current=0,n(0)):r.current=u,t(!0)},h=()=>{t(!1),r.current=0,n(0)},d=f=>{const j=Number(f.target.value),c=Math.min(Math.max(Number.isFinite(j)?Math.trunc(j):0,0),i);t(!1),r.current=c,n(c)};return e.jsxs("main",{className:"playground-page oracle-page",children:[e.jsx(I,{alwaysHome:!0}),e.jsxs("header",{className:"playground-header",children:[e.jsx(P,{current:5}),e.jsx("h1",{children:"Double Oracle"}),e.jsx("h2",{className:"playground-subtitle",children:"Colonel Blotto"})]}),e.jsxs("section",{className:"oracle-controls",children:[e.jsxs("div",{className:"oracle-playback",children:[e.jsx("button",{type:"button",className:"playground-button primary",onClick:x,children:s?"Pause":"Start"}),e.jsx("button",{type:"button",className:"playground-button",onClick:h,children:"Reset"})]}),e.jsxs("label",{className:"oracle-scrubber",children:[e.jsx("span",{children:"0"}),e.jsx("input",{type:"range",min:"0",max:i,value:u,onChange:d,"aria-label":"Double Oracle step"}),e.jsx("span",{children:i})]})]}),e.jsxs("section",{className:"oracle-workspace",children:[e.jsxs("section",{className:"oracle-card oracle-matrix-card",children:[e.jsxs("div",{className:"oracle-card-heading",children:[e.jsxs("div",{children:[e.jsx("p",{className:"panel-label",children:"Population"}),e.jsx("h2",{children:"Empirical payoff matrix"})]}),e.jsxs("strong",{className:"oracle-population-size",children:[m.rowPopulation.length," × ",m.columnPopulation.length]})]}),e.jsx(V,{snapshot:m})]}),e.jsxs("aside",{className:"oracle-card oracle-exploitability-card",children:[e.jsxs("div",{className:"oracle-card-heading",children:[e.jsxs("div",{children:[e.jsx("p",{className:"panel-label",children:"Performance"}),e.jsx("h2",{children:"Exploitability"})]}),e.jsx("strong",{className:"oracle-exploitability-value",children:m.exploitability.toFixed(3)})]}),e.jsx("div",{className:"oracle-chart-wrap",children:e.jsx(k,{snapshots:a,currentIndex:u})})]})]})]})}export{L as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.