icoa-cli 2.19.665 → 2.19.667

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import chalk from"chalk";const t=()=>{const t=process.env.LC_ALL||process.env.LANG||"";return"C"!==t&&"POSIX"!==t},a=t=>new Promise(a=>setTimeout(a,t));export function traceKind(t){const a=String(t.goal?.type??"");return"bow"===a?"bow":"nod"===a?"nod":"stand"===a?"stand":"top"}export function topFrame(a,e,o=56,n=15){const s=a.samples,r=[0,...s.map(t=>t[1]),...a.markers.map(t=>t[0])],l=[0,...s.map(t=>t[2]),...a.markers.map(t=>t[1])];for(const t of a.walls)r.push(t.pos[0]-t.size[0],t.pos[0]+t.size[0]),l.push(t.pos[1]-t.size[1],t.pos[1]+t.size[1]);const p=a.goal;Array.isArray(p.goal)&&(r.push(p.goal[0]),l.push(p.goal[1]));const i=.15;let c=Math.min(...r)-i,h=Math.max(...r)+i,m=Math.min(...l)-i,d=Math.max(...l)+i;const f=(h-c)/o,g=(d-m)/n,u=Math.max(f,g/2,.02),y=(c+h)/2,w=(m+d)/2;c=y-u*o/2,h=y+u*o/2,m=w-u*n,d=w+u*n;const x=Array.from({length:n},()=>Array(o).fill(" ")),M=(t,a,e,s=!0)=>{const r=((t,a)=>{const e=Math.floor((t-c)/(h-c)*o),s=Math.floor((d-a)/(d-m)*n);return s>=0&&s<n&&e>=0&&e<o?[s,e]:null})(t,a);r&&(s||" "===x[r[0]][r[1]])&&(x[r[0]][r[1]]=e)};for(const t of a.walls){const a=Math.max(2,Math.round(2*t.size[1]/(2*u)));for(let e=0;e<=a;e++)M(t.pos[0],t.pos[1]-t.size[1]+2*t.size[1]*e/a,"#")}a.markers.forEach((t,a)=>{M(t[0],t[1],String((a+1)%10))}),Array.isArray(p.goal)&&!a.markers.length&&M(p.goal[0],p.goal[1],"G");const b=t()?"·":".",$=s.filter(t=>t[0]<=e+1e-9);for(const t of $.slice(0,-1))M(t[1],t[2],b,!1);M(0,0,"S");const _=null!=a.fallen_at&&e>=a.fallen_at,A=$[$.length-1];A&&M(A[1],A[2],_?"X":"D");const k=t=>"#"===t?chalk.white(t):"S"===t?chalk.green(t):"D"===t?chalk.bold.yellow(t):"X"===t?chalk.bold.red(t):t===b?chalk.cyan(t):/[0-9G]/.test(t)?chalk.magenta(t):t,v=chalk.gray(` +${"-".repeat(o)}+`);return[v,...x.map(t=>chalk.gray(" |")+t.map(k).join("")+chalk.gray("|")),v]}export function stripFrame(a,e,o=56,n=9){const s=traceKind(a),r=t=>"nod"===s?t[5]:t[4],l=a.goal,p="bow"===s?[{v:l.gx_high??.18,label:"down line"},{v:l.gx_low??.08,label:"up line"}]:"nod"===s?[{v:(l.amp_min??.4)/2,label:"down line"},{v:-(l.amp_min??.4)/2,label:"up line"}]:[],i=a.samples.map(r),c=Math.min(...i,...p.map(t=>t.v))-.05,h=Math.max(...i,...p.map(t=>t.v))+.05,m=t=>Math.max(0,Math.min(n-1,Math.round((h-t)/(h-c)*(n-1)))),d=Array.from({length:n},()=>Array(o).fill(" ")),f=new Map;for(const t of p){const a=m(t.v);f.set(a,t.label);for(let t=0;t<o;t++)d[a][t]="-"}const g=t()?"●":"o";for(const t of a.samples){if(t[0]>e+1e-9)break;const n=Math.min(o-1,Math.floor(t[0]/Math.max(a.seconds,.1)*o));d[m(r(t))][n]=null!=a.fallen_at&&t[0]>=a.fallen_at?"X":g}const u="nod"===s?"head":"body lean",y=[chalk.gray(` ${u} ↑`)];return d.forEach((t,a)=>{const e=t.map(t=>"-"===t?chalk.gray(t):"X"===t?chalk.bold.red(t):chalk.cyan(t)).join("");y.push(chalk.gray(" |")+e+(f.has(a)?chalk.gray(` ${f.get(a)}`):""))}),y.push(chalk.gray(` +${"-".repeat(o)}> time`)),y.push(chalk.gray(` 0 s${" ".repeat(Math.max(1,o-8))}${a.seconds} s`)),y}export async function playTrace(t){if(!t?.samples?.length)return;const e=traceKind(t),o=a=>{const o="top"===e?topFrame(t,a):stripFrame(t,a),n=t.samples.filter(t=>t[0]<=a+1e-9).pop()??t.samples[0],s=null!=t.fallen_at&&a>=t.fallen_at,r="top"===e?` t=${a.toFixed(1).padStart(4)} s x ${n[1].toFixed(2)} m y ${n[2].toFixed(2)} m heading ${n[3]}°`:` t=${a.toFixed(1).padStart(4)} s`;return[...o,chalk.white(r)+(s?chalk.red(` fell at ${t.fallen_at} s`):"")]},n=t.samples[t.samples.length-1][0];if(!process.stdout.isTTY){for(const t of o(n))console.log(t);return}let s=0;for(let t=1;t<=30;t++){const e=o(n*t/30);process.stdout.write((s?`[${s}A`:"")+e.map(t=>`${t}`).join("\n")+"\n"),s=e.length,t<30&&await a(100)}}export function traceLegend(a){const e=traceKind(a);return"top"===e?" S start · D the duck · X fell · # wall · 1 2 3 markers · G goal · "+(t()?"·":".")+" its path":"bow"===e?" each bow = the dots go above the down line, then back under the up line":"nod"===e?" each nod = the head goes past the down line, then past the up line":" the duck should stay standing the whole time"}
1
+ import chalk from"chalk";const e=()=>{const e=process.env.LC_ALL||process.env.LANG||"";return"C"!==e&&"POSIX"!==e},t=e=>new Promise(t=>setTimeout(t,e));export function traceKind(e){const t=String(e.goal?.type??"");return"bow"===t?"bow":"nod"===t?"nod":"stand"===t?"stand":"top"}export function topFrame(t,o,a=56,n=15){const r=t.samples,s=[0,...r.map(e=>e[1]),...t.markers.map(e=>e[0])],l=[0,...r.map(e=>e[2]),...t.markers.map(e=>e[1])];for(const e of t.walls)s.push(e.pos[0]-e.size[0],e.pos[0]+e.size[0]),l.push(e.pos[1]-e.size[1],e.pos[1]+e.size[1]);const h=t.goal;Array.isArray(h.goal)&&(s.push(h.goal[0]),l.push(h.goal[1]));const i=.15;let p=Math.min(...s)-i,d=Math.max(...s)+i,c=Math.min(...l)-i,m=Math.max(...l)+i;const f=(d-p)/a,g=(m-c)/n,u=Math.max(f,g/2,.02),w=(p+d)/2,y=(c+m)/2;p=w-u*a/2,d=w+u*a/2,c=y-u*n,m=y+u*n;const b=Array.from({length:n},()=>Array(a).fill(" ")),x=(e,t,o,r=!0)=>{const s=((e,t)=>{const o=Math.floor((e-p)/(d-p)*a),r=Math.floor((m-t)/(m-c)*n);return r>=0&&r<n&&o>=0&&o<a?[r,o]:null})(e,t);s&&(r||" "===b[s[0]][s[1]])&&(b[s[0]][s[1]]=o)};for(const e of t.walls){const t=Math.max(2,Math.round(2*e.size[1]/(2*u)));for(let o=0;o<=t;o++)x(e.pos[0],e.pos[1]-e.size[1]+2*e.size[1]*o/t,"#")}t.markers.forEach((e,t)=>{x(e[0],e[1],String((t+1)%10))}),Array.isArray(h.goal)&&!t.markers.length&&x(h.goal[0],h.goal[1],"G");const M=e()?"·":".",$=r.filter(e=>e[0]<=o+1e-9);for(const e of $.slice(0,-1))x(e[1],e[2],M,!1);x(0,0,"S");const v=null!=t.fallen_at&&o>=t.fallen_at,_=$[$.length-1];_&&x(_[1],_[2],v?"X":"D");const k=e=>"#"===e?chalk.white(e):"S"===e?chalk.green(e):"D"===e?chalk.bold.yellow(e):"X"===e?chalk.bold.red(e):e===M?chalk.cyan(e):/[0-9G]/.test(e)?chalk.magenta(e):e,A=chalk.gray(` +${"-".repeat(a)}+`);return[A,...b.map(e=>chalk.gray(" |")+e.map(k).join("")+chalk.gray("|")),A]}export function stripFrame(t,o,a=56,n=9){const r=traceKind(t),s=e=>"nod"===r?-e[5]:e[4],l=t.goal,h="bow"===r?[{v:l.gx_high??.18,label:"bent enough"},{v:l.gx_low??.08,label:"standing straight"}]:"nod"===r?[{v:-(l.amp_min??.4)/2,label:"head down enough"},{v:(l.amp_min??.4)/2,label:"head up enough"}]:[],i=t.samples.map(s),p=Math.min(...i,...h.map(e=>e.v))-.05,d=Math.max(...i,...h.map(e=>e.v))+.05,c=e=>Math.max(0,Math.min(n-1,Math.round((d-e)/(d-p)*(n-1)))),m=Array.from({length:n},()=>Array(a).fill(" ")),f=new Map;for(const e of h){const t=c(e.v);f.set(t,e.label);for(let e=0;e<a;e++)m[t][e]="-"}const g=e()?"●":"o";for(const e of t.samples){if(e[0]>o+1e-9)break;const n=Math.min(a-1,Math.floor(e[0]/Math.max(t.seconds,.1)*a));m[c(s(e))][n]=null!=t.fallen_at&&e[0]>=t.fallen_at?"X":g}const u="nod"===r?"head: up ↑ · down ↓":"body: bent forward ↑ · straight ↓",w=[chalk.gray(` ${u}`)];return m.forEach((e,t)=>{const o=e.map(e=>"-"===e?chalk.gray(e):"X"===e?chalk.bold.red(e):chalk.cyan(e)).join("");w.push(chalk.gray(" |")+o+(f.has(t)?chalk.gray(` ${f.get(t)}`):""))}),w.push(chalk.gray(` +${"-".repeat(a)}> time`)),w.push(chalk.gray(` 0 s${" ".repeat(Math.max(1,a-8))}${t.seconds} s`)),w}export async function playTrace(e){if(!e?.samples?.length)return;const o=traceKind(e),a=t=>{const a="top"===o?topFrame(e,t):stripFrame(e,t),n=e.samples.filter(e=>e[0]<=t+1e-9).pop()??e.samples[0],r=null!=e.fallen_at&&t>=e.fallen_at,s="top"===o?` t=${t.toFixed(1).padStart(4)} s x ${n[1].toFixed(2)} m y ${n[2].toFixed(2)} m heading ${n[3]}°`:` t=${t.toFixed(1).padStart(4)} s`;return[...a,chalk.white(s)+(r?chalk.red(` fell at ${e.fallen_at} s`):"")]},n=e.samples[e.samples.length-1][0];if(!process.stdout.isTTY){for(const e of a(n))console.log(e);return}let r=0;for(let e=1;e<=30;e++){const o=a(n*e/30);process.stdout.write((r?`[${r}A`:"")+o.map(e=>`${e}`).join("\n")+"\n"),r=o.length,e<30&&await t(100)}}export function traceLegend(t,o){if(o?.none)return" (This problem has no extra legend — read the picture yourself.)";const a=traceKind(t);if("top"===a)return` The floor seen from above. ${e()?"·":"."} = where the duck walked (one dot every 0.1 s), D = the duck now, S = start.\n # = wall · 1 2 3 = markers on the floor · G = goal · X = where it fell.`;const n=(t.seconds/56).toFixed(1);return"bow"===a?` ● = how far the body is bent forward, one dot every ${n} s, left → right = time.\n One bow = the dots climb above "bent enough", then drop below "standing straight".`:"nod"===a?` ● = where the head is told to point, one dot every ${n} s, left → right = time. High = up, low = down.\n One nod = the dots drop below "head down enough", then climb above "head up enough".`:" the duck should stay standing the whole time"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "icoa-cli",
3
- "version": "2.19.665",
3
+ "version": "2.19.667",
4
4
  "description": "ICOA CLI — AI-native competition runtime of the International Cyber Olympiad in AI: learn, practise, and compete in AI & cybersecurity from the terminal (AI4CTF · CTF4AI · CTF4EAI)",
5
5
  "author": "Charlie Zhu",
6
6
  "type": "module",