icoa-cli 2.19.671 → 2.19.673
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.
- package/dist/commands/ai4ctf.js +1 -1
- package/dist/commands/ctf4ai-demo.js +1 -1
- package/dist/commands/ctf4vla.js +1 -1
- package/dist/commands/duck-contest.js +1 -1
- package/dist/commands/exam.js +1 -1
- package/dist/lib/duck-trace-run.js +4 -1
- package/dist/lib/duck-trace.js +1 -1
- package/package.json +1 -1
|
@@ -2,6 +2,7 @@ import{spawnSync as e}from"node:child_process";import{existsSync as s,mkdirSync
|
|
|
2
2
|
engine = sys.argv[sys.argv.index('--engine') + 1]
|
|
3
3
|
path = sys.argv[sys.argv.index('--file') + 1]
|
|
4
4
|
sid = sys.argv[sys.argv.index('--scenario') + 1]
|
|
5
|
+
seed = int(sys.argv[sys.argv.index('--seed') + 1]) if '--seed' in sys.argv else None
|
|
5
6
|
sys.path.insert(0, engine)
|
|
6
7
|
os.environ.setdefault('OMP_NUM_THREADS', '1')
|
|
7
8
|
os.environ.setdefault('MUJOCO_GL', 'disable')
|
|
@@ -22,6 +23,8 @@ buf, real = io.StringIO(), sys.stdout
|
|
|
22
23
|
sys.stdout = buf
|
|
23
24
|
try:
|
|
24
25
|
sc = Scenario.load(sid)
|
|
26
|
+
if seed is not None:
|
|
27
|
+
sc.seed = seed # another course: same map, different wobble (like the judge's hidden ones)
|
|
25
28
|
log = run_file(path, sc)
|
|
26
29
|
res = score(sc, log)
|
|
27
30
|
except ControlError as e:
|
|
@@ -48,4 +51,4 @@ emit({'ok': True, 'pass': bool(res['pass']), 'value': res['value'], 'detail': re
|
|
|
48
51
|
'trace': {'samples': pts, 'seconds': sc.seconds, 'fallen_at': log.fallen_at,
|
|
49
52
|
'walls': [{'pos': list(w['pos'][:2]), 'size': list(w['size'][:2])} for w in sc.walls],
|
|
50
53
|
'markers': [list(m['pos'][:2]) for m in sc.markers], 'goal': dict(sc.goal)}})
|
|
51
|
-
`,
|
|
54
|
+
`,d=i(n(),".icoa","duck","trace_run.py");export function runWithTrace(c,m,g,p,f=18e4,u){t(i(n(),".icoa","duck"),{recursive:!0}),s(d)&&r(d,"utf-8")===l||o(d,l);const y=e(c,[d,"--engine",m,"--file",a(g),"--scenario",p,...null!=u?["--seed",String(u)]:[]],{encoding:"utf-8",timeout:f,cwd:m,env:{...process.env,PYTHONDONTWRITEBYTECODE:"1",OMP_NUM_THREADS:"1",MUJOCO_GL:"disable"}}),x=String(y.stdout??"").trim().split("\n").pop()||"";try{return JSON.parse(x)}catch{return{ok:!1,error:"engine",message:String(y.stderr??"").trim().split("\n").slice(-3).join(" ")||`exit ${y.status}`}}}
|
package/dist/lib/duck-trace.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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 i=t.goal;Array.isArray(i.goal)&&(s.push(i.goal[0]),l.push(i.goal[1]));const h=.15;let d=Math.min(...s)-h,
|
|
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 i=t.goal;Array.isArray(i.goal)&&(s.push(i.goal[0]),l.push(i.goal[1]));const h=.15;let d=Math.min(...s)-h,c=Math.max(...s)+h,p=Math.min(...l)-h,m=Math.max(...l)+h;const f=(c-d)/a,g=(m-p)/n,u=Math.max(f,g/2,.02),y=(d+c)/2,w=(p+m)/2;d=y-u*a/2,c=y+u*a/2,p=w-u*n,m=w+u*n;const x=Array.from({length:n},()=>Array(a).fill(" ")),b=(e,t,o,r=!0)=>{const s=((e,t)=>{const o=Math.floor((e-d)/(c-d)*a),r=Math.floor((m-t)/(m-p)*n);return r>=0&&r<n&&o>=0&&o<a?[r,o]:null})(e,t);s&&(r||" "===x[s[0]][s[1]])&&(x[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++)b(e.pos[0],e.pos[1]-e.size[1]+2*e.size[1]*o/t,"#")}t.markers.forEach((e,t)=>{b(e[0],e[1],String((t+1)%10))}),Array.isArray(i.goal)&&!t.markers.length&&b(i.goal[0],i.goal[1],"G");const $=e()?"·":".",M=r.filter(e=>e[0]<=o+1e-9);for(const e of M.slice(0,-1))b(e[1],e[2],$,!1);b(0,0,"S");const v=null!=t.fallen_at&&o>=t.fallen_at,F=M[M.length-1];F&&b(F[1],F[2],v?"X":"D");const A=e=>"#"===e?chalk.white(e):"S"===e?chalk.green(e):"D"===e?chalk.bold.yellow(e):"X"===e?chalk.bold.red(e):e===$?chalk.cyan(e):/[0-9G]/.test(e)?chalk.magenta(e):e,_=chalk.gray(` +${"-".repeat(a)}+`),k=e=>e>=.1?e.toFixed(2):e.toFixed(3),S=chalk.gray(` scale: → 1 character ≈ ${k(u)} m · ↓ 1 line ≈ ${k(2*u)} m · whole box ≈ ${(u*a).toFixed(1)} × ${(2*u*n).toFixed(1)} m`),z=new Map;for(let e=.5*Math.ceil(p/.5);e<=m;e+=.5){const t=Math.floor((m-e)/(m-p)*n);t>=0&&t<n&&!z.has(t)&&z.set(t,`y ${e.toFixed(1)}`)}const T=Array(a+8).fill(" "),X=Array(a).fill("-");for(let e=.5*Math.ceil(d/.5);e<=c;e+=.5){const t=Math.floor((e-d)/(c-d)*a);if(t<0||t>=a)continue;X[t]="+";const o=e.toFixed(1);for(let e=0;e<o.length&&t+3+e<T.length;e++)T[t+3+e]=o[e]}return[_,...x.map((e,t)=>chalk.gray(" |")+e.map(A).join("")+chalk.gray("|")+(z.has(t)?chalk.gray(` ${z.get(t)}`):"")),chalk.gray(` +${X.join("")}+`),chalk.gray(`${T.join("").trimEnd()} x (m)`),S]}export function stripFrame(t,o,a=56,n=9){const r=traceKind(t),s=e=>"nod"===r?-e[5]:e[4],l=t.goal,i="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"}]:[],h=t.samples.map(s),d=Math.min(...h,...i.map(e=>e.v))-.05,c=Math.max(...h,...i.map(e=>e.v))+.05,p=e=>Math.max(0,Math.min(n-1,Math.round((c-e)/(c-d)*(n-1)))),m=Array.from({length:n},()=>Array(a).fill(" ")),f=new Map;for(const e of i){const t=p(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[p(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 ↓",y=[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("");y.push(chalk.gray(" |")+o+(f.has(t)?chalk.gray(` ${f.get(t)}`):""))}),y.push(chalk.gray(` +${"-".repeat(a)}> time`)),y.push(chalk.gray(` 0 s${" ".repeat(Math.max(1,a-8))}${t.seconds} s`)),y}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=>`[2K${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.
|
|
3
|
+
"version": "2.19.673",
|
|
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",
|