icoa-cli 2.19.658 → 2.19.660
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/lib/learn-cup.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as e,readFileSync as o}from"node:fs";import chalk from"chalk";import{playSavedReplay as t,resolveEngineDir as n,saveJudgeReplay as a}from"../commands/battle.js";import{getConfig as s,saveConfig as r}from"./config.js";import{learnPost as l}from"./learn-contest.js";import{DEFAULT_PVP_BOT as i,myBotsCommand as c,printKnobs as u,setKnob as d,writeTemplate as p}from"./learn-pvp.js";import{runInteractive as y}from"./interactive-spawn.js";import{makeReplAsker as g}from"./repl-asker.js";export const CUP_RE=/^\/?(?:cup|cups|杯赛|ถ้วย)(?:\s+(.*))?$/i;const b="https://practice.icoa2026.au/assets/translations/cup/index.html?c=",h=()=>{const e=(s().language||"en").toLowerCase();return e.startsWith("zh")?"zh":e.startsWith("th")?"th":"en"},k=(e,o,t)=>{const n=h();return"zh"===n?o:"th"===n?t??e:e},$=(e,o,t={},n=2e4)=>l(`/api/icoa/learn/cup/${e}`,{token:o.toUpperCase(),...t},n),f=new Set(["back","b","quit","q","exit","card","lesson","卡片"]),m={1:["Round of 64 (64 → 32)","64 强(64 进 32)","รอบ 64 ทีม (64 → 32)"],2:["Round of 32 (32 → 16)","32 强(32 进 16)","รอบ 32 ทีม (32 → 16)"],3:["Round of 16 (16 → 8)","16 强(16 进 8)","รอบ 16 ทีม (16 → 8)"],4:["Quarter-final (8 → 4)","8 强(8 进 4)","รอบ 8 ทีม (8 → 4)"],5:["Semi-final (4 → 2)","半决赛(4 进 2)","รอบรองชนะเลิศ (4 → 2)"],6:["Final (2 → 1)","决赛(2 进 1)","รอบชิงชนะเลิศ (2 → 1)"]},w=e=>{const o=m[e];return o?k(o[0],o[1],o[2]):`R${e}`};let v=0;const _=e=>{e?.server_now&&(v=Date.parse(e.server_now)-Date.now())},N=e=>k(`${Math.floor(e/60)} min ${e%60} s`,`${Math.floor(e/60)} 分 ${e%60} 秒`,`${Math.floor(e/60)} นาที ${e%60} วินาที`);function C(e){const o=function(e){return e.next_at&&"done"!==e.state?Math.max(0,Math.round((Date.parse(e.next_at)-(Date.now()+v))/1e3)):null}(e);if(null===o)return null;const t=w("open"===e.state?1:e.round+1);return o>0?k(`⏱ ${t} starts in ${N(o)}`,`⏱ ${N(o)}后开始 ${t}`,`⏱ ${t} เริ่มในอีก ${N(o)}`):k(`⏱ ${t} is starting now`,`⏱ ${t} 马上开始`,`⏱ ${t} กำลังเริ่ม`)}const A=e=>"knobs"===e?k("🔧 KNOBS cup","🔧 旋钮杯","🔧 ถ้วย KNOBS"):"code"===e?k("✍ CODE cup","✍ 代码杯","✍ ถ้วย CODE"):"",B=e=>"knobs"===e?k("only the 15-knob bot — no editing code, no AI help: template knobs, then set <KNOB> <value>, then up","只收 15 个旋钮的 bot —— 不改代码、不用 AI:template knobs,再 set <旋钮> <值>,再 up","รับเฉพาะ bot แบบ 15 knobs — ห้ามแก้โค้ด ห้ามใช้ AI: template knobs แล้ว set <KNOB> <ค่า> แล้ว up"):"code"===e?k("any Python bot — write your own act(u); AI help is allowed (the knob bot is fine too)","任何 Python bot 都可以 —— 自己写 act(u),可以用 AI 帮忙(旋钮 bot 也行)","รับ bot Python แบบใดก็ได้ — เขียน act(u) เอง ใช้ AI ช่วยได้ (bot แบบ knobs ก็ได้)"):"",O=e=>({1:"R64",2:"R32",3:"R16",4:"QF",5:"SF",6:"F"}[e]??`R${e}`),j=e=>{let o=0;for(const t of e){const e=t.codePointAt(0)??0;e>=3633&&e<=3642&&3634!==e&&3635!==e||e>=3655&&e<=3662||(o+=e>65535||e>=11904&&e<=42191||e>=44032&&e<=55203||e>=63744&&e<=64255?2:1)}return o},x=(e,o)=>e+" ".repeat(Math.max(0,o-j(e))),T=e=>{if(!e)return chalk.gray("—");const o="filler"===e.kind?`🤖 ${e.nick}`:e.nick,t=chalk.gray(` #${e.slot}`);return e.forfeit?chalk.gray(`${o} #${e.slot} (${k("no bot","没交 bot","ไม่มี bot")})`):(e.me?chalk.bold.yellow(o):chalk.white(o))+t};function E(e){if(!e?.versions.length)return null;const o=e.chosen_version;return o&&e.versions.some(e=>e.version===o)?o:e.versions[e.versions.length-1].version}function I(e){const o=e.me;if(!o?.versions.length)return void console.log(chalk.gray(k(" No versions yet — up uploads your bot as v1."," 还没有版本 —— up 上传后就是 v1。"," ยังไม่มีเวอร์ชัน — up เพื่ออัปโหลดเป็น v1")));const t=o.locked_version??E(o);console.log(),console.log(chalk.bold.white(k(" Your versions in this cup"," 你在这个杯赛的版本"," เวอร์ชันของคุณในถ้วยนี้")));for(const e of o.versions){const n=(e.ts||"").replace("T"," ").slice(5,16),a=e.version===t;console.log(` ${a?o.locked_version?"🔒":"★":" "} ${a?chalk.bold.green(`v${e.version}`):chalk.white(`v${e.version}`)}`+chalk.gray(` ${n} UTC · ${e.sha.slice(0,8)}`)+(a?chalk.green(o.locked_version?k(" ← locked, this one plays"," ← 已锁定,比赛用它"," ← ล็อกแล้ว ตัวนี้ลงแข่ง"):k(" ← your entry"," ← 正式参赛版本"," ← ตัวที่ส่งแข่ง")):""))}(o.can_edit??"open"===e.state)&&o.versions.length>1&&console.log(chalk.gray(" ▸ ")+chalk.bold.green(`use ${(o.versions.find(e=>e.version!==t)??o.versions[0]).version}`)+chalk.gray(k(" make another version your entry (until the next round starts)"," 把另一个版本设为正式参赛版本(下一轮开始前都能换)"," เปลี่ยนเวอร์ชันที่ส่งแข่ง (เปลี่ยนได้จนกว่ารอบถัดไปจะเริ่ม)")))}function S(e,o){switch(e){case"no_cup":return k("No cup with that passcode — check it with your teacher.","没有这个口令的杯赛 —— 跟老师核对一下口令。","ไม่มีถ้วยที่ใช้รหัสนี้ — ลองถามครูอีกครั้ง");case"closed":return k("Registration is closed — the bracket has started.","报名已截止 —— 对阵已经开始。","ปิดรับสมัครแล้ว — การแข่งขันเริ่มแล้ว");case"full":return k("The cup is full (64 players).","杯赛满了(64 人)。","ถ้วยเต็มแล้ว (64 คน)");case"same_device":return k("This computer already has a player in this cup — one person, one computer, one entry.","这台电脑已经有人报名了这个杯赛 —— 一人、一台电脑、一个名额。","คอมพิวเตอร์เครื่องนี้มีผู้เล่นในถ้วยนี้แล้ว — หนึ่งคน หนึ่งเครื่อง หนึ่งสิทธิ์");case"nick_taken":return k("That nickname is taken — pick another.","这个昵称被用了 —— 换一个。","ชื่อเล่นนี้มีคนใช้แล้ว — เลือกชื่ออื่น");case"bad_nick":return k("Nickname: 2–12 letters, digits, _ or - (no spaces, not your real name).","昵称:2–12 个字母、数字、_ 或 -(不要空格,不要真名)。","ชื่อเล่น: ตัวอักษรอังกฤษ ตัวเลข _ หรือ - จำนวน 2–12 ตัว (ไม่มีช่องว่าง ไม่ใช้ชื่อจริง)");case"locked":return k("Bots were locked when round 1 started — you play with the version shown above.","第一轮开始时 bot 已锁定 —— 比赛用的是上面显示的那个版本。","bot ถูกล็อกตอนเริ่มรอบแรกแล้ว — ใช้เวอร์ชันที่แสดงด้านบน");case"has_slot":return k("You already have a number — it stays yours.","你已经有号码了,不能再换。","คุณมีหมายเลขแล้ว — เปลี่ยนไม่ได้");case"wrong_course":return k("The cup is for BattleAI tokens (battleai-48).","杯赛只对 BattleAI 课程 token(battleai-48)开放。","ถ้วยนี้สำหรับ token ของ BattleAI (battleai-48) เท่านั้น");default:return o||k("The server did not answer — try again.","服务器没有回应 —— 再试一次。","เซิร์ฟเวอร์ไม่ตอบ — ลองอีกครั้ง")}}const K=(e,o)=>{const t=e.entrants.find(e=>e.slot===o);return t?{slot:o,nick:t.nick,kind:t.kind,level:t.level,forfeit:0,me:e.me?.slot===o}:null};function M(e,o){const t=e.a?.slot===o,[n,a]=t?[e.wins_a,e.wins_b]:[e.wins_b,e.wins_a],s=e.winner_slot===o,r="tiebreak"===e.decided_by?k(" (tie-break game)","(加赛一局定胜负)"," (เกมตัดสิน)"):"value"===e.decided_by?k(" (army value)","(按兵力价值)"," (ตัดสินด้วยมูลค่ากองทัพ)"):"coin"===e.decided_by?k(" (coin toss)","(抽签)"," (เสี่ยงทาย)"):"walkover"===e.decided_by?k(" (walkover)","(对手弃权)"," (ชนะบาย)"):"admin"===e.decided_by?k(" (decided by the teacher)","(老师判定)"," (ครูตัดสิน)"):"",l=null!=n&&null!=a?` ${n}-${a}`:"";return(s?chalk.green(`✅ ${k("won","赢","ชนะ")}${l}`):chalk.red(`❌ ${k("lost","输","แพ้")}${l}`))+chalk.gray(r)}function P(e){console.log();const o="open"===e.state?e.next_at?k("registration open","报名中","เปิดรับสมัคร"):k("registration open — waiting for the teacher to start","报名中 —— 等老师开赛","เปิดรับสมัคร — รอครูเริ่มการแข่งขัน"):"done"===e.state?k("finished","已结束","จบแล้ว"):`${w(e.round)} · ${"judging"===e.round_state?k("playing now","正在比赛","กำลังแข่ง"):"done"===e.round_state?k("done — break before the next round","本轮结束 —— 下一轮之前休息","จบรอบแล้ว — พักก่อนรอบถัดไป"):e.round_state}`;console.log(chalk.bold.white(` 🏆 ${e.label||e.cup}`)+(e.division?chalk.bold.cyan(` · ${A(e.division)}`):"")+chalk.gray(` · ${o} · ${e.players} ${k("players","人","คน")}`));const t=C(e);t&&console.log(chalk.bold.yellow(` ${t}`));const n=e.me;if(!n)return;const a=n.slot;if(console.log(chalk.white(` ${k("You","你","คุณ")}: `)+chalk.bold.yellow(n.nick)+chalk.gray(a?` #${a}`:` · ${k("no number yet","还没选号","ยังไม่ได้เลือกหมายเลข")}`)+chalk.gray(n.locked_version?` · 🔒 bot v${n.locked_version}`:n.forfeit?` · ${k("no bot — out","没交 bot,弃权","ไม่มี bot — ตกรอบ")}`:n.versions.length?` · bot v${n.versions[n.versions.length-1].version}`:` · ${k("no bot uploaded yet","还没上传 bot","ยังไม่ได้อัปโหลด bot")}`)),!a)return;const s=function(e){const o=new Set;for(const t of e.bracket)for(const e of t)if("done"===e.state)for(const t of[e.a,e.b])t&&t.slot!==e.winner_slot&&o.add(t.slot);return o}(e);let r=!n.forfeit;for(let o=1;o<=6;o++){const t=chalk.cyan(x(O(o),4)),n=e.bracket[o-1]?.find(e=>e.a?.slot===a||e.b?.slot===a);if(n){const e=n.a?.slot===a?n.b:n.a,o="done"===n.state?M(n,a):"judging"===n.state?chalk.yellow(`⚖ ${k("playing…","正在判…","กำลังแข่ง…")}`):"error"===n.state?chalk.yellow(k("⚖ judge hiccup — the teacher will re-run it","⚖ 判分出了点问题,老师会重判","⚖ ระบบตัดสินขัดข้อง — ครูจะสั่งแข่งใหม่")):chalk.gray(k("waiting","等待","รอ")),s=n.replays?chalk.gray(` 🎬 replay ${n.id} 1`):"";if(console.log(` ${t} vs ${T(e)} ${o}${s}`),"done"===n.state&&n.winner_slot!==a){r=!1,console.log(chalk.gray(k(" ↳ Your run ends here. Keep watching: bracket, and replay any game."," ↳ 你的比赛到这里结束。可以继续看:bracket 看对阵,replay 看任何一局。"," ↳ เส้นทางของคุณจบที่นี่ ดูต่อได้: bracket ดูสาย และ replay ดูเกมไหนก็ได้")));break}continue}if(!r)break;const l=1<<o-1,i=(a-1>>o<<o)+((a-1>>o-1)%2==0?l:0)+1,c=[];for(let o=i;o<i+l;o++){if(s.has(o))continue;const t=K(e,o);t&&c.push(t)}const u=c.slice(0,3).map(e=>T(e)),d=c.length>3?chalk.gray(" +"+(c.length-3)):"",p=chalk.gray(l>1?` (#${i}–${i+l-1})`:` (#${i})`);"open"===e.state&&1===o?console.log(` ${t} vs ${c.length?u.join(chalk.gray(" · ")):chalk.gray(k("a bot, drawn when round 1 starts","开赛时抽到的 bot","bot ที่จะสุ่มตอนเริ่มรอบแรก"))}${p}`):console.log(` ${t} ${chalk.gray(k("next: one of","可能对上:","อาจเจอ:"))} ${c.length?u.join(chalk.gray(" · "))+d:chalk.gray("open"===e.state?k("bots, drawn at the start","开赛时抽到的 bot","bot ที่จะสุ่มตอนเริ่ม"):k("(to be decided)","(待定)","(ยังไม่รู้)"))}${p}`)}if("done"===e.state&&e.champion_slot){const o=K(e,e.champion_slot);console.log(chalk.bold.yellow(` 🏆 ${k("Champion","冠军","แชมป์")}: `)+(o?T(o):"?")+(o&&o.slot===a?chalk.bold.green(k(" — that is you! 🎉"," —— 就是你!🎉"," — คือคุณ! 🎉")):""))}}function z(e,o){const t=e.bracket[o-1];if(t){console.log(chalk.bold.white(` ${w(o)}`)+chalk.gray(` · ${t.length} ${k("matches","场","นัด")}`));for(const e of t){const o="done"===e.state&&null!=e.winner_slot&&e.winner_slot===e.a?.slot,t="done"===e.state&&null!=e.winner_slot&&e.winner_slot===e.b?.slot,n="done"===e.state?null!=e.wins_a?`${e.wins_a}-${e.wins_b}`:"walkover"===e.decided_by?"w/o":"—":"judging"===e.state?"⚖":"…",a=e.a?"filler"===e.a.kind?`🤖${e.a.nick}`:e.a.nick:"—",s=e.b?"filler"===e.b.kind?`🤖${e.b.nick}`:e.b.nick:"—",r=e.a?.me||e.b?.me,l=(o,t)=>t?chalk.bold.green(o):"done"===e.state?chalk.gray(o):chalk.white(o);console.log(` ${chalk.gray(x(`#${e.id}`,6))}${l(x(a,14),o)} ${chalk.cyan(x(n,5))} ${l(x(s,14),t)}`+(e.replays?chalk.gray(" 🎬"):"")+(r?chalk.yellow(k(" ← you"," ← 你"," ← คุณ")):""))}console.log(chalk.gray(k(" replay <match#> <game#> — e.g. replay 41 1"," replay <场号> <局号> —— 例如 replay 41 1"," replay <เลขนัด> <เลขเกม> — เช่น replay 41 1")))}else console.log(chalk.gray(k(` ${w(o)} has not started yet.`,` ${w(o)}还没开始。`,` ${w(o)} ยังไม่เริ่ม`)))}function R(e){const o=e.entrants.filter(e=>"player"===e.kind);console.log(chalk.bold.white(` ${o.length} ${k("players","人报名","ผู้เล่น")}`));const t=o.map(e=>`${e.nick}${e.slot?`#${e.slot}`:""}${e.has_bot?" ✓":""}`);for(let e=0;e<t.length;e+=3)console.log(" "+t.slice(e,e+3).map(e=>chalk.white(x(e,20))).join(""));console.log(chalk.gray(k(" ✓ = bot uploaded"," ✓ = 已上传 bot"," ✓ = อัปโหลด bot แล้ว")))}function D(e,o){const t=function(e){const o=new Set(e.entrants.map(e=>e.slot).filter(e=>!!e)),t=[];for(let e=1;e<=64;e++)o.has(e)||t.push(e);return t}(e);if(!t.length)return void console.log(chalk.yellow(k(" No free numbers left."," 没有空号了。"," ไม่มีหมายเลขว่างแล้ว")));o&&console.log(chalk.white(` ${k("Closest free","离得最近的空号","หมายเลขว่างที่ใกล้ที่สุด")}: `)+t.slice().sort((e,t)=>Math.abs(e-o)-Math.abs(t-o)||e-t).slice(0,4).map(e=>chalk.bold.green(`pick ${e}`)).join(chalk.gray(" · ")));const n=new Set(t);for(const[e,o]of[[k("left ","左半区","ซ้าย "),1],[k("right ","右半区","ขวา "),33]]){const t=[];for(let e=o;e<o+32;e++)t.push(n.has(e)?chalk.green(String(e).padStart(2)):chalk.gray(" ·"));console.log(chalk.gray(` ${e} `)+t.slice(0,16).join(" ")),console.log(chalk.gray(` ${" ".repeat(j(e))} `)+t.slice(16).join(" "))}console.log(chalk.gray(k(" green = free · grey dot = taken"," 绿色 = 空号 · 灰点 = 已被选"," สีเขียว = ว่าง · จุดเทา = มีคนเลือกแล้ว")))}function W(o){const t=o.me,n=e=>chalk.bold.green(e),a=(e,o)=>console.log(` ${e?"✅":"⬜"} ${e?chalk.gray(o):chalk.white(o)}`),s=!!t?.versions.length;console.log(),o.division&&console.log(` ${chalk.bold.cyan(A(o.division))}${chalk.gray(` — ${B(o.division)}`)}`),a(!!t,k(`joined as ${t?.nick??"?"}`,`已报名,昵称 ${t?.nick??"?"}`,`สมัครแล้ว ชื่อ ${t?.nick??"?"}`)),a(!!t?.slot,t?.slot?k(`your number: #${t.slot}`,`你的号码:#${t.slot}`,`หมายเลขของคุณ: #${t.slot}`):k("pick a number 1–64: pick 17 (or pick random)","选一个 1–64 的号码:pick 17(或 pick random)","เลือกหมายเลข 1–64: pick 17 (หรือ pick random)"));const r=E(t),l=t?.versions.length??0;a(s||!!t?.locked_version,t?.locked_version?k(`bot locked: v${t.locked_version}`,`bot 已锁定:v${t.locked_version}`,`bot ถูกล็อก: v${t.locked_version}`):s?k(`your entry: v${r} (${l} version${1===l?"":"s"}) — up = new version · versions = list · use N = switch`,`正式参赛版本:v${r}(共 ${l} 个版本)—— up = 新版本 · versions = 列表 · use N = 换版本`,`ตัวที่ส่งแข่ง: v${r} (มี ${l} เวอร์ชัน) — up = เวอร์ชันใหม่ · versions = รายการ · use N = เปลี่ยน`):"knobs"===o.division?k("make and upload your knob bot: template knobs → set WOMBATS 6 → up (no bot by round 1 = you forfeit)","做好并上传旋钮 bot:template knobs → set WOMBATS 6 → up(第一轮开始还没交 = 弃权)","สร้างและอัปโหลด bot แบบ knobs: template knobs → set WOMBATS 6 → up (ไม่มี bot ตอนเริ่มรอบแรก = สละสิทธิ์)"):k("upload your bot: up (no bot by round 1 = you forfeit)","上传 bot:up(第一轮开始还没交 = 弃权)","อัปโหลด bot: up (ไม่มี bot ตอนเริ่มรอบแรก = สละสิทธิ์)")),a("open"!==o.state,"open"===o.state?k("wait for round 1 to start","等第一轮开始","รอรอบแรกเริ่ม"):k("the bracket has started","对阵已开始","การแข่งขันเริ่มแล้ว")),"running"===o.state&&t&&(!1===t.alive?console.log(chalk.gray(k(" 👀 You are out of this cup — well played! Watch the others: bracket · replay <match#> 1"," 👀 你已经被淘汰了 —— 打得不错!看看别人:bracket · replay <场号> 1"," 👀 คุณตกรอบแล้ว — เล่นได้ดีมาก! ดูคนอื่น: bracket · replay <นัด> 1"))):"judging"===o.round_state?console.log(chalk.yellow(k(" ⚖ This round is being played — bots are LOCKED. Wait for the result (press Enter to check)."," ⚖ 这一轮正在比赛 —— bot 已锁定。等结果(按回车查看)。"," ⚖ กำลังแข่งรอบนี้ — bot ถูกล็อก รอผล (กด Enter เพื่อดู)"))):t.can_edit&&console.log(chalk.bold.green(k(" 🛠 BREAK — you are still in! You may change your bot now: set … then up (or use N)."," 🛠 休息时间 —— 你还在比赛里!现在可以改 bot:set … 再 up(或者 use N 换版本)。"," 🛠 พัก — คุณยังอยู่ในการแข่งขัน! เปลี่ยน bot ได้ตอนนี้: set … แล้ว up (หรือ use N)"))+chalk.gray(k(" It locks when the next round starts.","下一轮开始时锁定。"," จะล็อกเมื่อรอบถัดไปเริ่ม"))));const c=C(o);c&&console.log(chalk.bold.yellow(` ${c}`));const u=t?.slot?s||"open"!==o.state?"path":"knobs"!==o.division||e(i)?"up":"template knobs":"pick 17";console.log(chalk.gray(" ▸ ")+chalk.gray(k("next: ","下一步敲 ","พิมพ์ต่อไป: "))+n(u)+chalk.gray(" ▸ ")+n("guide")+chalk.gray(k(" the full sheet"," 完整说明"," คำอธิบายทั้งหมด")))}function Y(e,o,t){"knobs"===o&&console.log(chalk.gray(k(" 🔧 template knobs · knobs (see them) · set <KNOB> <value> · up"," 🔧 template knobs · knobs 看旋钮 · set <旋钮> <值> · up"," 🔧 template knobs · knobs (ดู knobs) · set <KNOB> <ค่า> · up"))),console.log(chalk.gray(k(` Enter = my path · pick N · up · versions · use N · bracket [round] · who · replay <match#> <game#> · web · guide · lang en|zh|th · card (${e})`,` 回车 = 我的路线 · pick N 选号 · up 上传 · versions 版本 · use N 选版本 · bracket [轮] · who · replay <场号> <局号> · web · guide · lang en|zh|th · card 回卡片 (${e})`,` Enter = เส้นทางของฉัน · pick N · up · versions · use N · bracket [รอบ] · who · replay <นัด> <เกม> · web · guide · lang en|zh|th · card (${e})`)))}function L(e,o){const t=e=>chalk.bold.green(e),n=e=>chalk.gray(e);console.log(),console.log(chalk.bold.white(k(" 🏆 The cup — how it works"," 🏆 杯赛怎么玩"," 🏆 ถ้วย — เล่นอย่างไร"))),o&&(console.log(` ${chalk.bold.cyan(A(o))}${n(` — ${B(o)}`)}`),console.log(n(k(" There are two cups today: 🔧 KNOBS (only the 15 knob values, no AI) and ✍ CODE (your own Python, AI allowed). You may enter both — one bot in each."," 今天有两个杯赛:🔧 旋钮杯(只改 15 个旋钮的值,不用 AI)和 ✍ 代码杯(自己写 Python,可以用 AI)。两个都可以参加 —— 每个杯赛各交一个 bot。"," วันนี้มีสองถ้วย: 🔧 KNOBS (เปลี่ยนเฉพาะค่า 15 knobs ห้ามใช้ AI) และ ✍ CODE (เขียน Python เอง ใช้ AI ได้) เข้าได้ทั้งสองถ้วย — ถ้วยละหนึ่ง bot"))));const a=[["pick 17","choose your number 1–64 — first come, first served. Taken? the free numbers are shown, pick one. Once it is yours it never changes","选 1–64 的号码 —— 先到先得。被占了会列出空号,再选一个。选定之后不能再换","เลือกหมายเลข 1–64 — ใครมาก่อนได้ก่อน ถ้ามีคนใช้แล้วจะแสดงหมายเลขว่างให้เลือก เลือกแล้วเปลี่ยนไม่ได้"],["pick random","let the system draw a free number","让系统随机给一个空号","ให้ระบบสุ่มหมายเลขว่างให้"],["up","upload ~/.icoa/battleai/bot.py as a NEW version (v1, v2, v3 …); the newest becomes your entry. Old versions are kept","把 ~/.icoa/battleai/bot.py 上传成一个新版本(v1、v2、v3…),最新的自动成为正式参赛版本;旧版本都保留","อัปโหลด ~/.icoa/battleai/bot.py เป็นเวอร์ชันใหม่ (v1, v2, v3 …) ตัวล่าสุดจะเป็นตัวที่ส่งแข่ง เวอร์ชันเก่ายังเก็บไว้"],["versions","list every version you uploaded; ★ = your entry","列出你上传过的所有版本;★ = 正式参赛版本","แสดงทุกเวอร์ชันที่อัปโหลด ★ = ตัวที่ส่งแข่ง"],["use 2","make v2 your entry instead — the server checks it can really play first (before round 1, and in every break while you are still in)","改用 v2 作为正式参赛版本 —— 服务器会先检查它真的能打(第一轮之前,以及你还在比赛时的每次休息)","ใช้ v2 เป็นตัวที่ส่งแข่งแทน — เซิร์ฟเวอร์จะตรวจก่อนว่าเล่นได้จริง (ก่อนรอบแรก และทุกช่วงพักถ้ายังไม่ตกรอบ)"],["bots","every version you ever uploaded (cups + rooms) · show N = see its knobs or code · get N = save it · restore N = back into bot.py","你上传过的所有版本(杯赛 + 房间)· show N 看旋钮或代码 · get N 存成文件 · restore N 放回 bot.py","ทุกเวอร์ชันที่เคยอัปโหลด (ถ้วย + ห้อง) · show N = ดู knobs หรือโค้ด · get N = บันทึก · restore N = ใส่กลับเข้า bot.py"],["lang th","switch the language: lang en · lang zh · lang th","切换语言:lang en · lang zh · lang th","เปลี่ยนภาษา: lang en · lang zh · lang th"],["template knobs","puts the 15-knob starter at bot.py (already have one? template knobs force; the old file becomes bot.py.bak)","把 15 个旋钮的起步 bot 放到 bot.py(已经有了?template knobs force,旧文件留作 bot.py.bak)","วาง bot เริ่มต้นแบบ 15 knobs ไว้ที่ bot.py (มีอยู่แล้ว? template knobs force ไฟล์เดิมจะเป็น bot.py.bak)"],["knobs","list the 15 knobs and their values","列出 15 个旋钮和现在的值","แสดง knobs ทั้ง 15 ตัวและค่าปัจจุบัน"],["set WOMBATS 6","change one knob value in bot.py (no editor needed)","改 bot.py 里一个旋钮的值(不用编辑器)","เปลี่ยนค่า knob หนึ่งตัวใน bot.py (ไม่ต้องเปิด editor)"],["Enter","your path: this round, who you may meet next, the road to the final","我的路线:这一轮对手、下一轮可能遇到谁、到决赛的路","เส้นทางของคุณ: คู่แข่งรอบนี้ ใครที่อาจเจอต่อไป และทางสู่รอบชิง"],["bracket 2","one round, every match (no number = the current round)","看某一轮的全部对阵(不写 = 当前轮)","ดูทุกนัดของรอบหนึ่ง (ไม่ใส่เลข = รอบปัจจุบัน)"],["replay 41 1","watch match #41, game 1 (any match, any player)","看第 41 场的第 1 局(任何一场都能看)","ดูนัด #41 เกมที่ 1 (ดูได้ทุกนัด)"],["who","everyone in the cup and their numbers","所有报名的人和号码","ผู้เล่นทุกคนและหมายเลข"],["web","the address of the big bracket page (projector / phone)","大屏 / 手机看的对阵图网址","ที่อยู่หน้าสายการแข่งขัน (โปรเจกเตอร์ / มือถือ)"]];for(const[e,o,s,r]of a)console.log(` ${t(x(e,16))}${n(k(o,s,r))}`);console.log(),console.log(chalk.bold.white(k(" Rules"," 规则"," กติกา")));for(const[e,o,t]of[["64 numbers. Numbers nobody picked get graded bots (gauntlet levels, spread across the bracket).","64 个号码。没人选的号码由分档 bot 补上(挑战台等级,分散在整个对阵里)。","64 หมายเลข หมายเลขที่ไม่มีใครเลือกจะใส่ bot ตามระดับ (กระจายทั่วสาย)"],["Knock-out, left half (#1–32) and right half (#33–64) meet in the final: 64 → 32 → 16 → 8 → 4 → 2 → champion.","单败淘汰,左半区(#1–32)和右半区(#33–64)在决赛相遇:64 进 32 → 32 进 16 → 16 进 8 → 8 进 4 → 半决赛 → 决赛。","แพ้คัดออก ครึ่งซ้าย (#1–32) และครึ่งขวา (#33–64) เจอกันในรอบชิง: 64 → 32 → 16 → 8 → 4 → 2 → แชมป์"],["A match = one game on each of the 3 maps; from the quarter-final on, 5 games (+ Ballarat and Murray again). More game wins goes through. Every round has new seeds = new layouts.","一场 = 3 张图各一局;8 强起每场 5 局(再加 Ballarat、Murray 各一局)。赢得局数多的晋级。每一轮都换新种子 = 新地形。","หนึ่งนัด = 3 แผนที่ แผนที่ละ 1 เกม ตั้งแต่รอบ 8 ทีม = 5 เกม (เพิ่ม Ballarat และ Murray) ชนะมากกว่าได้ไปต่อ ทุกรอบใช้ seed ใหม่ = แผนที่แบบใหม่"],["Level after 3 games → one tie-break game; still level → higher army value.","3 局打平 → 加赛一局;还是平 → 比兵力价值。","เสมอหลัง 3 เกม → เกมตัดสิน 1 เกม ยังเสมอ → เทียบมูลค่ากองทัพ"],["Your ENTRY version (★ in versions) LOCKS when a round starts. No bot when round 1 starts = you forfeit.","每一轮开始时锁定你的正式参赛版本(versions 里的 ★)。第一轮开始时还没上传 = 弃权。","เวอร์ชันที่ส่งแข่ง (★ ใน versions) จะถูกล็อกเมื่อแต่ละรอบเริ่ม ถ้าไม่มี bot ตอนรอบแรกเริ่ม = สละสิทธิ์"],["After every round there is a BREAK (a countdown shows how long). Still in? Change your bot: set … → up, or use N. Out? Watch the replays.","每一轮结束后有休息时间(倒计时会显示还剩多久)。还在比赛里?改 bot:set … → up,或 use N。被淘汰了?去看回放。","หลังจบแต่ละรอบมีช่วงพัก (มีนับถอยหลัง) ยังไม่ตกรอบ? เปลี่ยน bot: set … → up หรือ use N ตกรอบแล้ว? ดูรีเพลย์"],["One person, one computer, one entry: a second account on the same computer is refused.","一人、一台电脑、一个名额:同一台电脑的第二个账号进不来。","หนึ่งคน หนึ่งเครื่อง หนึ่งสิทธิ์: บัญชีที่สองบนเครื่องเดียวกันจะถูกปฏิเสธ"]])console.log(n(` · ${k(e,o,t)}`));console.log(n(` ${k("Big bracket","大屏对阵图","สายการแข่งขัน")}: ${b}${e}`))}async function q(e){for(;;){const o=await e(chalk.white(k(" Nickname for the cup (2–12 letters/digits, not your real name; empty = cancel): "," 杯赛昵称(2–12 个字母/数字,不要真名;直接回车 = 取消):"," ชื่อเล่นในถ้วย (2–12 ตัวอักษร/ตัวเลข ไม่ใช่ชื่อจริง; Enter เปล่า = ยกเลิก): ")));if(null===o)return null;const t=o.trim();if(!t)return null;if(/^[A-Za-z0-9_-]{2,12}$/.test(t))return t;console.log(chalk.yellow(" "+S("bad_nick")))}}export async function runCup(s,l,y,g={}){const m=y.trim().replace(/^(?:join|enter|进)\s+/i,"").toUpperCase().replace(/[^A-Z0-9]/g,"").slice(0,8);if(!m){const e=await $("status",s);if(console.log(),console.log(chalk.bold.white(k(" 🏆 Cup"," 🏆 杯赛"," 🏆 ถ้วย"))+chalk.gray(k(" — the 64-player knock-out your teacher runs."," —— 老师组织的 64 强淘汰赛。"," — การแข่งแบบแพ้คัดออก 64 คนที่ครูจัด"))),e.ok&&e.data?.cups.length)for(const o of e.data.cups)console.log(` ${chalk.bold.cyan(x(o.cup,7))} ${chalk.white(x(o.label||"",22))} ${chalk.cyan(x(A(o.division),14))}${chalk.gray(`${k("you are","你是","คุณคือ")} ${o.nick}`)}`);else e.ok||console.log(chalk.yellow(" "+S(e.code,e.message)));return console.log(chalk.gray(" ▸ ")+chalk.bold.green(k("cup <PASSCODE>","cup <口令>","cup <รหัส>"))+chalk.gray(k(" the passcode comes from your teacher, e.g. cup BKK26"," 口令由老师给,例如 cup BKK26"," รหัสได้จากครู เช่น cup BKK26"))),"back"}let w=null;const v=await $("status",s,{cup:m});if(v.ok&&v.data)w=v.data;else{if("not_member"!==v.code)return console.log(chalk.yellow(" "+S(v.code,v.message))),"back";{const e=await $("join",s,{cup:m,probe:!0});if(!e.ok||!e.data)return console.log(chalk.yellow(" "+S(e.code,e.message))),"back";if(console.log(chalk.white(` ${k("Entering","进入","กำลังเข้า")} `)+chalk.bold.cyan(m)+chalk.gray(` ${e.data.label||""} · ${e.data.players} ${k("players","人","คน")}`)),e.data.division&&console.log(` ${chalk.bold.cyan(A(e.data.division))}${chalk.gray(` — ${B(e.data.division)}`)}`),"open"!==e.data.state)return console.log(chalk.yellow(" "+S("closed"))+chalk.gray(` ${b}${m}`)),"back";for(let e=0;e<4&&!w;e++){const e=await q(l);if(null===e)return"back";const o=await $("join",s,{cup:m,nick:e});if(o.ok&&o.data)w=o.data;else if(console.log(chalk.yellow(" "+S(o.code,o.message))),"same_device"===o.code||"closed"===o.code||"full"===o.code)return"back"}if(!w)return"back";L(m,w.division)}}const N=chalk.bold.magenta(`icoa cup ${m}> `),C=async()=>{const e=await $("status",s,{cup:m});return e.ok&&e.data?(w=e.data,_(w),!0):(console.log(chalk.yellow(" "+S(e.code,e.message))),!1)};for(_(w),W(w),P(w),Y(m,w.division);;){const y=await l(N);if(null===y)return"back";const v=y.trim(),_=v.toLowerCase();if(f.has(_))return"back";if("menu"===_)return"menu";if(!v||/^(?:path|me|route|路线|เส้นทาง|status)$/i.test(v)){await C()&&P(w),Y(m,w.division);continue}if(/^(?:help|\?|帮助|ช่วย)$/i.test(v)){await C(),W(w),Y(m,w.division);continue}if(/^(?:guide|说明|คู่มือ)$/i.test(v)){L(m,w.division),Y(m,w.division);continue}if(/^(?:web|url|网页)$/i.test(v)){console.log(chalk.white(` ${b}${m}`)+chalk.gray(k(" — open on the projector or a phone"," —— 投影或手机打开"," — เปิดบนโปรเจกเตอร์หรือมือถือ")));continue}if(/^(?:who|players|名单|ผู้เล่น)$/i.test(v)){await C()&&R(w);continue}const A=/^(?:bracket|round|对阵|สาย)(?:\s+(\d))?$/i.exec(v);if(A){await C()&&z(w,A[1]?Number(A[1]):Math.max(1,w.round));continue}const B=/^(?:pick|选|เลือก)(?:\s+(random|\d+))?$/i.exec(v);if(B){if(!B[1]){console.log(chalk.gray(k(" pick 17 — a number 1–64, or pick random"," pick 17 —— 1–64 的号码,或 pick random"," pick 17 — หมายเลข 1–64 หรือ pick random")));continue}const e="random"===B[1].toLowerCase(),o=Number(B[1]);if(!(e||o>=1&&o<=64)){console.log(chalk.yellow(k(" Numbers go from 1 to 64 — e.g. pick 17"," 号码是 1 到 64 —— 例如 pick 17"," หมายเลขคือ 1 ถึง 64 — เช่น pick 17")));continue}if(w.me?.slot){console.log(chalk.yellow(" "+S("has_slot"))+chalk.gray(` #${w.me.slot}`));continue}const t=await l(chalk.bold.white(e?k(" Let the system give you a free number? It can NOT be changed afterwards. Type yes (Enter = cancel): "," 让系统给你一个空号?之后不能再换。敲 yes 确认(直接回车 = 取消):"," ให้ระบบเลือกหมายเลขว่างให้? เปลี่ยนภายหลังไม่ได้ พิมพ์ yes (Enter = ยกเลิก): "):k(` Take number #${o}? Once it is yours it can NOT be changed. Type yes (Enter = cancel): `,` 要 #${o} 号吗?选了之后不能再换。敲 yes 确认(直接回车 = 取消):`,` เอาหมายเลข #${o}? เลือกแล้วเปลี่ยนไม่ได้ พิมพ์ yes (Enter = ยกเลิก): `)));if(null===t)return"back";if(!/^(?:y|yes|ok|是|好|确认|ใช่|ตกลง)$/i.test(t.trim())){console.log(chalk.gray(k(" Cancelled — no number taken."," 已取消 —— 没有选号。"," ยกเลิกแล้ว — ยังไม่ได้เลือกหมายเลข")));continue}const n=await $("pick",s,e?{cup:m,random:!0}:{cup:m,slot:o});if(n.ok&&n.data){w=n.data;const e=n.data.how??"";console.log(chalk.green(" ✓ ")+chalk.bold.white(k(`Number #${n.data.picked} is yours for the whole cup`,`#${n.data.picked} 号是你的了,整个杯赛都不变`,`หมายเลข #${n.data.picked} เป็นของคุณตลอดการแข่งขัน`))+chalk.gray("random_after_2_clashes"===e?k(" — second clash, so the system drew it for you"," —— 第二次撞号,系统帮你抽的"," — ชนเป็นครั้งที่สอง ระบบจึงสุ่มให้"):"random_asked"===e?k(" — drawn at random"," —— 随机抽的"," — สุ่มให้"):"")),W(w)}else"taken"===n.code?(console.log(chalk.yellow(k(` #${o} is already taken — choose one of the free numbers below.`,` #${o} 已经被别人选了 —— 从下面的空号里再选一个。`,` #${o} มีคนเลือกแล้ว — เลือกหมายเลขว่างด้านล่าง`))),await C()&&D(w,o)):console.log(chalk.yellow(" "+S(n.code,n.message)));continue}const O=/^lang(?:\s+(\S+))?$/i.exec(v);if(O){const e=(O[1]??"").toLowerCase().slice(0,2);if(!["en","zh","th"].includes(e)){console.log(chalk.gray(` ${k("language","语言","ภาษา")}: `)+chalk.white(h())+chalk.gray(" · ")+["en","zh","th"].map(e=>chalk.bold.green(`lang ${e}`)).join(chalk.gray(" / ")));continue}r({language:e}),console.log(chalk.green(" ✓ ")+chalk.gray("zh"===e?"语言 → ":"th"===e?"ภาษา → ":"language → ")+chalk.white(e)),await C()&&W(w),Y(m,w.division);continue}if(await c(v,s,`CUP-${m}`))continue;if(/^(?:versions?|版本|เวอร์ชัน)$/i.test(v)){await C()&&I(w);continue}const j=/^(?:use|用|ใช้)(?:\s+v?(\d+))?$/i.exec(v);if(j){if(!j[1]){await C()&&I(w);continue}const e=await $("use",s,{cup:m,version:Number(j[1]),lang:h()});if(!e.ok||!e.data){console.log(chalk.yellow(" "+("no_version"===e.code?k(`You have no v${j[1]} in this cup — type versions.`,`你在这个杯赛没有 v${j[1]} —— 敲 versions 看列表。`,`คุณไม่มี v${j[1]} ในถ้วยนี้ — พิมพ์ versions`):`❌ ${S(e.code,e.message)}`))),"no_version"!==e.code&&"locked"!==e.code&&"out"!==e.code&&console.log(chalk.gray(k(" Your entry did not change. Pick a version that works (versions), or fix bot.py and up."," 正式参赛版本没变。换一个能用的版本(versions 看列表),或者改好 bot.py 再 up。"," ตัวที่ส่งแข่งยังเหมือนเดิม เลือกเวอร์ชันที่ใช้ได้ (versions) หรือแก้ bot.py แล้ว up")));continue}w=e.data,console.log(chalk.green(" ✓ ")+chalk.white(k(`v${j[1]} checked ✓ — it is now your entry and locks when the next round starts.`,`v${j[1]} 检查通过 ✓ —— 现在是正式参赛版本,下一轮开始时锁定。`,`v${j[1]} ตรวจแล้ว ✓ — ตอนนี้เป็นตัวที่ส่งแข่ง จะล็อกเมื่อรอบถัดไปเริ่ม`))),I(w);continue}if(/^(?:knobs?|旋钮)$/i.test(v)||/^set$/i.test(v)){if(!e(i)){console.log(chalk.yellow(k(" No bot.py yet — "," 还没有 bot.py —— "," ยังไม่มี bot.py — "))+chalk.bold.green("template knobs"));continue}u(o(i,"utf8"));continue}const x=/^(?:set|改)\s+(.+)$/i.exec(v);if(x){if(!e(i)){console.log(chalk.yellow(k(" No bot.py yet — "," 还没有 bot.py —— "," ยังไม่มี bot.py — "))+chalk.bold.green("template knobs"));continue}d(o(i,"utf8"),x[1],k(" next: up uploads it to the cup"," 下一步:up 上传到杯赛"," ขั้นต่อไป: up เพื่ออัปโหลดเข้าถ้วย"));continue}const T=/^(?:template|模板)(?:\s+(knobs?|code|新手|高手|旋钮|代码))?(?:\s+(force|覆盖))?$/i.exec(v);if(T){const e=/^(?:code|高手|代码)$/i.test(T[1]??"")?"code":"knobs";if("code"===e&&"knobs"===w.division){console.log(chalk.yellow(k(" This is the 🔧 KNOBS cup — it takes only the knob bot. Type template knobs (custom code goes in the ✍ CODE cup)."," 这是 🔧 旋钮杯 —— 只收旋钮 bot。请敲 template knobs(自己写的代码去 ✍ 代码杯)。"," นี่คือถ้วย 🔧 KNOBS — รับเฉพาะ bot แบบ knobs พิมพ์ template knobs (โค้ดที่เขียนเองให้ส่งในถ้วย ✍ CODE)")));continue}if(!await n()){console.log(chalk.yellow(k(" The arena engine is not on this computer yet: type card, then battle once (it downloads the engine), then come back."," 这台电脑还没有竞技场引擎:先 card 回卡片,进一次 battle(会下载引擎),再回来。"," เครื่องนี้ยังไม่มี engine: พิมพ์ card แล้วเข้า battle หนึ่งครั้ง (จะดาวน์โหลด engine) แล้วกลับมา")));continue}await p(e,!!T[2],"zh"===h())&&console.log(chalk.gray(" ▸ ")+chalk.bold.green("knobs"===e?"set WOMBATS 6":"up")+chalk.gray("knobs"===e?k(" change a knob, then up"," 改一个旋钮,然后 up"," เปลี่ยน knob แล้ว up"):k(" after you edit bot.py"," 改好 bot.py 之后"," หลังจากแก้ bot.py")));continue}const K=/^(?:up|upload|submit|上传|อัปโหลด)(?:\s+(.+))?$/i.exec(v);if(K){const t=(K[1]??"").trim()||i;if(!e(t)){console.log(chalk.yellow(` ${k("Not found","找不到","ไม่พบไฟล์")}: ${t}`)+chalk.gray(k(" — type template first"," —— 先敲 template"," — พิมพ์ template ก่อน")));continue}let n="";try{n=o(t,"utf8")}catch{console.log(chalk.yellow(` ${k("Could not read","读不了","อ่านไฟล์ไม่ได้")}: ${t}`));continue}const a=await $("upload",s,{cup:m,code:n,lang:h()},3e4);if(!a.ok||!a.data){console.log(chalk.bold.red(k(" ❌ Not accepted"," ❌ 没有收下"," ❌ ไม่รับ"))),console.log(chalk.yellow(" "+S(a.code,a.message)));const e=E(w.me);e&&"locked"!==a.code&&"out"!==a.code&&console.log(chalk.gray(k(` Nothing changed — your entry is still v${e}.`,` 什么都没变 —— 正式参赛版本还是 v${e}。`,` ไม่มีอะไรเปลี่ยน — ตัวที่ส่งแข่งยังเป็น v${e}`)));continue}console.log(a.data.unchanged?chalk.gray(k(` Identical to v${a.data.version} — nothing new.`,` 和 v${a.data.version} 一字不差,没有新版本。`,` เหมือนกับ v${a.data.version} ทุกตัวอักษร — ไม่มีเวอร์ชันใหม่`)):chalk.green(" ✓ ")+chalk.white(k(`Checked ✓ and uploaded as v${a.data.version} — it is now your entry. Older versions are kept: versions · use N.`,`检查通过 ✓,已上传为 v${a.data.version} —— 现在它是正式参赛版本。旧版本都保留:versions 看列表 · use N 换回去。`,`ตรวจแล้ว ✓ อัปโหลดเป็น v${a.data.version} — ตอนนี้เป็นตัวที่ส่งแข่ง เวอร์ชันเก่ายังอยู่: versions · use N`))),await C(),W(w);continue}const M=/^(?:replay|回放|รีเพลย์)(?:\s+(\d+))?(?:\s+(\d+))?$/i.exec(v);if(M){if(!M[1]){console.log(chalk.gray(k(" replay <match#> <game#> — e.g. replay 41 1 (match numbers are in bracket and your path)"," replay <场号> <局号> —— 例如 replay 41 1(场号在 bracket 和你的路线里)"," replay <เลขนัด> <เลขเกม> — เช่น replay 41 1 (เลขนัดอยู่ใน bracket และเส้นทางของคุณ)")));continue}const e=await $("replay",s,{cup:m,match_id:Number(M[1]),game:Number(M[2]??1)},3e4);if(!e.ok||!e.data){console.log(chalk.yellow(" "+S(e.code,e.message)));continue}const o=e.data,n=0===o.seat_a?{blue:o.a,red:o.b}:1===o.seat_a?{blue:o.b,red:o.a}:null,r="a"===o.winner?o.a:"b"===o.winner?o.b:null;if(console.log(chalk.gray(` #${M[1]} ${k("game","第","เกม")} ${M[2]??1}${k(""," 局","")}${o.tiebreak?k(" (tie-break)","(加赛)"," (เกมตัดสิน)"):""} · ${o.map} · `)+(n?`🟦 ${chalk.bold.white(n.blue)}${chalk.gray(" vs ")}🟥 ${chalk.bold.white(n.red)}`:`${o.a} vs ${o.b}`)+chalk.gray(` · ${k("winner","胜者","ผู้ชนะ")}: `)+(r?chalk.bold.white(r):chalk.gray(k("draw","平局","เสมอ")))),!a(o.replay,n)){console.log(chalk.yellow(k(" Could not save the replay."," 回放存不下来。"," บันทึกรีเพลย์ไม่ได้")));continue}console.log(chalk.gray(k(" space = pause · ← → = step · ↑ ↓ = speed · q = back to the cup"," 空格 = 暂停 · ← → = 单步 · ↑ ↓ = 速度 · q = 回到杯赛"," space = หยุด · ← → = ทีละขั้น · ↑ ↓ = ความเร็ว · q = กลับไปที่ถ้วย"))),await t(g.interactive)||console.log(chalk.yellow(k(" The replay is saved, but the viewer needs Python 3.12 and the arena engine: run python setup, open battle once, then replay again."," 回放已存在本机,但播放器需要 Python 3.12 和竞技场引擎:先 python setup,再进一次 battle,回来再 replay。"," บันทึกรีเพลย์แล้ว แต่ตัวเล่นต้องใช้ Python 3.12 และ engine: รัน python setup แล้วเข้า battle หนึ่งครั้ง จากนั้น replay อีกครั้ง")));continue}console.log(chalk.gray(k(` Not a cup command: ${v}`,` 不是杯赛命令:${v}`,` ไม่ใช่คำสั่งของถ้วย: ${v}`))),Y(m,w.division)}}function U(e){return"open"===e.state?k("registration open","报名中","เปิดรับสมัคร"):"done"===e.state?k("finished — see the results","已结束 —— 可以看结果","จบแล้ว — ดูผลได้"):`${w(e.round)} · ${"judging"===e.round_state?k("playing now","正在比赛","กำลังแข่ง"):k("break","休息中","พัก")}`}export async function runCampCup(e){const o=e.trim().toUpperCase();console.log(chalk.gray(k(" Checking your BattleAI token…"," 正在检查你的 BattleAI token…"," กำลังตรวจ token BattleAI…")));const t=await $("status",o);if(!t.ok||!t.data)return"device_bound"===t.code?(console.log(chalk.yellow(` ✗ ${t.message??""}`)),console.log(chalk.gray(k(" This token was first opened on another computer — tell your teacher your seat number."," 这个 token 第一次是在另一台电脑上打开的 —— 把你的座位号告诉老师。"," token นี้ถูกเปิดครั้งแรกบนเครื่องอื่น — บอกครูหมายเลขที่นั่งของคุณ"))),!0):"expired"===t.code&&(console.log(chalk.yellow(` ✗ ${t.message??"expired"}`)),!0);const n=g();try{for(;;){const e=await $("status",o),t=e.ok&&e.data?.listed?e.data.listed:[],a="═".repeat(44);if(console.log(),console.log(chalk.bold.cyan(` ${a}`)),console.log(chalk.bold.white(" ICOA Thailand 2026 AI CAMP")),console.log(chalk.bold.yellow(k(" BattleAI Cup — 64-player knock-out"," BattleAI 杯 —— 64 强淘汰赛"," BattleAI Cup — แพ้คัดออก 64 คน"))),console.log(chalk.bold.cyan(` ${a}`)),!t.length)return console.log(chalk.yellow(k(" No cup is open yet — wait for your teacher, then type your token again."," 杯赛还没开 —— 等老师说开始,再输入一次你的 token。"," ยังไม่เปิดถ้วย — รอครูบอก แล้วพิมพ์ token อีกครั้ง"))),!0;t.forEach((e,o)=>{console.log(` ${chalk.bold.green(String(o+1))} ${chalk.bold.cyan(x(A(e.division)||e.label||e.cup,16))}`+chalk.white(x(e.label||"",20))+chalk.gray(`${e.players} ${k("players","人","คน")} · ${U(e)}`)+(e.member?chalk.green(k(" · you are in ✓"," · 你已报名 ✓"," · คุณอยู่ในถ้วยนี้ ✓")):""));const t=B(e.division);t&&console.log(chalk.gray(` ${t}`))});const s=await n.ask(chalk.bold.white(k(` Type ${t.map((e,o)=>o+1).join(" or ")} to enter a cup (Enter = back): `,` 敲 ${t.map((e,o)=>o+1).join(" 或 ")} 进入杯赛(直接回车 = 返回):`,` พิมพ์ ${t.map((e,o)=>o+1).join(" หรือ ")} เพื่อเข้าถ้วย (Enter = กลับ): `)));if(null===s)return!0;const r=s.trim().toLowerCase();if(!r||f.has(r)||"menu"===r)return!0;const l=t[Number(r)-1]??t.find(e=>e.cup.toLowerCase()===r||/^(?:knobs?|旋钮|🔧)$/.test(r)&&"knobs"===e.division||/^(?:code|pro|代码|高手|✍)$/.test(r)&&"code"===e.division);if(l){if("menu"===await runCup(o,n.ask,l.cup,{interactive:(e,o)=>y(e,o)}))return!0;console.log(chalk.gray(k(" ↩ Back to the cup list."," ↩ 回到杯赛列表。"," ↩ กลับไปที่รายการถ้วย")))}else console.log(chalk.yellow(k(` Type a number from the list: ${t.map((e,o)=>o+1).join(", ")}`,` 请敲列表里的数字:${t.map((e,o)=>o+1).join("、")}`,` พิมพ์ตัวเลขจากรายการ: ${t.map((e,o)=>o+1).join(", ")}`)))}}finally{n.close()}}
|
|
1
|
+
import{existsSync as e,readFileSync as o}from"node:fs";import chalk from"chalk";import{playSavedReplay as t,resolveEngineDir as n,saveJudgeReplay as a}from"../commands/battle.js";import{getConfig as s,saveConfig as r}from"./config.js";import{learnPost as l}from"./learn-contest.js";import{DEFAULT_PVP_BOT as i,myBotsCommand as c,printKnobs as u,setKnob as d,writeTemplate as g}from"./learn-pvp.js";import{runInteractive as p}from"./interactive-spawn.js";import{makeReplAsker as y}from"./repl-asker.js";export const CUP_RE=/^\/?(?:cup|cups|杯赛|ถ้วย)(?:\s+(.*))?$/i;const b="https://practice.icoa2026.au/assets/translations/cup/index.html?c=",h=()=>{const e=(s().language||"en").toLowerCase();return e.startsWith("zh")?"zh":e.startsWith("th")?"th":"en"},k=(e,o,t)=>{const n=h();return"zh"===n?o:"th"===n?t??e:e},$=(e,o,t={},n=2e4)=>l(`/api/icoa/learn/cup/${e}`,{token:o.toUpperCase(),...t},n),f=new Set(["back","b","quit","q","exit","card","lesson","卡片"]),m={1:["Round of 64 (64 → 32)","64 强(64 进 32)","รอบ 64 ทีม (64 → 32)"],2:["Round of 32 (32 → 16)","32 强(32 进 16)","รอบ 32 ทีม (32 → 16)"],3:["Round of 16 (16 → 8)","16 强(16 进 8)","รอบ 16 ทีม (16 → 8)"],4:["Quarter-final (8 → 4)","8 强(8 进 4)","รอบ 8 ทีม (8 → 4)"],5:["Semi-final (4 → 2)","半决赛(4 进 2)","รอบรองชนะเลิศ (4 → 2)"],6:["Final (2 → 1)","决赛(2 进 1)","รอบชิงชนะเลิศ (2 → 1)"]},w=e=>{const o=m[e];return o?k(o[0],o[1],o[2]):`R${e}`};let v=0;const _=e=>{e?.server_now&&(v=Date.parse(e.server_now)-Date.now())},N=e=>k(`${Math.floor(e/60)} min ${e%60} s`,`${Math.floor(e/60)} 分 ${e%60} 秒`,`${Math.floor(e/60)} นาที ${e%60} วินาที`);function C(e){const o=function(e){return e.next_at&&"done"!==e.state?Math.max(0,Math.round((Date.parse(e.next_at)-(Date.now()+v))/1e3)):null}(e);if(null===o)return null;const t=w("open"===e.state?1:e.round+1);return o>0?k(`⏱ ${t} starts in ${N(o)}`,`⏱ ${N(o)}后开始 ${t}`,`⏱ ${t} เริ่มในอีก ${N(o)}`):k(`⏱ ${t} is starting now`,`⏱ ${t} 马上开始`,`⏱ ${t} กำลังเริ่ม`)}const A=e=>"knobs"===e?k("🔧 KNOBS cup","🔧 旋钮杯","🔧 ถ้วย KNOBS"):"code"===e?k("✍ CODE cup","✍ 代码杯","✍ ถ้วย CODE"):"",B=e=>"knobs"===e?k("only the 15-knob bot — no editing code, no AI help: template knobs, then set <KNOB> <value>, then up","只收 15 个旋钮的 bot —— 不改代码、不用 AI:template knobs,再 set <旋钮> <值>,再 up","รับเฉพาะ bot แบบ 15 knobs — ห้ามแก้โค้ด ห้ามใช้ AI: template knobs แล้ว set <KNOB> <ค่า> แล้ว up"):"code"===e?k("any Python bot — write your own act(u); AI help is allowed (the knob bot is fine too)","任何 Python bot 都可以 —— 自己写 act(u),可以用 AI 帮忙(旋钮 bot 也行)","รับ bot Python แบบใดก็ได้ — เขียน act(u) เอง ใช้ AI ช่วยได้ (bot แบบ knobs ก็ได้)"):"",O=e=>({1:"R64",2:"R32",3:"R16",4:"QF",5:"SF",6:"F"}[e]??`R${e}`),j=e=>{let o=0;for(const t of e){const e=t.codePointAt(0)??0;e>=3633&&e<=3642&&3634!==e&&3635!==e||e>=3655&&e<=3662||(o+=e>65535||e>=11904&&e<=42191||e>=44032&&e<=55203||e>=63744&&e<=64255?2:1)}return o},x=(e,o)=>e+" ".repeat(Math.max(0,o-j(e))),T=e=>{if(!e)return chalk.gray("—");const o="filler"===e.kind?`🤖 ${e.nick}`:e.nick,t=chalk.gray(` #${e.slot}`);return e.forfeit?chalk.gray(`${o} #${e.slot} (${k("no bot","没交 bot","ไม่มี bot")})`):(e.me?chalk.bold.yellow(o):chalk.white(o))+t};function E(e){if(!e?.versions.length)return null;const o=e.chosen_version;return o&&e.versions.some(e=>e.version===o)?o:e.versions[e.versions.length-1].version}function I(e){const o=e.me;if(!o?.versions.length)return void console.log(chalk.gray(k(" No versions yet — up uploads your bot as v1."," 还没有版本 —— up 上传后就是 v1。"," ยังไม่มีเวอร์ชัน — up เพื่ออัปโหลดเป็น v1")));const t=o.locked_version??E(o);console.log(),console.log(chalk.bold.white(k(" Your versions in this cup"," 你在这个杯赛的版本"," เวอร์ชันของคุณในถ้วยนี้")));for(const e of o.versions){const n=(e.ts||"").replace("T"," ").slice(5,16),a=e.version===t;console.log(` ${a?o.locked_version?"🔒":"★":" "} ${a?chalk.bold.green(`v${e.version}`):chalk.white(`v${e.version}`)}`+chalk.gray(` ${n} UTC · ${e.sha.slice(0,8)}`)+(a?chalk.green(o.locked_version?k(" ← locked, this one plays"," ← 已锁定,比赛用它"," ← ล็อกแล้ว ตัวนี้ลงแข่ง"):k(" ← your entry"," ← 正式参赛版本"," ← ตัวที่ส่งแข่ง")):""))}(o.can_edit??"open"===e.state)&&o.versions.length>1&&console.log(chalk.gray(" ▸ ")+chalk.bold.green(`use ${(o.versions.find(e=>e.version!==t)??o.versions[0]).version}`)+chalk.gray(k(" make another version your entry (until the next round starts)"," 把另一个版本设为正式参赛版本(下一轮开始前都能换)"," เปลี่ยนเวอร์ชันที่ส่งแข่ง (เปลี่ยนได้จนกว่ารอบถัดไปจะเริ่ม)")))}function S(e,o){switch(e){case"no_cup":return k("No cup with that passcode — check it with your teacher.","没有这个口令的杯赛 —— 跟老师核对一下口令。","ไม่มีถ้วยที่ใช้รหัสนี้ — ลองถามครูอีกครั้ง");case"closed":return k("Registration is closed — the bracket has started.","报名已截止 —— 对阵已经开始。","ปิดรับสมัครแล้ว — การแข่งขันเริ่มแล้ว");case"full":return k("The cup is full (64 players).","杯赛满了(64 人)。","ถ้วยเต็มแล้ว (64 คน)");case"same_device":return k("This computer already has a player in this cup — one person, one computer, one entry.","这台电脑已经有人报名了这个杯赛 —— 一人、一台电脑、一个名额。","คอมพิวเตอร์เครื่องนี้มีผู้เล่นในถ้วยนี้แล้ว — หนึ่งคน หนึ่งเครื่อง หนึ่งสิทธิ์");case"nick_taken":return k("That nickname is taken — pick another.","这个昵称被用了 —— 换一个。","ชื่อเล่นนี้มีคนใช้แล้ว — เลือกชื่ออื่น");case"bad_nick":return k("Nickname: 2–12 letters, digits, _ or - (no spaces, not your real name).","昵称:2–12 个字母、数字、_ 或 -(不要空格,不要真名)。","ชื่อเล่น: ตัวอักษรอังกฤษ ตัวเลข _ หรือ - จำนวน 2–12 ตัว (ไม่มีช่องว่าง ไม่ใช้ชื่อจริง)");case"locked":return k("Bots were locked when round 1 started — you play with the version shown above.","第一轮开始时 bot 已锁定 —— 比赛用的是上面显示的那个版本。","bot ถูกล็อกตอนเริ่มรอบแรกแล้ว — ใช้เวอร์ชันที่แสดงด้านบน");case"has_slot":return k("You already have a number — it stays yours.","你已经有号码了,不能再换。","คุณมีหมายเลขแล้ว — เปลี่ยนไม่ได้");case"wrong_course":return k("The cup is for BattleAI tokens (battleai-48).","杯赛只对 BattleAI 课程 token(battleai-48)开放。","ถ้วยนี้สำหรับ token ของ BattleAI (battleai-48) เท่านั้น");default:return o||k("The server did not answer — try again.","服务器没有回应 —— 再试一次。","เซิร์ฟเวอร์ไม่ตอบ — ลองอีกครั้ง")}}const K=(e,o)=>{const t=e.entrants.find(e=>e.slot===o);return t?{slot:o,nick:t.nick,kind:t.kind,level:t.level,forfeit:0,me:e.me?.slot===o}:null};function z(e,o){const t=e.a?.slot===o,[n,a]=t?[e.wins_a,e.wins_b]:[e.wins_b,e.wins_a],s=e.winner_slot===o,r="tiebreak"===e.decided_by?k(" (tie-break game)","(加赛一局定胜负)"," (เกมตัดสิน)"):"value"===e.decided_by?k(" (army value)","(按兵力价值)"," (ตัดสินด้วยมูลค่ากองทัพ)"):"coin"===e.decided_by?k(" (coin toss)","(抽签)"," (เสี่ยงทาย)"):"walkover"===e.decided_by?k(" (walkover)","(对手弃权)"," (ชนะบาย)"):"admin"===e.decided_by?k(" (decided by the teacher)","(老师判定)"," (ครูตัดสิน)"):"",l=null!=n&&null!=a?` ${n}-${a}`:"";return(s?chalk.green(`✅ ${k("won","赢","ชนะ")}${l}`):chalk.red(`❌ ${k("lost","输","แพ้")}${l}`))+chalk.gray(r)}function M(e){console.log();const o="open"===e.state?e.next_at?k("registration open","报名中","เปิดรับสมัคร"):k("registration open — waiting for the teacher to start","报名中 —— 等老师开赛","เปิดรับสมัคร — รอครูเริ่มการแข่งขัน"):"done"===e.state?k("finished","已结束","จบแล้ว"):`${w(e.round)} · ${"judging"===e.round_state?k("playing now","正在比赛","กำลังแข่ง"):"done"===e.round_state?k("done — break before the next round","本轮结束 —— 下一轮之前休息","จบรอบแล้ว — พักก่อนรอบถัดไป"):e.round_state}`;console.log(chalk.bold.white(` 🏆 ${e.label||e.cup}`)+(e.division?chalk.bold.cyan(` · ${A(e.division)}`):"")+chalk.gray(` · ${o} · ${e.players} ${k("players","人","คน")}`));const t=C(e);t&&console.log(chalk.bold.yellow(` ${t}`));const n=e.me;if(!n)return;const a=n.slot;if(console.log(chalk.white(` ${k("You","你","คุณ")}: `)+chalk.bold.yellow(n.nick)+chalk.gray(a?` #${a}`:` · ${k("no number yet","还没选号","ยังไม่ได้เลือกหมายเลข")}`)+chalk.gray(n.locked_version?` · 🔒 bot v${n.locked_version}`:n.forfeit?` · ${k("no bot — out","没交 bot,弃权","ไม่มี bot — ตกรอบ")}`:n.versions.length?` · bot v${n.versions[n.versions.length-1].version}`:` · ${k("no bot uploaded yet","还没上传 bot","ยังไม่ได้อัปโหลด bot")}`)),!a)return;const s=function(e){const o=new Set;for(const t of e.bracket)for(const e of t)if("done"===e.state)for(const t of[e.a,e.b])t&&t.slot!==e.winner_slot&&o.add(t.slot);return o}(e);let r=!n.forfeit;for(let o=1;o<=6;o++){const t=chalk.cyan(x(O(o),4)),n=e.bracket[o-1]?.find(e=>e.a?.slot===a||e.b?.slot===a);if(n){const e=n.a?.slot===a?n.b:n.a,o="done"===n.state?z(n,a):"judging"===n.state?chalk.yellow(`⚖ ${k("playing…","正在判…","กำลังแข่ง…")}`):"error"===n.state?chalk.yellow(k("⚖ judge hiccup — the teacher will re-run it","⚖ 判分出了点问题,老师会重判","⚖ ระบบตัดสินขัดข้อง — ครูจะสั่งแข่งใหม่")):chalk.gray(k("waiting","等待","รอ")),s=n.replays?chalk.gray(` 🎬 replay ${n.id} 1`):"";if(console.log(` ${t} vs ${T(e)} ${o}${s}`),"done"===n.state&&n.winner_slot!==a){r=!1,console.log(chalk.gray(k(" ↳ Your run ends here. Keep watching: bracket, and replay any game."," ↳ 你的比赛到这里结束。可以继续看:bracket 看对阵,replay 看任何一局。"," ↳ เส้นทางของคุณจบที่นี่ ดูต่อได้: bracket ดูสาย และ replay ดูเกมไหนก็ได้")));break}continue}if(!r)break;const l=1<<o-1,i=(a-1>>o<<o)+((a-1>>o-1)%2==0?l:0)+1,c=[];for(let o=i;o<i+l;o++){if(s.has(o))continue;const t=K(e,o);t&&c.push(t)}const u=c.slice(0,3).map(e=>T(e)),d=c.length>3?chalk.gray(" +"+(c.length-3)):"",g=chalk.gray(l>1?` (#${i}–${i+l-1})`:` (#${i})`);"open"===e.state&&1===o?console.log(` ${t} vs ${c.length?u.join(chalk.gray(" · ")):chalk.gray(k("a bot, drawn when round 1 starts","开赛时抽到的 bot","bot ที่จะสุ่มตอนเริ่มรอบแรก"))}${g}`):console.log(` ${t} ${chalk.gray(k("next: one of","可能对上:","อาจเจอ:"))} ${c.length?u.join(chalk.gray(" · "))+d:chalk.gray("open"===e.state?k("bots, drawn at the start","开赛时抽到的 bot","bot ที่จะสุ่มตอนเริ่ม"):k("(to be decided)","(待定)","(ยังไม่รู้)"))}${g}`)}if("done"===e.state&&e.champion_slot){const o=K(e,e.champion_slot);console.log(chalk.bold.yellow(` 🏆 ${k("Champion","冠军","แชมป์")}: `)+(o?T(o):"?")+(o&&o.slot===a?chalk.bold.green(k(" — that is you! 🎉"," —— 就是你!🎉"," — คือคุณ! 🎉")):""))}}function P(e,o){const t=e.bracket[o-1];if(t){console.log(chalk.bold.white(` ${w(o)}`)+chalk.gray(` · ${t.length} ${k("matches","场","นัด")}`));for(const e of t){const o="done"===e.state&&null!=e.winner_slot&&e.winner_slot===e.a?.slot,t="done"===e.state&&null!=e.winner_slot&&e.winner_slot===e.b?.slot,n="done"===e.state?null!=e.wins_a?`${e.wins_a}-${e.wins_b}`:"walkover"===e.decided_by?"w/o":"—":"judging"===e.state?"⚖":"…",a=e.a?"filler"===e.a.kind?`🤖${e.a.nick}`:e.a.nick:"—",s=e.b?"filler"===e.b.kind?`🤖${e.b.nick}`:e.b.nick:"—",r=e.a?.me||e.b?.me,l=(o,t)=>t?chalk.bold.green(o):"done"===e.state?chalk.gray(o):chalk.white(o);console.log(` ${chalk.gray(x(`#${e.id}`,6))}${l(x(a,14),o)} ${chalk.cyan(x(n,5))} ${l(x(s,14),t)}`+(e.replays?chalk.gray(" 🎬"):"")+(r?chalk.yellow(k(" ← you"," ← 你"," ← คุณ")):""))}console.log(chalk.gray(k(" replay <match#> <game#> — e.g. replay 41 1"," replay <场号> <局号> —— 例如 replay 41 1"," replay <เลขนัด> <เลขเกม> — เช่น replay 41 1")))}else console.log(chalk.gray(k(` ${w(o)} has not started yet.`,` ${w(o)}还没开始。`,` ${w(o)} ยังไม่เริ่ม`)))}function R(e){const o=e.entrants.filter(e=>"player"===e.kind);console.log(chalk.bold.white(` ${o.length} ${k("players","人报名","ผู้เล่น")}`));const t=o.map(e=>`${e.nick}${e.slot?`#${e.slot}`:""}${e.has_bot?" ✓":""}`);for(let e=0;e<t.length;e+=3)console.log(" "+t.slice(e,e+3).map(e=>chalk.white(x(e,20))).join(""));console.log(chalk.gray(k(" ✓ = bot uploaded"," ✓ = 已上传 bot"," ✓ = อัปโหลด bot แล้ว")))}function D(e,o){const t=function(e){const o=new Set(e.entrants.map(e=>e.slot).filter(e=>!!e)),t=[];for(let e=1;e<=64;e++)o.has(e)||t.push(e);return t}(e);if(!t.length)return void console.log(chalk.yellow(k(" No free numbers left."," 没有空号了。"," ไม่มีหมายเลขว่างแล้ว")));o&&console.log(chalk.white(` ${k("Closest free","离得最近的空号","หมายเลขว่างที่ใกล้ที่สุด")}: `)+t.slice().sort((e,t)=>Math.abs(e-o)-Math.abs(t-o)||e-t).slice(0,4).map(e=>chalk.bold.green(`pick ${e}`)).join(chalk.gray(" · ")));const n=new Set(t);for(const[e,o]of[[k("left ","左半区","ซ้าย "),1],[k("right ","右半区","ขวา "),33]]){const t=[];for(let e=o;e<o+32;e++)t.push(n.has(e)?chalk.green(String(e).padStart(2)):chalk.gray(" ·"));console.log(chalk.gray(` ${e} `)+t.slice(0,16).join(" ")),console.log(chalk.gray(` ${" ".repeat(j(e))} `)+t.slice(16).join(" "))}console.log(chalk.gray(k(" green = free · grey dot = taken"," 绿色 = 空号 · 灰点 = 已被选"," สีเขียว = ว่าง · จุดเทา = มีคนเลือกแล้ว")))}function L(o){const t=o.me,n=e=>chalk.bold.green(e),a=(e,o)=>console.log(` ${e?"✅":"⬜"} ${e?chalk.gray(o):chalk.white(o)}`),s=!!t?.versions.length;console.log(),o.division&&console.log(` ${chalk.bold.cyan(A(o.division))}${chalk.gray(` — ${B(o.division)}`)}`),a(!!t,k(`joined as ${t?.nick??"?"}`,`已报名,昵称 ${t?.nick??"?"}`,`สมัครแล้ว ชื่อ ${t?.nick??"?"}`)),a(!!t?.slot,t?.slot?k(`your number: #${t.slot}`,`你的号码:#${t.slot}`,`หมายเลขของคุณ: #${t.slot}`):k("pick a number 1–64: pick 17 (or pick random)","选一个 1–64 的号码:pick 17(或 pick random)","เลือกหมายเลข 1–64: pick 17 (หรือ pick random)"));const r=E(t),l=t?.versions.length??0;a(s||!!t?.locked_version,t?.locked_version?k(`bot locked: v${t.locked_version}`,`bot 已锁定:v${t.locked_version}`,`bot ถูกล็อก: v${t.locked_version}`):s?k(`your entry: v${r} (${l} version${1===l?"":"s"}) — up = new version · versions = list · use N = switch`,`正式参赛版本:v${r}(共 ${l} 个版本)—— up = 新版本 · versions = 列表 · use N = 换版本`,`ตัวที่ส่งแข่ง: v${r} (มี ${l} เวอร์ชัน) — up = เวอร์ชันใหม่ · versions = รายการ · use N = เปลี่ยน`):"knobs"===o.division?k("make and upload your knob bot: template knobs → set WOMBATS 6 → up (no bot by round 1 = you forfeit)","做好并上传旋钮 bot:template knobs → set WOMBATS 6 → up(第一轮开始还没交 = 弃权)","สร้างและอัปโหลด bot แบบ knobs: template knobs → set WOMBATS 6 → up (ไม่มี bot ตอนเริ่มรอบแรก = สละสิทธิ์)"):k("upload your bot: up (no bot by round 1 = you forfeit)","上传 bot:up(第一轮开始还没交 = 弃权)","อัปโหลด bot: up (ไม่มี bot ตอนเริ่มรอบแรก = สละสิทธิ์)")),a("open"!==o.state,"open"===o.state?k("wait for round 1 to start","等第一轮开始","รอรอบแรกเริ่ม"):k("the bracket has started","对阵已开始","การแข่งขันเริ่มแล้ว")),"running"===o.state&&t&&(!1===t.alive?console.log(chalk.gray(k(" 👀 You are out of this cup — well played! Watch the others: bracket · replay <match#> 1"," 👀 你已经被淘汰了 —— 打得不错!看看别人:bracket · replay <场号> 1"," 👀 คุณตกรอบแล้ว — เล่นได้ดีมาก! ดูคนอื่น: bracket · replay <นัด> 1"))):"judging"===o.round_state?console.log(chalk.yellow(k(" ⚖ This round is being played — bots are LOCKED. Wait for the result (press Enter to check)."," ⚖ 这一轮正在比赛 —— bot 已锁定。等结果(按回车查看)。"," ⚖ กำลังแข่งรอบนี้ — bot ถูกล็อก รอผล (กด Enter เพื่อดู)"))):t.can_edit&&console.log(chalk.bold.green(k(" 🛠 BREAK — you are still in! You may change your bot now: set … then up (or use N)."," 🛠 休息时间 —— 你还在比赛里!现在可以改 bot:set … 再 up(或者 use N 换版本)。"," 🛠 พัก — คุณยังอยู่ในการแข่งขัน! เปลี่ยน bot ได้ตอนนี้: set … แล้ว up (หรือ use N)"))+chalk.gray(k(" It locks when the next round starts.","下一轮开始时锁定。"," จะล็อกเมื่อรอบถัดไปเริ่ม"))));const c=C(o);c&&console.log(chalk.bold.yellow(` ${c}`));const u=t?.slot?s||"open"!==o.state?"path":"knobs"!==o.division||e(i)?"up":"template knobs":"pick 17";console.log(chalk.gray(" ▸ ")+chalk.gray(k("next: ","下一步敲 ","พิมพ์ต่อไป: "))+n(u)+chalk.gray(" ▸ ")+n("guide")+chalk.gray(k(" the full sheet"," 完整说明"," คำอธิบายทั้งหมด")))}function W(e,o,t){"knobs"===o&&console.log(chalk.gray(k(" 🔧 template knobs · knobs (see them) · set <KNOB> <value> · up"," 🔧 template knobs · knobs 看旋钮 · set <旋钮> <值> · up"," 🔧 template knobs · knobs (ดู knobs) · set <KNOB> <ค่า> · up"))),console.log(chalk.gray(k(` Enter = my path · pick N · up · versions · use N · bracket [round] · who · replay <match#> <game#> · web · guide · lang en|zh|th · card (${e})`,` 回车 = 我的路线 · pick N 选号 · up 上传 · versions 版本 · use N 选版本 · bracket [轮] · who · replay <场号> <局号> · web · guide · lang en|zh|th · card 回卡片 (${e})`,` Enter = เส้นทางของฉัน · pick N · up · versions · use N · bracket [รอบ] · who · replay <นัด> <เกม> · web · guide · lang en|zh|th · card (${e})`)))}function Y(e,o){const t=e=>chalk.bold.green(e),n=e=>chalk.gray(e);console.log(),console.log(chalk.bold.white(k(" 🏆 The cup — how it works"," 🏆 杯赛怎么玩"," 🏆 ถ้วย — เล่นอย่างไร"))),o&&(console.log(` ${chalk.bold.cyan(A(o))}${n(` — ${B(o)}`)}`),console.log(n(k(" There are two cups today: 🔧 KNOBS (only the 15 knob values, no AI) and ✍ CODE (your own Python, AI allowed). You may enter both — one bot in each."," 今天有两个杯赛:🔧 旋钮杯(只改 15 个旋钮的值,不用 AI)和 ✍ 代码杯(自己写 Python,可以用 AI)。两个都可以参加 —— 每个杯赛各交一个 bot。"," วันนี้มีสองถ้วย: 🔧 KNOBS (เปลี่ยนเฉพาะค่า 15 knobs ห้ามใช้ AI) และ ✍ CODE (เขียน Python เอง ใช้ AI ได้) เข้าได้ทั้งสองถ้วย — ถ้วยละหนึ่ง bot"))));const a=[["pick 17","choose your number 1–64 — first come, first served. Taken? the free numbers are shown, pick one. Once it is yours it never changes","选 1–64 的号码 —— 先到先得。被占了会列出空号,再选一个。选定之后不能再换","เลือกหมายเลข 1–64 — ใครมาก่อนได้ก่อน ถ้ามีคนใช้แล้วจะแสดงหมายเลขว่างให้เลือก เลือกแล้วเปลี่ยนไม่ได้"],["pick random","let the system draw a free number","让系统随机给一个空号","ให้ระบบสุ่มหมายเลขว่างให้"],["up","upload ~/.icoa/battleai/bot.py as a NEW version (v1, v2, v3 …); the newest becomes your entry. Old versions are kept","把 ~/.icoa/battleai/bot.py 上传成一个新版本(v1、v2、v3…),最新的自动成为正式参赛版本;旧版本都保留","อัปโหลด ~/.icoa/battleai/bot.py เป็นเวอร์ชันใหม่ (v1, v2, v3 …) ตัวล่าสุดจะเป็นตัวที่ส่งแข่ง เวอร์ชันเก่ายังเก็บไว้"],["versions","list every version you uploaded; ★ = your entry","列出你上传过的所有版本;★ = 正式参赛版本","แสดงทุกเวอร์ชันที่อัปโหลด ★ = ตัวที่ส่งแข่ง"],["use 2","make v2 your entry instead — the server checks it can really play first (before round 1, and in every break while you are still in)","改用 v2 作为正式参赛版本 —— 服务器会先检查它真的能打(第一轮之前,以及你还在比赛时的每次休息)","ใช้ v2 เป็นตัวที่ส่งแข่งแทน — เซิร์ฟเวอร์จะตรวจก่อนว่าเล่นได้จริง (ก่อนรอบแรก และทุกช่วงพักถ้ายังไม่ตกรอบ)"],["bots","every version you ever uploaded (cups + rooms) · show N = see its knobs or code · get N = save it · restore N = back into bot.py","你上传过的所有版本(杯赛 + 房间)· show N 看旋钮或代码 · get N 存成文件 · restore N 放回 bot.py","ทุกเวอร์ชันที่เคยอัปโหลด (ถ้วย + ห้อง) · show N = ดู knobs หรือโค้ด · get N = บันทึก · restore N = ใส่กลับเข้า bot.py"],["lang th","switch the language: lang en · lang zh · lang th","切换语言:lang en · lang zh · lang th","เปลี่ยนภาษา: lang en · lang zh · lang th"],["template knobs","puts the 15-knob starter at bot.py (already have one? template knobs force; the old file becomes bot.py.bak)","把 15 个旋钮的起步 bot 放到 bot.py(已经有了?template knobs force,旧文件留作 bot.py.bak)","วาง bot เริ่มต้นแบบ 15 knobs ไว้ที่ bot.py (มีอยู่แล้ว? template knobs force ไฟล์เดิมจะเป็น bot.py.bak)"],["knobs","list the 15 knobs and their values","列出 15 个旋钮和现在的值","แสดง knobs ทั้ง 15 ตัวและค่าปัจจุบัน"],["set WOMBATS 6","change one knob value in bot.py (no editor needed)","改 bot.py 里一个旋钮的值(不用编辑器)","เปลี่ยนค่า knob หนึ่งตัวใน bot.py (ไม่ต้องเปิด editor)"],["Enter","your path: this round, who you may meet next, the road to the final","我的路线:这一轮对手、下一轮可能遇到谁、到决赛的路","เส้นทางของคุณ: คู่แข่งรอบนี้ ใครที่อาจเจอต่อไป และทางสู่รอบชิง"],["bracket 2","one round, every match (no number = the current round)","看某一轮的全部对阵(不写 = 当前轮)","ดูทุกนัดของรอบหนึ่ง (ไม่ใส่เลข = รอบปัจจุบัน)"],["replay 41 1","watch match #41, game 1 (any match, any player)","看第 41 场的第 1 局(任何一场都能看)","ดูนัด #41 เกมที่ 1 (ดูได้ทุกนัด)"],["who","everyone in the cup and their numbers","所有报名的人和号码","ผู้เล่นทุกคนและหมายเลข"],["web","the address of the big bracket page (projector / phone)","大屏 / 手机看的对阵图网址","ที่อยู่หน้าสายการแข่งขัน (โปรเจกเตอร์ / มือถือ)"]];for(const[e,o,s,r]of a)console.log(` ${t(x(e,16))}${n(k(o,s,r))}`);console.log(),console.log(chalk.bold.white(k(" Rules"," 规则"," กติกา")));for(const[e,o,t]of[["64 numbers. Numbers nobody picked get graded bots (gauntlet levels, spread across the bracket).","64 个号码。没人选的号码由分档 bot 补上(挑战台等级,分散在整个对阵里)。","64 หมายเลข หมายเลขที่ไม่มีใครเลือกจะใส่ bot ตามระดับ (กระจายทั่วสาย)"],["Knock-out, left half (#1–32) and right half (#33–64) meet in the final: 64 → 32 → 16 → 8 → 4 → 2 → champion.","单败淘汰,左半区(#1–32)和右半区(#33–64)在决赛相遇:64 进 32 → 32 进 16 → 16 进 8 → 8 进 4 → 半决赛 → 决赛。","แพ้คัดออก ครึ่งซ้าย (#1–32) และครึ่งขวา (#33–64) เจอกันในรอบชิง: 64 → 32 → 16 → 8 → 4 → 2 → แชมป์"],["A match = one game on each of the 3 maps; from the quarter-final on, 5 games (+ Ballarat and Murray again). More game wins goes through. Every round has new seeds = new layouts.","一场 = 3 张图各一局;8 强起每场 5 局(再加 Ballarat、Murray 各一局)。赢得局数多的晋级。每一轮都换新种子 = 新地形。","หนึ่งนัด = 3 แผนที่ แผนที่ละ 1 เกม ตั้งแต่รอบ 8 ทีม = 5 เกม (เพิ่ม Ballarat และ Murray) ชนะมากกว่าได้ไปต่อ ทุกรอบใช้ seed ใหม่ = แผนที่แบบใหม่"],["Level after 3 games → one tie-break game; still level → higher army value.","3 局打平 → 加赛一局;还是平 → 比兵力价值。","เสมอหลัง 3 เกม → เกมตัดสิน 1 เกม ยังเสมอ → เทียบมูลค่ากองทัพ"],["Your ENTRY version (★ in versions) LOCKS when a round starts. No bot when round 1 starts = you forfeit.","每一轮开始时锁定你的正式参赛版本(versions 里的 ★)。第一轮开始时还没上传 = 弃权。","เวอร์ชันที่ส่งแข่ง (★ ใน versions) จะถูกล็อกเมื่อแต่ละรอบเริ่ม ถ้าไม่มี bot ตอนรอบแรกเริ่ม = สละสิทธิ์"],["After every round there is a BREAK (a countdown shows how long). Still in? Change your bot: set … → up, or use N. Out? Watch the replays.","每一轮结束后有休息时间(倒计时会显示还剩多久)。还在比赛里?改 bot:set … → up,或 use N。被淘汰了?去看回放。","หลังจบแต่ละรอบมีช่วงพัก (มีนับถอยหลัง) ยังไม่ตกรอบ? เปลี่ยน bot: set … → up หรือ use N ตกรอบแล้ว? ดูรีเพลย์"],["One person, one computer, one entry: a second account on the same computer is refused.","一人、一台电脑、一个名额:同一台电脑的第二个账号进不来。","หนึ่งคน หนึ่งเครื่อง หนึ่งสิทธิ์: บัญชีที่สองบนเครื่องเดียวกันจะถูกปฏิเสธ"]])console.log(n(` · ${k(e,o,t)}`));console.log(n(` ${k("Big bracket","大屏对阵图","สายการแข่งขัน")}: ${b}${e}`))}async function q(e){for(;;){const o=await e(chalk.white(k(" Nickname for the cup (2–12 letters/digits, not your real name; empty = cancel): "," 杯赛昵称(2–12 个字母/数字,不要真名;直接回车 = 取消):"," ชื่อเล่นในถ้วย (2–12 ตัวอักษร/ตัวเลข ไม่ใช่ชื่อจริง; Enter เปล่า = ยกเลิก): ")));if(null===o)return null;const t=o.trim();if(!t)return null;if(/^[A-Za-z0-9_-]{2,12}$/.test(t))return t;console.log(chalk.yellow(" "+S("bad_nick")))}}export async function runCup(s,l,p,y={}){const m=p.trim().replace(/^(?:join|enter|进)\s+/i,"").toUpperCase().replace(/[^A-Z0-9]/g,"").slice(0,8);if(!m){const e=await $("status",s);if(console.log(),console.log(chalk.bold.white(k(" 🏆 Cup"," 🏆 杯赛"," 🏆 ถ้วย"))+chalk.gray(k(" — the 64-player knock-out your teacher runs."," —— 老师组织的 64 强淘汰赛。"," — การแข่งแบบแพ้คัดออก 64 คนที่ครูจัด"))),e.ok&&e.data?.cups.length)for(const o of e.data.cups)console.log(` ${chalk.bold.cyan(x(o.cup,7))} ${chalk.white(x(o.label||"",22))} ${chalk.cyan(x(A(o.division),14))}${chalk.gray(`${k("you are","你是","คุณคือ")} ${o.nick}`)}`);else e.ok||console.log(chalk.yellow(" "+S(e.code,e.message)));return console.log(chalk.gray(" ▸ ")+chalk.bold.green(k("cup <PASSCODE>","cup <口令>","cup <รหัส>"))+chalk.gray(k(" the passcode comes from your teacher, e.g. cup BKK26"," 口令由老师给,例如 cup BKK26"," รหัสได้จากครู เช่น cup BKK26"))),"back"}let w=null;const v=await $("status",s,{cup:m});if(v.ok&&v.data)w=v.data;else{if("not_member"!==v.code)return console.log(chalk.yellow(" "+S(v.code,v.message))),"back";{const e=await $("join",s,{cup:m,probe:!0});if(!e.ok||!e.data)return console.log(chalk.yellow(" "+S(e.code,e.message))),"back";if(console.log(chalk.white(` ${k("Entering","进入","กำลังเข้า")} `)+chalk.bold.cyan(m)+chalk.gray(` ${e.data.label||""} · ${e.data.players} ${k("players","人","คน")}`)),e.data.division&&console.log(` ${chalk.bold.cyan(A(e.data.division))}${chalk.gray(` — ${B(e.data.division)}`)}`),"open"!==e.data.state)return console.log(chalk.yellow(" "+S("closed"))+chalk.gray(` ${b}${m}`)),"back";for(let e=0;e<4&&!w;e++){const e=await q(l);if(null===e)return"back";const o=await $("join",s,{cup:m,nick:e});if(o.ok&&o.data)w=o.data;else if(console.log(chalk.yellow(" "+S(o.code,o.message))),"same_device"===o.code||"closed"===o.code||"full"===o.code)return"back"}if(!w)return"back";Y(m,w.division)}}const N=chalk.bold.magenta(`icoa cup ${m}> `),C=async()=>{const e=await $("status",s,{cup:m});return e.ok&&e.data?(w=e.data,_(w),!0):(console.log(chalk.yellow(" "+S(e.code,e.message))),!1)};for(_(w),L(w),M(w),W(m,w.division);;){const p=await l(N);if(null===p)return"back";const v=p.trim(),_=v.toLowerCase();if(f.has(_))return"back";if("menu"===_)return"menu";if(!v||/^(?:path|me|route|路线|เส้นทาง|status)$/i.test(v)){await C()&&M(w),W(m,w.division);continue}if(/^(?:help|\?|帮助|ช่วย)$/i.test(v)){await C(),L(w),W(m,w.division);continue}if(/^(?:guide|说明|คู่มือ)$/i.test(v)){Y(m,w.division),W(m,w.division);continue}if(/^(?:web|url|网页)$/i.test(v)){console.log(chalk.white(` ${b}${m}`)+chalk.gray(k(" — open on the projector or a phone"," —— 投影或手机打开"," — เปิดบนโปรเจกเตอร์หรือมือถือ")));continue}if(/^(?:who|players|名单|ผู้เล่น)$/i.test(v)){await C()&&R(w);continue}const A=/^(?:bracket|round|对阵|สาย)(?:\s+(\d))?$/i.exec(v);if(A){await C()&&P(w,A[1]?Number(A[1]):Math.max(1,w.round));continue}const B=/^(?:pick|选|เลือก)(?:\s+(random|\d+))?$/i.exec(v);if(B){if(!B[1]){console.log(chalk.gray(k(" pick 17 — a number 1–64, or pick random"," pick 17 —— 1–64 的号码,或 pick random"," pick 17 — หมายเลข 1–64 หรือ pick random")));continue}const e="random"===B[1].toLowerCase(),o=Number(B[1]);if(!(e||o>=1&&o<=64)){console.log(chalk.yellow(k(" Numbers go from 1 to 64 — e.g. pick 17"," 号码是 1 到 64 —— 例如 pick 17"," หมายเลขคือ 1 ถึง 64 — เช่น pick 17")));continue}if(w.me?.slot){console.log(chalk.yellow(" "+S("has_slot"))+chalk.gray(` #${w.me.slot}`));continue}const t=await l(chalk.bold.white(e?k(" Let the system give you a free number? It can NOT be changed afterwards. Type yes (Enter = cancel): "," 让系统给你一个空号?之后不能再换。敲 yes 确认(直接回车 = 取消):"," ให้ระบบเลือกหมายเลขว่างให้? เปลี่ยนภายหลังไม่ได้ พิมพ์ yes (Enter = ยกเลิก): "):k(` Take number #${o}? Once it is yours it can NOT be changed. Type yes (Enter = cancel): `,` 要 #${o} 号吗?选了之后不能再换。敲 yes 确认(直接回车 = 取消):`,` เอาหมายเลข #${o}? เลือกแล้วเปลี่ยนไม่ได้ พิมพ์ yes (Enter = ยกเลิก): `)));if(null===t)return"back";if(!/^(?:y|yes|ok|是|好|确认|ใช่|ตกลง)$/i.test(t.trim())){console.log(chalk.gray(k(" Cancelled — no number taken."," 已取消 —— 没有选号。"," ยกเลิกแล้ว — ยังไม่ได้เลือกหมายเลข")));continue}const n=await $("pick",s,e?{cup:m,random:!0}:{cup:m,slot:o});if(n.ok&&n.data){w=n.data;const e=n.data.how??"";console.log(chalk.green(" ✓ ")+chalk.bold.white(k(`Number #${n.data.picked} is yours for the whole cup`,`#${n.data.picked} 号是你的了,整个杯赛都不变`,`หมายเลข #${n.data.picked} เป็นของคุณตลอดการแข่งขัน`))+chalk.gray("random_after_2_clashes"===e?k(" — second clash, so the system drew it for you"," —— 第二次撞号,系统帮你抽的"," — ชนเป็นครั้งที่สอง ระบบจึงสุ่มให้"):"random_asked"===e?k(" — drawn at random"," —— 随机抽的"," — สุ่มให้"):"")),L(w)}else"taken"===n.code?(console.log(chalk.yellow(k(` #${o} is already taken — choose one of the free numbers below.`,` #${o} 已经被别人选了 —— 从下面的空号里再选一个。`,` #${o} มีคนเลือกแล้ว — เลือกหมายเลขว่างด้านล่าง`))),await C()&&D(w,o)):console.log(chalk.yellow(" "+S(n.code,n.message)));continue}const O=/^lang(?:\s+(\S+))?$/i.exec(v);if(O){const e=(O[1]??"").toLowerCase().slice(0,2);if(!["en","zh","th"].includes(e)){console.log(chalk.gray(` ${k("language","语言","ภาษา")}: `)+chalk.white(h())+chalk.gray(" · ")+["en","zh","th"].map(e=>chalk.bold.green(`lang ${e}`)).join(chalk.gray(" / ")));continue}r({language:e}),console.log(chalk.green(" ✓ ")+chalk.gray("zh"===e?"语言 → ":"th"===e?"ภาษา → ":"language → ")+chalk.white(e)),await C()&&L(w),W(m,w.division);continue}if(await c(v,s,`CUP-${m}`))continue;if(/^(?:versions?|版本|เวอร์ชัน)$/i.test(v)){await C()&&I(w);continue}const j=/^(?:use|用|ใช้)(?:\s+v?(\d+))?$/i.exec(v);if(j){if(!j[1]){await C()&&I(w);continue}const e=await $("use",s,{cup:m,version:Number(j[1]),lang:h()});if(!e.ok||!e.data){console.log(chalk.yellow(" "+("no_version"===e.code?k(`You have no v${j[1]} in this cup — type versions.`,`你在这个杯赛没有 v${j[1]} —— 敲 versions 看列表。`,`คุณไม่มี v${j[1]} ในถ้วยนี้ — พิมพ์ versions`):`❌ ${S(e.code,e.message)}`))),"no_version"!==e.code&&"locked"!==e.code&&"out"!==e.code&&console.log(chalk.gray(k(" Your entry did not change. Pick a version that works (versions), or fix bot.py and up."," 正式参赛版本没变。换一个能用的版本(versions 看列表),或者改好 bot.py 再 up。"," ตัวที่ส่งแข่งยังเหมือนเดิม เลือกเวอร์ชันที่ใช้ได้ (versions) หรือแก้ bot.py แล้ว up")));continue}w=e.data,console.log(chalk.green(" ✓ ")+chalk.white(k(`v${j[1]} checked ✓ — it is now your entry and locks when the next round starts.`,`v${j[1]} 检查通过 ✓ —— 现在是正式参赛版本,下一轮开始时锁定。`,`v${j[1]} ตรวจแล้ว ✓ — ตอนนี้เป็นตัวที่ส่งแข่ง จะล็อกเมื่อรอบถัดไปเริ่ม`))),I(w);continue}if(/^(?:knobs?|旋钮)$/i.test(v)||/^set$/i.test(v)){if(!e(i)){console.log(chalk.yellow(k(" No bot.py yet — "," 还没有 bot.py —— "," ยังไม่มี bot.py — "))+chalk.bold.green("template knobs"));continue}u(o(i,"utf8"));continue}const x=/^(?:set|改)\s+(.+)$/i.exec(v);if(x){if(!e(i)){console.log(chalk.yellow(k(" No bot.py yet — "," 还没有 bot.py —— "," ยังไม่มี bot.py — "))+chalk.bold.green("template knobs"));continue}d(o(i,"utf8"),x[1],k(" next: up uploads it to the cup"," 下一步:up 上传到杯赛"," ขั้นต่อไป: up เพื่ออัปโหลดเข้าถ้วย"));continue}const T=/^(?:template|模板)(?:\s+(knobs?|code|新手|高手|旋钮|代码))?(?:\s+(force|覆盖))?$/i.exec(v);if(T){const e=/^(?:code|高手|代码)$/i.test(T[1]??"")?"code":"knobs";if("code"===e&&"knobs"===w.division){console.log(chalk.yellow(k(" This is the 🔧 KNOBS cup — it takes only the knob bot. Type template knobs (custom code goes in the ✍ CODE cup)."," 这是 🔧 旋钮杯 —— 只收旋钮 bot。请敲 template knobs(自己写的代码去 ✍ 代码杯)。"," นี่คือถ้วย 🔧 KNOBS — รับเฉพาะ bot แบบ knobs พิมพ์ template knobs (โค้ดที่เขียนเองให้ส่งในถ้วย ✍ CODE)")));continue}if(!await n()){console.log(chalk.yellow(k(" The arena engine is not on this computer yet: type card, then battle once (it downloads the engine), then come back."," 这台电脑还没有竞技场引擎:先 card 回卡片,进一次 battle(会下载引擎),再回来。"," เครื่องนี้ยังไม่มี engine: พิมพ์ card แล้วเข้า battle หนึ่งครั้ง (จะดาวน์โหลด engine) แล้วกลับมา")));continue}await g(e,!!T[2],"zh"===h())&&console.log(chalk.gray(" ▸ ")+chalk.bold.green("knobs"===e?"set WOMBATS 6":"up")+chalk.gray("knobs"===e?k(" change a knob, then up"," 改一个旋钮,然后 up"," เปลี่ยน knob แล้ว up"):k(" after you edit bot.py"," 改好 bot.py 之后"," หลังจากแก้ bot.py")));continue}const K=/^(?:up|upload|submit|上传|อัปโหลด)(?:\s+(.+))?$/i.exec(v);if(K){const t=(K[1]??"").trim()||i;if(!e(t)){console.log(chalk.yellow(` ${k("Not found","找不到","ไม่พบไฟล์")}: ${t}`)+chalk.gray(k(" — type template first"," —— 先敲 template"," — พิมพ์ template ก่อน")));continue}let n="";try{n=o(t,"utf8")}catch{console.log(chalk.yellow(` ${k("Could not read","读不了","อ่านไฟล์ไม่ได้")}: ${t}`));continue}const a=await $("upload",s,{cup:m,code:n,lang:h()},3e4);if(!a.ok||!a.data){console.log(chalk.bold.red(k(" ❌ Not accepted"," ❌ 没有收下"," ❌ ไม่รับ"))),console.log(chalk.yellow(" "+S(a.code,a.message)));const e=E(w.me);e&&"locked"!==a.code&&"out"!==a.code&&console.log(chalk.gray(k(` Nothing changed — your entry is still v${e}.`,` 什么都没变 —— 正式参赛版本还是 v${e}。`,` ไม่มีอะไรเปลี่ยน — ตัวที่ส่งแข่งยังเป็น v${e}`)));continue}console.log(a.data.unchanged?chalk.gray(k(` Identical to v${a.data.version} — nothing new.`,` 和 v${a.data.version} 一字不差,没有新版本。`,` เหมือนกับ v${a.data.version} ทุกตัวอักษร — ไม่มีเวอร์ชันใหม่`)):chalk.green(" ✓ ")+chalk.white(k(`Checked ✓ and uploaded as v${a.data.version} — it is now your entry. Older versions are kept: versions · use N.`,`检查通过 ✓,已上传为 v${a.data.version} —— 现在它是正式参赛版本。旧版本都保留:versions 看列表 · use N 换回去。`,`ตรวจแล้ว ✓ อัปโหลดเป็น v${a.data.version} — ตอนนี้เป็นตัวที่ส่งแข่ง เวอร์ชันเก่ายังอยู่: versions · use N`))),await C(),L(w);continue}const z=/^(?:replay|回放|รีเพลย์)(?:\s+(\d+))?(?:\s+(\d+))?$/i.exec(v);if(z){if(!z[1]){console.log(chalk.gray(k(" replay <match#> <game#> — e.g. replay 41 1 (match numbers are in bracket and your path)"," replay <场号> <局号> —— 例如 replay 41 1(场号在 bracket 和你的路线里)"," replay <เลขนัด> <เลขเกม> — เช่น replay 41 1 (เลขนัดอยู่ใน bracket และเส้นทางของคุณ)")));continue}const e=await $("replay",s,{cup:m,match_id:Number(z[1]),game:Number(z[2]??1)},3e4);if(!e.ok||!e.data){console.log(chalk.yellow(" "+S(e.code,e.message)));continue}const o=e.data,n=0===o.seat_a?{blue:o.a,red:o.b}:1===o.seat_a?{blue:o.b,red:o.a}:null,r="a"===o.winner?o.a:"b"===o.winner?o.b:null;if(console.log(chalk.gray(` #${z[1]} ${k("game","第","เกม")} ${z[2]??1}${k(""," 局","")}${o.tiebreak?k(" (tie-break)","(加赛)"," (เกมตัดสิน)"):""} · ${o.map} · `)+(n?`🟦 ${chalk.bold.white(n.blue)}${chalk.gray(" vs ")}🟥 ${chalk.bold.white(n.red)}`:`${o.a} vs ${o.b}`)+chalk.gray(` · ${k("winner","胜者","ผู้ชนะ")}: `)+(r?chalk.bold.white(r):chalk.gray(k("draw","平局","เสมอ")))),!a(o.replay,n)){console.log(chalk.yellow(k(" Could not save the replay."," 回放存不下来。"," บันทึกรีเพลย์ไม่ได้")));continue}console.log(chalk.gray(k(" space = pause · ← → = step · ↑ ↓ = speed · q = back to the cup"," 空格 = 暂停 · ← → = 单步 · ↑ ↓ = 速度 · q = 回到杯赛"," space = หยุด · ← → = ทีละขั้น · ↑ ↓ = ความเร็ว · q = กลับไปที่ถ้วย"))),await t(y.interactive)||console.log(chalk.yellow(k(" The replay is saved, but the viewer needs Python 3.12 and the arena engine: run python setup, open battle once, then replay again."," 回放已存在本机,但播放器需要 Python 3.12 和竞技场引擎:先 python setup,再进一次 battle,回来再 replay。"," บันทึกรีเพลย์แล้ว แต่ตัวเล่นต้องใช้ Python 3.12 และ engine: รัน python setup แล้วเข้า battle หนึ่งครั้ง จากนั้น replay อีกครั้ง")));continue}console.log(chalk.gray(k(` Not a cup command: ${v}`,` 不是杯赛命令:${v}`,` ไม่ใช่คำสั่งของถ้วย: ${v}`))),W(m,w.division)}}function U(e){return"open"===e.state?k("registration open","报名中","เปิดรับสมัคร"):"done"===e.state?k("finished — see the results","已结束 —— 可以看结果","จบแล้ว — ดูผลได้"):`${w(e.round)} · ${"judging"===e.round_state?k("playing now","正在比赛","กำลังแข่ง"):k("break","休息中","พัก")}`}export async function runCampCup(e){const o=e.trim().toUpperCase();console.log(chalk.gray(k(" Checking your BattleAI token…"," 正在检查你的 BattleAI token…"," กำลังตรวจ token BattleAI…")));const t=await $("status",o);if(!t.ok||!t.data)return"device_bound"===t.code?(console.log(chalk.yellow(` ✗ ${t.message??""}`)),console.log(chalk.gray(k(" This token was first opened on another computer — tell your teacher your seat number."," 这个 token 第一次是在另一台电脑上打开的 —— 把你的座位号告诉老师。"," token นี้ถูกเปิดครั้งแรกบนเครื่องอื่น — บอกครูหมายเลขที่นั่งของคุณ"))),!0):"expired"===t.code&&(console.log(chalk.yellow(` ✗ ${t.message??"expired"}`)),!0);const n=y();try{for(;;){const e=await $("status",o),t=e.ok&&e.data?.listed?e.data.listed:[],a="═".repeat(44);if(console.log(),console.log(chalk.bold.cyan(` ${a}`)),console.log(chalk.bold.white(" ICOA Thailand 2026 AI CAMP")),console.log(chalk.bold.yellow(k(" BattleAI Cup — 64-player knock-out"," BattleAI 杯 —— 64 强淘汰赛"," BattleAI Cup — แพ้คัดออก 64 คน"))),console.log(chalk.bold.cyan(` ${a}`)),!t.length)return console.log(chalk.yellow(k(" No cup is open yet — wait for your teacher, then type your token again."," 杯赛还没开 —— 等老师说开始,再输入一次你的 token。"," ยังไม่เปิดถ้วย — รอครูบอก แล้วพิมพ์ token อีกครั้ง"))),!0;t.forEach((e,o)=>{console.log(` ${chalk.bold.green(String(o+1))} ${chalk.bold.cyan(x(A(e.division)||e.label||e.cup,16))}`+chalk.white(`${x((e.label||"").replace(/^ICOA\b.*?\s[-–—]\s+/i,""),22)} `)+chalk.gray(`${e.players} ${k("players","人","คน")} · ${U(e)}`)+(e.member?chalk.green(k(" · you are in ✓"," · 你已报名 ✓"," · คุณอยู่ในถ้วยนี้ ✓")):""));const t=B(e.division);t&&console.log(chalk.gray(` ${t}`))}),console.log(chalk.gray(" 🌐 ")+["en","zh","th"].map(e=>h()===e?chalk.bold.green(`lang ${e}`):chalk.white(`lang ${e}`)).join(chalk.gray(" · "))+chalk.gray(" English · 中文 · ภาษาไทย"));const s=await n.ask(chalk.bold.white(k(` Type ${t.map((e,o)=>o+1).join(" or ")} to enter a cup (Enter = back): `,` 敲 ${t.map((e,o)=>o+1).join(" 或 ")} 进入杯赛(直接回车 = 返回):`,` พิมพ์ ${t.map((e,o)=>o+1).join(" หรือ ")} เพื่อเข้าถ้วย (Enter = กลับ): `)));if(null===s)return!0;const l=s.trim().toLowerCase();if(!l||f.has(l)||"menu"===l)return!0;const i=/^(?:lang|language|语言|ภาษา)(?:\s+(\S+))?$/.exec(l)??/^(en|zh|th|english|中文|ไทย|thai)$/.exec(l);if(i){const e=(i[1]??"").toLowerCase(),o=/^(?:en|english)$/.test(e)?"en":/^(?:zh|中文|cn)$/.test(e)?"zh":/^(?:th|ไทย|thai)$/.test(e)?"th":"";o?r({language:o}):console.log(chalk.gray(" lang en · lang zh · lang th"));continue}const c=t[Number(l)-1]??t.find(e=>e.cup.toLowerCase()===l||/^(?:knobs?|旋钮|🔧)$/.test(l)&&"knobs"===e.division||/^(?:code|pro|代码|高手|✍)$/.test(l)&&"code"===e.division);if(c){if("menu"===await runCup(o,n.ask,c.cup,{interactive:(e,o)=>p(e,o)}))return!0;console.log(chalk.gray(k(" ↩ Back to the cup list."," ↩ 回到杯赛列表。"," ↩ กลับไปที่รายการถ้วย")))}else console.log(chalk.yellow(k(` Type a number from the list: ${t.map((e,o)=>o+1).join(", ")}`,` 请敲列表里的数字:${t.map((e,o)=>o+1).join("、")}`,` พิมพ์ตัวเลขจากรายการ: ${t.map((e,o)=>o+1).join(", ")}`)))}}finally{n.close()}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "icoa-cli",
|
|
3
|
-
"version": "2.19.
|
|
3
|
+
"version": "2.19.660",
|
|
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",
|