icoa-cli 2.19.674 β 2.19.676
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{createHash as e}from"node:crypto";import{existsSync as o,mkdirSync as t,readFileSync as s,statSync as n,writeFileSync as r}from"node:fs";import{homedir as a}from"node:os";import{join as l}from"node:path";import chalk from"chalk";import{runInteractive as i}from"../lib/interactive-spawn.js";import{lazyJson as c}from"../lib/lazy-assets.js";import{setNickname as g}from"../lib/learn-ai.js";import{syncCardFeedback as u}from"../lib/learn-curricula.js";import{contestStart as d,contestSubmit as m}from"../lib/learn-contest.js";import{logCommand as b}from"../lib/logger.js";import{mujocoPaths as p,probeMujoco as h}from"../lib/mujoco-setup.js";import{makeReplAsker as y}from"../lib/repl-asker.js";import{playTrace as f,traceLegend as k}from"../lib/duck-trace.js";import{ARENA_VI_FLAGS as w}from"../lib/vi-flags.js";import{runWithTrace as $}from"../lib/duck-trace-run.js";import{emptyDynamics as v,foldEditSession as S,isEmpty as x}from"../lib/arena-edit-dynamics.js";import{startEditSampler as j}from"../lib/edit-sampler.js";import{consumeLineDynamics as _}from"../lib/input-dynamics.js";import{printCliError as N,resolveEngineDir as D}from"./duck.js";const C={list:"list",ls:"list",problems:"list",read:"read",open:"read",show:"read",knobs:"read",template:"read",templates:"read",edit:"edit",e:"edit",vi:"edit",code:"edit",set:"set",knob:"set",change:"set",run:"run",syntax:"syntax",memo:"memo",reset:"reset",restart:"reset",starter:"reset",note:"memo",report:"memo",feedback:"memo",api:"syntax",docs:"syntax",r:"run",play:"run",submit:"submit",up:"submit",s:"submit",upload:"submit",score:"score",board:"score",rank:"score",ranking:"score",scoreboard:"score",help:"help","?":"help",h:"help",back:"back",quit:"back",q:"back",exit:"back",menu:"menu"};export function normalizeContestVerb(e){const o=e.trim().replace(/^\//,"").split(/\s+/).filter(Boolean);return o.length?/^[1-9]$/.test(o[0])?{verb:"read",args:o}:{verb:C[o[0].toLowerCase()]??"unknown",args:o.slice(1)}:{verb:"unknown",args:[]}}export function closestVerb(e){const o=e.toLowerCase();if(o.length<2)return null;const t=(e,o)=>{const t=Array.from({length:e.length+1},(e,t)=>[t,...Array(o.length).fill(0)]);for(let e=1;e<=o.length;e++)t[0][e]=e;for(let s=1;s<=e.length;s++)for(let n=1;n<=o.length;n++)t[s][n]=Math.min(t[s-1][n]+1,t[s][n-1]+1,t[s-1][n-1]+(e[s-1]===o[n-1]?0:1));return t[e.length][o.length]};let s=null,n=3;for(const e of["list","read","set","edit","run","submit","up","score","syntax","template","help","back","menu"]){const r=t(o,e);r<n&&r<=(e.length<=3?1:2)&&(s=e,n=r)}return s}export function readKnobs(e){const o=[];for(const t of e.split("\n")){const e=/^([A-Z][A-Z0-9_]*)\s*=\s*([^#\n]*?)\s*(?:#\s*(.*))?$/.exec(t);e&&o.push({name:e[1],value:e[2],note:e[3]??""})}return o}export function setKnob(e,o,t){const s=readKnobs(e).find(e=>e.name===o.toUpperCase());if(!s)return{ok:!1,why:"name"};const n=t.trim();if(!/^-?\d+(\.\d+)?$|^-?\.\d+$/.test(n))return{ok:!1,why:"value"};const r=new RegExp(`^(${s.name}\\s*=\\s*)([^#\\n]*?)(\\s*(?:#.*)?)$`,"m");return{ok:!0,src:e.replace(r,(e,o,t,s)=>`${o}${n}${s}`),shown:`${s.name} = ${n}`}}export function hint(e){return e.split(/(\b(?:read \d+|read|run|up|submit|set|edit|list|score|syntax|reset undo|reset)\b)/).map((e,o)=>o%2?chalk.bold.green(e):chalk.gray(e)).join("")}const E=(o,t)=>{const s=e("sha256").update(t.toUpperCase()).digest("hex").slice(0,12);return o?.me?.[s]??null};let M=l(a(),".icoa","duckcup");const T=e=>l(M,`p${e}.py`),A=()=>l(M,"last-submit.json");function O(){try{return Number(JSON.parse(s(A(),"utf-8")).at)||0}catch{return 0}}function P(){try{r(A(),JSON.stringify({at:Date.now()}))}catch{}}export async function runDuckContest(e,C,A){b(`duckcup ${e.slice(0,4)}`);const I=`camp/${C}-board.json`;M=l(a(),".icoa","duckcup",C.replace(/[^a-z0-9-]/gi,""),e.replace(/[^A-Z0-9]/gi,"")),t(M,{recursive:!0});let J=await c(I,8e3,{force:!0});const K=E(J,e);console.log(),console.log(chalk.bold.cyan(`π ${J?.title||A}`)+(K?chalk.bold.white(` Β· Seat ${String(K).padStart(2,"0")}`):""));const q=J?.minutes?`, ${J.minutes} minutes`:"",z=J?.problems?.length??0;console.log(chalk.gray(` ${z?`${z} duck problems`:"Duck problems"}${q}. A problem is worth 500 at first and less the more seats solve it.`)),console.log(chalk.bold.yellow(" Rules: ")+chalk.white("no AI tools Β· no web pages β stay in this terminal Β· no copy-paste Β· no talking or sharing with others.")),console.log(chalk.gray(" A question or a problem? Type ")+chalk.bold.green("memo")+chalk.gray(" β it goes to the organisers. Urgent: raise your hand.")),console.log(chalk.gray(" π¦ checking the engineβ¦"));const L=await D(),Y=h(),B=p(a()).python;L?Y.ok||console.log(chalk.yellow(" No simulator on this machine: ")+chalk.bold.green("mujoco setup")+chalk.yellow(" first for `run` (~45 MB). `submit` still works.")):console.log(chalk.yellow(" The robot engine is not on this machine yet β `run` needs it; `submit` still works."));let V=null,U=[];const Z=new Set;let H=0;const R=async()=>{const t=await d(e,1,1);if(!t.ok||!t.data)return"no_contest"===t.code||"no_slot"===t.code?console.log(chalk.yellow(" The Duck Cup has not opened yet.")+chalk.gray(J?.opens_at?` It opens at ${J.opens_at}.`:"")+chalk.gray(" Type ")+chalk.bold.green("list")+chalk.gray(" again when the teacher says go.")):console.log(chalk.yellow(` Could not open the contest: ${t.message??t.code??"no answer"}`)),!1;V=t.data,U=t.data.problems;for(const e of t.data.solved??[])Z.add(e);return U.forEach((e,t)=>{!o(T(t+1))&&e.starter&&r(T(t+1),e.starter)}),!0},W=()=>{const o=J?.problems??[];console.log(),console.log(chalk.bold.white(` The ${U.length} problems`)+" "+function(e){if(!e)return"";const o=Date.parse(e)-Date.now();if(!(o>0))return chalk.red("time is up");const t=Math.floor(o/6e4);return chalk.yellow(`β± ${Math.floor(t/60)}:${String(t%60).padStart(2,"0")} left`)}(J?.ends_iso??V?.deadline));const t=E(J,e),s=J?.rows?.find(e=>e.seat===t);U.forEach((e,t)=>{const n=o.find(e=>e.n===t+1),r=Z.has(e.id)?chalk.green("β
"):"β¬",a=e.knobs?chalk.magenta("knobs"):chalk.cyan("code ");console.log(` ${r} ${chalk.bold.white(String(t+1))} ${a} ${chalk.white((e.title??e.id).padEnd(26))} `+chalk.gray(`${(e.level??"").padEnd(9)} `)+(n?chalk.yellow(`${String(n.value).padStart(3)} pts`)+chalk.gray(` Β· ${n.solves} solved`):"")+(e.points_max?chalk.cyan(` Β· pays by points, your best ${s?.best?.[t]??0}/${e.points_max}`):e.time_full?chalk.cyan(" Β· pays by time, your best "+(null!=s?.best?.[t]?`${s.best[t]} s`:"β")):""))}),console.log(hint(" βΈ read 1 Β· knobs: set NAME value β run β up Β· code: edit β run β submit Β· score"))},Q=e=>{const o=Number(e[0]);return Number.isInteger(o)&&o>=1&&o<=U.length?(H=o,o):H},F=e=>{const t=U[e-1];console.log(),console.log(chalk.bold.cyan(` Problem ${e} Β· ${t.title??t.id}`)+chalk.gray(` (${t.level??""}${t.knobs?" Β· knobs":" Β· code"})`));for(const e of String(t.statement??"").split("\n"))console.log(chalk.white(` ${e}`));if(t.knobs){const n=o(T(e))?s(T(e),"utf-8"):String(t.starter??"");console.log(chalk.bold.white(" Your knobs now:"));for(const e of readKnobs(n))console.log(` ${chalk.bold.green(e.name.padEnd(6))} = ${chalk.yellow(e.value.padEnd(6))} ${chalk.gray(e.note)}`);console.log(chalk.gray(` βΈ set ${readKnobs(n)[0]?.name??"NAME"} 3 β run β up (edit shows the whole file)`))}else console.log(chalk.gray(` βΈ edit β run β submit (your file: ${T(e)})`))},G=()=>U.length?H||(console.log(chalk.gray(" Pick a problem first: ")+chalk.bold.green("read 1")+chalk.gray(` (1β${U.length||6})`)),0):(console.log(chalk.gray(" The problems are not open yet β ")+chalk.bold.green("list")),0),X=async()=>{if(J=await c(I,8e3,{force:!0})??J,!J?.rows)return void console.log(chalk.gray(" The scoreboard is not up yet."));const o=E(J,e);console.log(),console.log(chalk.bold.white(" π Scoreboard")+chalk.gray(` (updated ${J.updated??""} Β· every minute)`));const t=J.problems??[];console.log(chalk.gray(" # Seat Nickname Score ")+t.map(e=>chalk.gray(`P${e.n}`.padEnd(4))).join(""));const s=J.rows;s.length||console.log(chalk.gray(" (no problem solved yet β the board refreshes every minute)"));const n=s.slice(0,12),r=s.findIndex(e=>e.seat===o);r>=12&&n.push(s[r]);for(const e of n){const t=s.indexOf(e),n=` ${String(t+1).padStart(3)} ${String(e.seat).padStart(4)} ${(e.nick||"β").slice(0,16).padEnd(16)} ${String(e.score).padStart(5)} `+e.solved.map(e=>e?"x ":". ").join("");console.log(e.seat===o?chalk.bold.yellow(`${n} β you`):chalk.white(n))}console.log(chalk.gray(" Problem values now: ")+t.map(e=>chalk.yellow(`P${e.n} ${e.value}`)+chalk.gray(` (${e.solves})`)).join(chalk.gray(" Β· ")))},ee=()=>{console.log(),console.log(chalk.bold.white(" Commands"));const e=(e,o)=>console.log(` ${chalk.bold.green(e.padEnd(16))}${chalk.gray(o)}`);e("list","the problems, their points now, β
= yours"),e("read 2","open problem 2 (or just type 2)"),e("set DEPTH 0.4","knobs problems: change one knob"),e("edit","open the whole file in vi (any problem)"),e("run","try it here β the duck is drawn in this terminal"),e("run --seeds","try it on 3 other courses (is it steady?)"),e("submit / up","send it to the judge (same thing) Β· one every 30 s"),e("score","the scoreboard (seats and nicknames)"),e("syntax","everything control() can return, and what sense holds"),e("reset","start this problem again from its first file (reset undo = take it back)"),e("memo","a note for the organisers (a problem, a question)"),e("back","leave (come back: type this token again)")},oe=y(),te=oe.ask,se=new Map,ne=new Map,re=new Map,ae=new Map,le={lines:0,pastes:0,pasteChars:0,suspectLines:0,focusOuts:0,awayMs:0},ie=e=>{e&&(le.lines++,le.pastes+=e.pastes,le.pasteChars+=e.pasteChars,e.suspectPaste&&le.suspectLines++,le.focusOuts+=e.focusOuts??0,le.awayMs+=e.awayMs??0)};let ce="",ge=Date.now();const ue=async()=>{Date.now()-ge>2e4&&(ge=Date.now(),J=await c(I,3e3,{force:!0})??J);const e=J?.broadcast;e?.text&&e.ts!==ce&&(ce=e.ts,console.log(),console.log(chalk.bold.yellow(` π’ Organisers: ${e.text}`)),console.log())},de=l(M,"nick.json"),me=(()=>{try{return JSON.parse(s(de,"utf-8"))}catch{return{}}})(),be=o=>{me[e]=o;try{r(de,JSON.stringify(me))}catch{}};if(!me[e]){console.log(),console.log(chalk.bold.white(" Pick a nickname for the scoreboard.")),console.log(chalk.gray(" English letters and digits, 3β16 long, starting with a letter β e.g. QuackStorm7.")),console.log(chalk.gray(" Not your real name. It is checked, and it cannot be changed later."));for(let o=0;o<8;o++){const o=await te(chalk.bold.cyan(" nickname > "));if(null===o)return"back";const t=o.trim();if(!t)continue;const s=await g({token:e,nickname:t});if(s.ok&&s.nickname){be(s.nickname),console.log(chalk.green(` β You are ${s.nickname} on the scoreboard.`));break}const n="already_set"===s.code?/: (\S+)$/.exec(s.message??""):null;if(n){be(n[1]),console.log(chalk.green(` β You are ${n[1]} on the scoreboard.`));break}if("judge_unavailable"===s.code||"network"===s.code){console.log(chalk.gray(" The name check is busy β go ahead; you will be asked again next time."));break}console.log(chalk.yellow(` β ${s.message??"That name did not pass β pick another."}`))}}const pe=me[e];pe&&console.log(chalk.gray(` You: ${chalk.bold.white(pe)}${K?` Β· Seat ${String(K).padStart(2,"0")}`:""}`)),await R(),U.length&&W(),ee();let he=0;try{for(;;){await ue();const t=await te(chalk.bold.cyan(`icoa duckcup${H?` p${H}`:""}> `));if(ie(_()),null===t)return"back";if(!t.trim())continue;const{verb:a,args:g}=normalizeContestVerb(t);switch("unknown"!==a&&(he=0),a){case"back":return"back";case"menu":return"menu";case"reset":{const e=G();if(!e)break;const t=U[e-1],n=T(e),a=`${n}.bak`;if("undo"===g[0]){if(!o(a)){console.log(chalk.gray(" Nothing to undo β there is no saved file from a reset."));break}const t=o(n)?s(n,"utf-8"):"";r(n,s(a,"utf-8")),r(a,t),console.log(chalk.green(` β© Problem ${e}: your file is back.`)+hint(" βΈ run to try it"));break}console.log(chalk.yellow(` This puts problem ${e} back to its starting file.`)+chalk.gray(" Your file is kept (reset undo brings it back)."));const l=await te(chalk.bold.cyan(" type yes to reset > "));if(null===l)return"back";if(!/^(y|yes)$/i.test(l.trim())){console.log(chalk.gray(" Not reset β your file is unchanged."));break}o(n)&&r(a,s(n,"utf-8")),r(n,String(t.starter??"")),b(`duckcup reset p${e}`),console.log(chalk.green(` β Problem ${e} is back to the starting file.`)+hint(" βΈ read Β· run Β· reset undo"));break}case"memo":{let o=g.join(" ").trim();if(!o){console.log(chalk.gray(` Write one line for the organisers${H?` (about problem ${H})`:""}. Empty line = cancel.`));const e=await te(chalk.bold.cyan(" memo > "));if(null===e)return"back";o=e.trim()}if(!o){console.log(chalk.gray(" Nothing sent."));break}const t=l(M,"memos.json"),n=(()=>{try{return JSON.parse(s(t,"utf-8"))}catch{return[]}})(),a={ts:(new Date).toISOString(),problem:H,text:o,sent:!1};n.push(a),r(t,JSON.stringify(n,null,1)),b(`duckcup memo p${H} β ${o}`);try{a.sent=await u(e,{curriculum_id:C,card_number:H,feedback_text:o}),a.sent&&r(t,JSON.stringify(n,null,1))}catch{}console.log(chalk.green(` π ${a.sent?"Sent to the organisers":"Saved on this computer (could not send yet)"}.`)+chalk.gray(" There is no reply in the room β if it is urgent, raise your hand."));break}case"syntax":{const e=L&&o(l(L,"syntax.txt"))?s(l(L,"syntax.txt"),"utf-8"):"";console.log(chalk.gray(e||" (no syntax sheet in the engine package yet β `duck` once to fetch it)"));break}case"help":ee();break;case"list":if(!U.length&&!await R())break;J=await c(I,8e3,{force:!0})??J,W();break;case"score":await X();break;case"read":{if(!U.length&&!await R())break;const e=g.length?Q(g):H;if(!e||g.length&&Number(g[0])!==e){console.log(chalk.yellow(` read 1 β¦ read ${U.length||5}`));break}F(e);break}case"set":{const e=G();if(!e)break;if(!U[e-1].knobs){console.log(chalk.gray(` Problem ${e} is a code problem β `)+chalk.bold.green("edit")+chalk.gray(" the file."));break}if(g.length<2){console.log(chalk.gray(" set <KNOB> <number> β e.g. ")+chalk.bold.green("set DEPTH 0.4")+chalk.gray(" Β· read lists the knobs"));break}const o=setKnob(s(T(e),"utf-8"),g[0],g[1]);if(!o.ok){console.log(chalk.yellow("name"===o.why?` β No knob called "${g[0]}" β read lists them`:` β "${g[1]}" is not a number`));break}r(T(e),o.src),b(`duckcup set p${e} ${g.join(" ")}`),re.set(e,(re.get(e)??0)+1),console.log(chalk.green(` β ${o.shown}`)+hint(" βΈ run to try it Β· up to send it"));break}case"edit":{const e=g.length?Q(g):G();if(!e)break;console.log(chalk.gray(" vi survival: i = edit Β· Esc = stop editing Β· :wq = save and leave Β· :q! = discard"));const o=e=>{try{return n(e).size}catch{return 0}},t=o(T(e)),s=Date.now(),r=j(T(e));await i("vi",[...w,T(e)]);const a=r.stop(),l={ms:Date.now()-s,bytesBefore:t,bytesAfter:o(T(e))};se.set(e,S(se.get(e)??v(),l)),a.ticks>0&&ne.set(e,[...ne.get(e)??[],a].slice(-8)),b(`duckcup edit-done p${e}`,{...l,...a.ticks>0?{samples:a}:{}});break}case"run":{const e=g.length?Q(g):G();if(!e)break;const o=U[e-1];if(!L||!Y.ok){console.log(chalk.gray(" No simulator here β ")+chalk.bold.green("mujoco setup")+chalk.gray("; `submit` still works."));break}if(ae.set(e,(ae.get(e)??0)+1),g.includes("--seeds")||g.includes("seeds")){const t=[44,55,101];console.log(chalk.gray(` Problem ${e} on ${t.length} other courses (no picture) β¦`));let s=0;for(const n of t){const t=$(B,L,T(e),String(o.scenario),18e4,n);if(!0!==t.ok){N(t);break}t.pass&&s++,console.log((t.pass?chalk.green(" β "):chalk.yellow(" β "))+chalk.gray(`course ${n}: `)+chalk.white(String(t.detail??"")))}console.log(chalk.bold.white(` ${s}/${t.length} courses passed.`)+hint(s===t.length?" βΈ robust β up to submit":" βΈ make it steadier, then run --seeds again"));break}const t=g.indexOf("--seed"),s=t>=0&&Number.isInteger(Number(g[t+1]))?Number(g[t+1]):void 0;process.stdout.write(chalk.gray(` Problem ${e} Β· ${o.title}${null!=s?` Β· course ${s}`:""} β¦ `));const n=$(B,L,T(e),String(o.scenario),18e4,s);if(console.log(),!0!==n.ok){N(n);break}for(const e of(n.prints??[]).slice(0,8))console.log(chalk.white(` ${e}`));const r=n.trace;if(r&&(await f(r),console.log(chalk.gray(k(r,{none:!!o.no_legend})))),o.points_max&&String(n.detail??"").includes(" Β· ")){const[e,o]=String(n.detail).split(" = ");for(const o of e.split(" Β· ")){const e=o.includes("β")||/time \+[1-9]/.test(o);console.log((e?chalk.green(" β "):chalk.gray(" Β· "))+chalk.white(o.replace(/[ββ]/g," ").trim()))}console.log(chalk.bold.cyan(` π― here: ${o??""} points`)+chalk.gray(" β the judge uses 3 other courses (run --seeds to try 3)"))}else console.log((n.pass?chalk.green(" β "):chalk.yellow(" β "))+chalk.white(String(n.detail??""))+chalk.gray(null!=n.fallen_at?` Β· fell at ${n.fallen_at} s`:""));console.log(hint(n.pass?" βΈ looks good here β up / submit to send it to the judge":o.knobs?" βΈ set a knob and run again":" βΈ edit and run again"));break}case"submit":{const o=g.length?Q(g):G();if(!o)break;const t=U[o-1];if(Z.has(t.id)&&!t.points_max&&!t.time_full){console.log(chalk.green(` β
Problem ${o} is already solved β its points are yours. `)+chalk.gray("list"));break}if(J=await c(I,3e3,{force:!0})??J,J?.ends_iso&&Date.now()>Date.parse(J.ends_iso)){console.log(chalk.red(" β± Time is up β the Duck Cup has closed. ")+chalk.gray("score shows the final board."));break}const n=Math.ceil((O()+3e4-Date.now())/1e3);if(n>0){console.log(chalk.yellow(` β± One submit every 30 seconds β ${n} s to go. `)+chalk.gray("Meanwhile: run here as often as you like."));break}console.log(chalk.gray(` β judging problem ${o} on the serverβ¦ 5β10 s`)),P();const r=se.get(o),a={room:{...le},sets:re.get(o)??0,runs:ae.get(o)??0,...r&&!x(r)?{edit:r}:{},...ne.get(o)?.length?{samples:ne.get(o)}:{}},l=await m(e,1,t.id,s(T(o),"utf-8"),1,a);if(!l.ok||!l.data){console.log(chalk.yellow(` No verdict came back: ${l.message??l.code??""}`));break}const i=l.data;let u=0;const d=[...new Set([...(i.report??[]).slice(0,3),...i.note?[i.note]:[]])].map(e=>e.replace(/seed \d+:/g,()=>`course ${++u}:`));for(const e of d)console.log(chalk.gray(` ${e}`));if(t.time_full&&!i.late){const e=/reached the goal at ([\d.]+) s/.exec(d.join(" ")),o=t.time_max??40;if("AC"===i.verdict&&e){Z.add(t.id);const s=Number(e[1]),n=s<=t.time_full?1:Math.max(.1,1-.9*(s-t.time_full)/(o-t.time_full));console.log(chalk.bold.cyan(` π Arrived in ${s} s β ${Math.round(100*n)}% of this problem's value`)+chalk.gray(` (full value at ${t.time_full} s or faster).`)),console.log(hint(" βΈ your best time counts β edit, run, submit again to go faster"))}else console.log(chalk.yellow(" β Did not reach the goal yet β 0 for now. ")+hint("edit, run, submit again"));break}if(t.points_max&&!i.late){const e=[...d.join(" ").matchAll(/= (\d+)\/\d+/g)].map(e=>Number(e[1])).sort((e,o)=>e-o),o=e.length?e[Math.floor(e.length/2)]:0;"AC"===i.verdict&&Z.add(t.id),console.log(chalk.bold.cyan(` π― This try: ${o}/${t.points_max} points`)+chalk.gray(" (the middle of your 3 courses). This problem pays its value Γ your best / ")+chalk.gray(`${t.points_max}.`)),console.log(hint(o>=20?" βΈ counts as solved (20+). edit, run, submit again to raise your best β score shows it":" βΈ 20+ points also counts it as solved. edit, run, submit again"));break}if("AC"===i.verdict||i.already_ac){Z.add(t.id);const e=J?.problems?.find(e=>e.n===o);console.log(chalk.green(` β
Solved problem ${o}!`)+chalk.gray(e?` It is worth ${e.value} now; the board updates within a minute β `:" ")+chalk.bold.green("score"));const s=U.findIndex(e=>!Z.has(e.id));s>=0&&console.log(hint(` βΈ next: read ${s+1}`))}else i.late||String(i.verdict).startsWith("LATE")?console.log(chalk.red(" β± Time is up β this one was recorded but does not count.")):console.log(chalk.yellow(` β ${i.verdict} β not yet. `)+hint(t.knobs?"set a knob, run, up again":"edit, run, submit again (reset = start over)"));break}default:{he++;const e=t.trim().split(/\s+/)[0],o=closestVerb(e);if(o){console.log(chalk.yellow(" Did you mean ")+chalk.bold.green(o)+chalk.yellow("?"));break}console.log(chalk.yellow(` Don't know "${e}".`)+chalk.gray(" Commands: list Β· read 1 Β· set Β· edit Β· run Β· submit/up Β· score Β· memo Β· help Β· back")),he>=3&&ee()}}}}finally{oe.close()}}
|
|
1
|
+
import{createHash as e}from"node:crypto";import{existsSync as o,mkdirSync as t,readFileSync as s,statSync as n,writeFileSync as r}from"node:fs";import{homedir as a}from"node:os";import{join as l}from"node:path";import chalk from"chalk";import{runInteractive as i}from"../lib/interactive-spawn.js";import{lazyJson as c}from"../lib/lazy-assets.js";import{setNickname as u}from"../lib/learn-ai.js";import{syncCardFeedback as g}from"../lib/learn-curricula.js";import{contestStart as d,contestSubmit as m}from"../lib/learn-contest.js";import{logCommand as b}from"../lib/logger.js";import{mujocoPaths as p,probeMujoco as h}from"../lib/mujoco-setup.js";import{makeReplAsker as y}from"../lib/repl-asker.js";import{playTrace as f,traceLegend as k}from"../lib/duck-trace.js";import{ARENA_VI_FLAGS as w}from"../lib/vi-flags.js";import{runWithTrace as $}from"../lib/duck-trace-run.js";import{emptyDynamics as v,foldEditSession as S,isEmpty as x}from"../lib/arena-edit-dynamics.js";import{startEditSampler as _}from"../lib/edit-sampler.js";import{consumeLineDynamics as j}from"../lib/input-dynamics.js";import{printCliError as N,resolveEngineDir as D}from"./duck.js";const E={list:"list",ls:"list",problems:"list",read:"read",open:"read",show:"read",knobs:"read",template:"read",templates:"read",edit:"edit",e:"edit",vi:"edit",code:"edit",set:"set",knob:"set",change:"set",run:"run",syntax:"syntax",memo:"memo",reset:"reset",restart:"reset",starter:"reset",note:"memo",report:"memo",feedback:"memo",api:"syntax",docs:"syntax",r:"run",play:"run",submit:"submit",up:"submit",s:"submit",upload:"submit",score:"score",board:"score",rank:"score",ranking:"score",scoreboard:"score",help:"help","?":"help",h:"help",back:"back",quit:"back",q:"back",exit:"back",menu:"menu"};export function normalizeContestVerb(e){const o=e.trim().replace(/^\//,"").split(/\s+/).filter(Boolean);return o.length?/^[1-9]$/.test(o[0])?{verb:"read",args:o}:{verb:E[o[0].toLowerCase()]??"unknown",args:o.slice(1)}:{verb:"unknown",args:[]}}export function closestVerb(e){const o=e.toLowerCase();if(o.length<2)return null;const t=(e,o)=>{const t=Array.from({length:e.length+1},(e,t)=>[t,...Array(o.length).fill(0)]);for(let e=1;e<=o.length;e++)t[0][e]=e;for(let s=1;s<=e.length;s++)for(let n=1;n<=o.length;n++)t[s][n]=Math.min(t[s-1][n]+1,t[s][n-1]+1,t[s-1][n-1]+(e[s-1]===o[n-1]?0:1));return t[e.length][o.length]};let s=null,n=3;for(const e of["list","read","set","edit","run","submit","up","score","syntax","template","help","back","menu"]){const r=t(o,e);r<n&&r<=(e.length<=3?1:2)&&(s=e,n=r)}return s}export function readKnobs(e){const o=[];for(const t of e.split("\n")){const e=/^([A-Z][A-Z0-9_]*)\s*=\s*([^#\n]*?)\s*(?:#\s*(.*))?$/.exec(t);e&&o.push({name:e[1],value:e[2],note:e[3]??""})}return o}export function setKnob(e,o,t){const s=readKnobs(e).find(e=>e.name===o.toUpperCase());if(!s)return{ok:!1,why:"name"};const n=t.trim();if(!/^-?\d+(\.\d+)?$|^-?\.\d+$/.test(n))return{ok:!1,why:"value"};const r=new RegExp(`^(${s.name}\\s*=\\s*)([^#\\n]*?)(\\s*(?:#.*)?)$`,"m");return{ok:!0,src:e.replace(r,(e,o,t,s)=>`${o}${n}${s}`),shown:`${s.name} = ${n}`}}export function hint(e){return e.split(/(\b(?:read \d+|read|run|up|submit|set|edit|list|score|syntax|reset undo|reset)\b)/).map((e,o)=>o%2?chalk.bold.green(e):chalk.gray(e)).join("")}const C=(o,t)=>{const s=e("sha256").update(t.toUpperCase()).digest("hex").slice(0,12);return o?.me?.[s]??null};let M=l(a(),".icoa","duckcup");const T=e=>l(M,`p${e}.py`);function A(e){const o=function(e){let o="";try{o=s(T(e),"utf-8")}catch{return[]}const t=[];return o.split("\n").forEach((e,o)=>{e.split("#")[0].includes("___")&&t.push(o+1)}),t}(e);return!!o.length&&(console.log(chalk.yellow(` β ${o.length} blank${o.length>1?"s":""} (___) still empty β line ${o.join(", ")}. `)+hint("edit to fill them, then run")),!0)}const O=()=>l(M,"last-submit.json");function P(){try{return Number(JSON.parse(s(O(),"utf-8")).at)||0}catch{return 0}}function I(){try{r(O(),JSON.stringify({at:Date.now()}))}catch{}}export async function runDuckContest(e,E,O){b(`duckcup ${e.slice(0,4)}`);const J=`camp/${E}-board.json`;M=l(a(),".icoa","duckcup",E.replace(/[^a-z0-9-]/gi,""),e.replace(/[^A-Z0-9]/gi,"")),t(M,{recursive:!0});let K=await c(J,8e3,{force:!0});const q=C(K,e);console.log(),console.log(chalk.bold.cyan(`π ${K?.title||O}`)+(q?chalk.bold.white(` Β· Seat ${String(q).padStart(2,"0")}`):""));const z=K?.minutes?`, ${K.minutes} minutes`:"",L=K?.problems?.length??0;console.log(chalk.gray(` ${L?`${L} duck problems`:"Duck problems"}${z}. A problem is worth 500 at first and less the more seats solve it.`)),console.log(chalk.bold.yellow(" Rules: ")+chalk.white("no AI tools Β· no web pages β stay in this terminal Β· no copy-paste Β· no talking or sharing with others.")),console.log(chalk.gray(" A question or a problem? Type ")+chalk.bold.green("memo")+chalk.gray(" β it goes to the organisers. Urgent: raise your hand.")),console.log(chalk.gray(" π¦ checking the engineβ¦"));const Y=await D(),B=h(),V=p(a()).python;Y?B.ok||console.log(chalk.yellow(" No simulator on this machine: ")+chalk.bold.green("mujoco setup")+chalk.yellow(" first for `run` (~45 MB). `submit` still works.")):console.log(chalk.yellow(" The robot engine is not on this machine yet β `run` needs it; `submit` still works."));let U=null,Z=[];const H=new Set;let R=0;const W=async()=>{const t=await d(e,1,1);if(!t.ok||!t.data)return"no_contest"===t.code||"no_slot"===t.code?console.log(chalk.yellow(" The Duck Cup has not opened yet.")+chalk.gray(K?.opens_at?` It opens at ${K.opens_at}.`:"")+chalk.gray(" Type ")+chalk.bold.green("list")+chalk.gray(" again when the teacher says go.")):console.log(chalk.yellow(` Could not open the contest: ${t.message??t.code??"no answer"}`)),!1;U=t.data,Z=t.data.problems;for(const e of t.data.solved??[])H.add(e);return Z.forEach((e,t)=>{!o(T(t+1))&&e.starter&&r(T(t+1),e.starter)}),!0},Q=()=>{const o=K?.problems??[];console.log(),console.log(chalk.bold.white(` The ${Z.length} problems`)+" "+function(e){if(!e)return"";const o=Date.parse(e)-Date.now();if(!(o>0))return chalk.red("time is up");const t=Math.floor(o/6e4);return chalk.yellow(`β± ${Math.floor(t/60)}:${String(t%60).padStart(2,"0")} left`)}(K?.ends_iso??U?.deadline));const t=C(K,e),s=K?.rows?.find(e=>e.seat===t);Z.forEach((e,t)=>{const n=o.find(e=>e.n===t+1),r=H.has(e.id)?chalk.green("β
"):"β¬",a=e.knobs?chalk.magenta("knobs"):chalk.cyan("code ");console.log(` ${r} ${chalk.bold.white(String(t+1))} ${a} ${chalk.white((e.title??e.id).padEnd(26))} `+chalk.gray(`${(e.level??"").padEnd(9)} `)+(n?chalk.yellow(`${String(n.value).padStart(3)} pts`)+chalk.gray(` Β· ${n.solves} solved`):"")+(e.points_max?chalk.cyan(` Β· pays by points, your best ${s?.best?.[t]??0}/${e.points_max}`):e.time_full?chalk.cyan(" Β· pays by time, your best "+(null!=s?.best?.[t]?`${s.best[t]} s`:"β")):""))}),console.log(hint(" βΈ read 1 Β· knobs: set NAME value β run β up Β· code: edit β run β submit Β· score"))},F=e=>{const o=Number(e[0]);return Number.isInteger(o)&&o>=1&&o<=Z.length?(R=o,o):R},G=e=>{const t=Z[e-1];console.log(),console.log(chalk.bold.cyan(` Problem ${e} Β· ${t.title??t.id}`)+chalk.gray(` (${t.level??""}${t.knobs?" Β· knobs":" Β· code"})`));for(const e of String(t.statement??"").split("\n"))console.log(chalk.white(` ${e}`));if(t.knobs){const n=o(T(e))?s(T(e),"utf-8"):String(t.starter??"");console.log(chalk.bold.white(" Your knobs now:"));for(const e of readKnobs(n))console.log(` ${chalk.bold.green(e.name.padEnd(6))} = ${chalk.yellow(e.value.padEnd(6))} ${chalk.gray(e.note)}`);console.log(chalk.gray(` βΈ set ${readKnobs(n)[0]?.name??"NAME"} 3 β run β up (edit shows the whole file)`))}else console.log(chalk.gray(` βΈ edit β run β submit (your file: ${T(e)})`))},X=()=>Z.length?R||(console.log(chalk.gray(" Pick a problem first: ")+chalk.bold.green("read 1")+chalk.gray(` (1β${Z.length||6})`)),0):(console.log(chalk.gray(" The problems are not open yet β ")+chalk.bold.green("list")),0),ee=async()=>{if(K=await c(J,8e3,{force:!0})??K,!K?.rows)return void console.log(chalk.gray(" The scoreboard is not up yet."));const o=C(K,e);console.log(),console.log(chalk.bold.white(" π Scoreboard")+chalk.gray(` (updated ${K.updated??""} Β· every minute)`));const t=K.problems??[];console.log(chalk.gray(" # Seat Nickname Score ")+t.map(e=>chalk.gray(`P${e.n}`.padEnd(4))).join(""));const s=K.rows;s.length||console.log(chalk.gray(" (no problem solved yet β the board refreshes every minute)"));const n=s.slice(0,12),r=s.findIndex(e=>e.seat===o);r>=12&&n.push(s[r]);for(const e of n){const t=s.indexOf(e),n=` ${String(t+1).padStart(3)} ${String(e.seat).padStart(4)} ${(e.nick||"β").slice(0,16).padEnd(16)} ${String(e.score).padStart(5)} `+e.solved.map(e=>e?"x ":". ").join("");console.log(e.seat===o?chalk.bold.yellow(`${n} β you`):chalk.white(n))}console.log(chalk.gray(" Problem values now: ")+t.map(e=>chalk.yellow(`P${e.n} ${e.value}`)+chalk.gray(` (${e.solves})`)).join(chalk.gray(" Β· ")))},oe=()=>{console.log(),console.log(chalk.bold.white(" Commands"));const e=(e,o)=>console.log(` ${chalk.bold.green(e.padEnd(16))}${chalk.gray(o)}`);e("list","the problems, their points now, β
= yours"),e("read 2","open problem 2 (or just type 2)"),e("set DEPTH 0.4","knobs problems: change one knob"),e("edit","open the whole file in vi (any problem)"),e("run","try it here β the duck is drawn in this terminal"),e("run --seeds","try it on 3 other courses (is it steady?)"),e("submit / up","send it to the judge (same thing) Β· one every 30 s"),e("score","the scoreboard (seats and nicknames)"),e("syntax","everything control() can return, and what sense holds"),e("reset","start this problem again from its first file (reset undo = take it back)"),e("memo","a note for the organisers (a problem, a question)"),e("back","leave (come back: type this token again)")},te=y(),se=te.ask,ne=new Map,re=new Map,ae=new Map,le=new Map,ie={lines:0,pastes:0,pasteChars:0,suspectLines:0,focusOuts:0,awayMs:0},ce=e=>{e&&(ie.lines++,ie.pastes+=e.pastes,ie.pasteChars+=e.pasteChars,e.suspectPaste&&ie.suspectLines++,ie.focusOuts+=e.focusOuts??0,ie.awayMs+=e.awayMs??0)};let ue="",ge=Date.now();const de=async()=>{Date.now()-ge>2e4&&(ge=Date.now(),K=await c(J,3e3,{force:!0})??K);const e=K?.broadcast;e?.text&&e.ts!==ue&&(ue=e.ts,console.log(),console.log(chalk.bold.yellow(` π’ Organisers: ${e.text}`)),console.log())},me=l(M,"nick.json"),be=(()=>{try{return JSON.parse(s(me,"utf-8"))}catch{return{}}})(),pe=o=>{be[e]=o;try{r(me,JSON.stringify(be))}catch{}};if(!be[e]){console.log(),console.log(chalk.bold.white(" Pick a nickname for the scoreboard.")),console.log(chalk.gray(" English letters and digits, 3β16 long, starting with a letter β e.g. QuackStorm7.")),console.log(chalk.gray(" Not your real name. It is checked, and it cannot be changed later."));for(let o=0;o<8;o++){const o=await se(chalk.bold.cyan(" nickname > "));if(null===o)return"back";const t=o.trim();if(!t)continue;const s=await u({token:e,nickname:t});if(s.ok&&s.nickname){pe(s.nickname),console.log(chalk.green(` β You are ${s.nickname} on the scoreboard.`));break}const n="already_set"===s.code?/: (\S+)$/.exec(s.message??""):null;if(n){pe(n[1]),console.log(chalk.green(` β You are ${n[1]} on the scoreboard.`));break}if("judge_unavailable"===s.code||"network"===s.code){console.log(chalk.gray(" The name check is busy β go ahead; you will be asked again next time."));break}console.log(chalk.yellow(` β ${s.message??"That name did not pass β pick another."}`))}}const he=be[e];he&&console.log(chalk.gray(` You: ${chalk.bold.white(he)}${q?` Β· Seat ${String(q).padStart(2,"0")}`:""}`)),await W(),Z.length&&Q(),oe();let ye=0;try{for(;;){await de();const t=await se(chalk.bold.cyan(`icoa duckcup${R?` p${R}`:""}> `));if(ce(j()),null===t)return"back";if(!t.trim())continue;const{verb:a,args:u}=normalizeContestVerb(t);switch("unknown"!==a&&(ye=0),a){case"back":return"back";case"menu":return"menu";case"reset":{const e=X();if(!e)break;const t=Z[e-1],n=T(e),a=`${n}.bak`;if("undo"===u[0]){if(!o(a)){console.log(chalk.gray(" Nothing to undo β there is no saved file from a reset."));break}const t=o(n)?s(n,"utf-8"):"";r(n,s(a,"utf-8")),r(a,t),console.log(chalk.green(` β© Problem ${e}: your file is back.`)+hint(" βΈ run to try it"));break}console.log(chalk.yellow(` This puts problem ${e} back to its starting file.`)+chalk.gray(" Your file is kept (reset undo brings it back)."));const l=await se(chalk.bold.cyan(" type yes to reset > "));if(null===l)return"back";if(!/^(y|yes)$/i.test(l.trim())){console.log(chalk.gray(" Not reset β your file is unchanged."));break}o(n)&&r(a,s(n,"utf-8")),r(n,String(t.starter??"")),b(`duckcup reset p${e}`),console.log(chalk.green(` β Problem ${e} is back to the starting file.`)+hint(" βΈ read Β· run Β· reset undo"));break}case"memo":{let o=u.join(" ").trim();if(!o){console.log(chalk.gray(` Write one line for the organisers${R?` (about problem ${R})`:""}. Empty line = cancel.`));const e=await se(chalk.bold.cyan(" memo > "));if(null===e)return"back";o=e.trim()}if(!o){console.log(chalk.gray(" Nothing sent."));break}const t=l(M,"memos.json"),n=(()=>{try{return JSON.parse(s(t,"utf-8"))}catch{return[]}})(),a={ts:(new Date).toISOString(),problem:R,text:o,sent:!1};n.push(a),r(t,JSON.stringify(n,null,1)),b(`duckcup memo p${R} β ${o}`);try{a.sent=await g(e,{curriculum_id:E,card_number:R,feedback_text:o}),a.sent&&r(t,JSON.stringify(n,null,1))}catch{}console.log(chalk.green(` π ${a.sent?"Sent to the organisers":"Saved on this computer (could not send yet)"}.`)+chalk.gray(" There is no reply in the room β if it is urgent, raise your hand."));break}case"syntax":{const e=(Y&&o(l(Y,"syntax.txt"))?s(l(Y,"syntax.txt"),"utf-8"):"").split(/\n\s*words at icoa duck>/)[0].replace(/\s*\(card 7 only[^)]*\)/," (not used in these problems)").trimEnd();console.log(chalk.gray(e||" (no syntax sheet in the engine package yet β `duck` once to fetch it)"));break}case"help":oe();break;case"list":if(!Z.length&&!await W())break;K=await c(J,8e3,{force:!0})??K,Q();break;case"score":await ee();break;case"read":{if(!Z.length&&!await W())break;const e=u.length?F(u):R;if(!e||u.length&&Number(u[0])!==e){console.log(chalk.yellow(` read 1 β¦ read ${Z.length||5}`));break}G(e);break}case"set":{const e=X();if(!e)break;if(!Z[e-1].knobs){console.log(chalk.gray(` Problem ${e} is a code problem β `)+chalk.bold.green("edit")+chalk.gray(" the file."));break}if(u.length<2){console.log(chalk.gray(" set <KNOB> <number> β e.g. ")+chalk.bold.green("set DEPTH 0.4")+chalk.gray(" Β· read lists the knobs"));break}const o=setKnob(s(T(e),"utf-8"),u[0],u[1]);if(!o.ok){console.log(chalk.yellow("name"===o.why?` β No knob called "${u[0]}" β read lists them`:` β "${u[1]}" is not a number`));break}r(T(e),o.src),b(`duckcup set p${e} ${u.join(" ")}`),ae.set(e,(ae.get(e)??0)+1),console.log(chalk.green(` β ${o.shown}`)+hint(" βΈ run to try it Β· up to send it"));break}case"edit":{const e=u.length?F(u):X();if(!e)break;console.log(chalk.gray(" vi survival: i = edit Β· Esc = stop editing Β· :wq = save and leave Β· :q! = discard"));const o=e=>{try{return n(e).size}catch{return 0}},t=o(T(e)),s=Date.now(),r=_(T(e));await i("vi",[...w,T(e)]);const a=r.stop(),l={ms:Date.now()-s,bytesBefore:t,bytesAfter:o(T(e))};ne.set(e,S(ne.get(e)??v(),l)),a.ticks>0&&re.set(e,[...re.get(e)??[],a].slice(-8)),b(`duckcup edit-done p${e}`,{...l,...a.ticks>0?{samples:a}:{}});break}case"run":{const e=u.length?F(u):X();if(!e)break;const o=Z[e-1];if(!Y||!B.ok){console.log(chalk.gray(" No simulator here β ")+chalk.bold.green("mujoco setup")+chalk.gray("; `submit` still works."));break}if(le.set(e,(le.get(e)??0)+1),A(e))break;if(u.includes("--seeds")||u.includes("seeds")){const t=[44,55,101];console.log(chalk.gray(` Problem ${e} on ${t.length} other courses (no picture) β¦`));let s=0;for(const n of t){const t=$(V,Y,T(e),String(o.scenario),18e4,n);if(!0!==t.ok){N(t);break}t.pass&&s++,console.log((t.pass?chalk.green(" β "):chalk.yellow(" β "))+chalk.gray(`course ${n}: `)+chalk.white(String(t.detail??"")))}console.log(chalk.bold.white(` ${s}/${t.length} courses passed.`)+hint(s===t.length?" βΈ robust β up to submit":" βΈ make it steadier, then run --seeds again"));break}const t=u.indexOf("--seed"),s=t>=0&&Number.isInteger(Number(u[t+1]))?Number(u[t+1]):void 0;process.stdout.write(chalk.gray(` Problem ${e} Β· ${o.title}${null!=s?` Β· course ${s}`:""} β¦ `));const n=$(V,Y,T(e),String(o.scenario),18e4,s);if(console.log(),!0!==n.ok){N(n);break}for(const e of(n.prints??[]).slice(0,8))console.log(chalk.white(` ${e}`));const r=n.trace;if(r&&(await f(r),console.log(chalk.gray(k(r,{none:!!o.no_legend})))),o.points_max&&String(n.detail??"").includes(" Β· ")){const[e,o]=String(n.detail).split(" = ");for(const o of e.split(" Β· ")){const e=o.includes("β")||/time \+[1-9]/.test(o);console.log((e?chalk.green(" β "):chalk.gray(" Β· "))+chalk.white(o.replace(/[ββ]/g," ").trim()))}console.log(chalk.bold.cyan(` π― here: ${o??""} points`)+chalk.gray(" β the judge uses 3 other courses (run --seeds to try 3)"))}else console.log((n.pass?chalk.green(" β "):chalk.yellow(" β "))+chalk.white(String(n.detail??""))+chalk.gray(null!=n.fallen_at?` Β· fell at ${n.fallen_at} s`:""));console.log(hint(n.pass?" βΈ looks good here β up / submit to send it to the judge":o.knobs?" βΈ set a knob and run again":" βΈ edit and run again"));break}case"submit":{const o=u.length?F(u):X();if(!o)break;const t=Z[o-1];if(H.has(t.id)&&!t.points_max&&!t.time_full){console.log(chalk.green(` β
Problem ${o} is already solved β its points are yours. `)+chalk.gray("list"));break}if(K=await c(J,3e3,{force:!0})??K,K?.ends_iso&&Date.now()>Date.parse(K.ends_iso)){console.log(chalk.red(" β± Time is up β the Duck Cup has closed. ")+chalk.gray("score shows the final board."));break}if(A(o))break;const n=Math.ceil((P()+3e4-Date.now())/1e3);if(n>0){console.log(chalk.yellow(` β± One submit every 30 seconds β ${n} s to go. `)+chalk.gray("Meanwhile: run here as often as you like."));break}console.log(chalk.gray(` β judging problem ${o} on the serverβ¦ 5β10 s`)),I();const r=ne.get(o),a={room:{...ie},sets:ae.get(o)??0,runs:le.get(o)??0,...r&&!x(r)?{edit:r}:{},...re.get(o)?.length?{samples:re.get(o)}:{}},l=await m(e,1,t.id,s(T(o),"utf-8"),1,a);if(!l.ok||!l.data){console.log(chalk.yellow(` No verdict came back: ${l.message??l.code??""}`));break}const i=l.data;let g=0;const d=[...new Set([...(i.report??[]).slice(0,3),...i.note?[i.note]:[]])].map(e=>e.replace(/seed \d+:/g,()=>`course ${++g}:`));for(const e of d)console.log(chalk.gray(` ${e}`));if(t.time_full&&!i.late){const e=/reached the goal at ([\d.]+) s/.exec(d.join(" ")),o=t.time_max??40;if("AC"===i.verdict&&e){H.add(t.id);const s=Number(e[1]),n=s<=t.time_full?1:Math.max(.1,1-.9*(s-t.time_full)/(o-t.time_full));console.log(chalk.bold.cyan(` π Arrived in ${s} s β ${Math.round(100*n)}% of this problem's value`)+chalk.gray(` (full value at ${t.time_full} s or faster).`)),console.log(hint(" βΈ your best time counts β edit, run, submit again to go faster"))}else console.log(chalk.yellow(" β Did not reach the goal yet β 0 for now. ")+hint("edit, run, submit again"));break}if(t.points_max&&!i.late){const e=[...d.join(" ").matchAll(/= (\d+)\/\d+/g)].map(e=>Number(e[1])).sort((e,o)=>e-o),o=e.length?e[Math.floor(e.length/2)]:0;"AC"===i.verdict&&H.add(t.id),console.log(chalk.bold.cyan(` π― This try: ${o}/${t.points_max} points`)+chalk.gray(" (the middle of your 3 courses). This problem pays its value Γ your best / ")+chalk.gray(`${t.points_max}.`)),console.log(hint(o>=20?" βΈ counts as solved (20+). edit, run, submit again to raise your best β score shows it":" βΈ 20+ points also counts it as solved. edit, run, submit again"));break}if("AC"===i.verdict||i.already_ac){H.add(t.id);const e=K?.problems?.find(e=>e.n===o);console.log(chalk.green(` β
Solved problem ${o}!`)+chalk.gray(e?` It is worth ${e.value} now; the board updates within a minute β `:" ")+chalk.bold.green("score"));const s=Z.findIndex(e=>!H.has(e.id));s>=0&&console.log(hint(` βΈ next: read ${s+1}`))}else i.late||String(i.verdict).startsWith("LATE")?console.log(chalk.red(" β± Time is up β this one was recorded but does not count.")):console.log(chalk.yellow(` β ${i.verdict} β not yet. `)+hint(t.knobs?"set a knob, run, up again":"edit, run, submit again (reset = start over)"));break}default:{ye++;const e=t.trim().split(/\s+/)[0],o=closestVerb(e);if(o){console.log(chalk.yellow(" Did you mean ")+chalk.bold.green(o)+chalk.yellow("?"));break}console.log(chalk.yellow(` Don't know "${e}".`)+chalk.gray(" Commands: list Β· read 1 Β· set Β· edit Β· run Β· submit/up Β· score Β· memo Β· help Β· back")),ye>=3&&oe()}}}}finally{te.close()}}
|