icoa-cli 2.19.659 → 2.19.661
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 P(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 z(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?P(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 M(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.","下一轮开始时锁定。"," จะล็อกเมื่อรอบถัดไปเริ่ม")))),t&&(t.can_edit??"open"===o.state)&&e(i)&&(console.log(chalk.gray(" 📄 ")+chalk.gray(k("bot.py = your bot (the same file as in the PvP room): ","bot.py = 你的 bot(和 PvP 房间是同一个文件):","bot.py = bot ของคุณ (ไฟล์เดียวกับในห้อง PvP): "))+chalk.bold.green("knobs")+chalk.gray(k(" see the settings → "," 看设置 → "," ดูการตั้งค่า → "))+chalk.bold.green("set …")+chalk.gray(k(" change one → "," 改一个 → "," เปลี่ยนหนึ่งตัว → "))+chalk.bold.green("up")+chalk.gray(k(" send it to the cup"," 交给杯赛"," ส่งเข้าถ้วย"))),s&&console.log(chalk.gray(k(` Changed it in the room? The cup still has v${r} until you come back and up.`,` 在房间里改过?回到这里再 up 之前,杯赛里还是 v${r}。`,` แก้ในห้องมาแล้ว? ถ้วยยังใช้ v${r} จนกว่าคุณจะกลับมา up`))));const c=C(o);c&&console.log(chalk.bold.yellow(` ${c}`));const u=t?.slot?s||"open"!==o.state?t?.can_edit&&s?"knobs":"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),z(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()&&z(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()&&M(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 P=/^(?:replay|回放|รีเพลย์)(?:\s+(\d+))?(?:\s+(\d+))?$/i.exec(v);if(P){if(!P[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(P[1]),game:Number(P[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(` #${P[1]} ${k("game","第","เกม")} ${P[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/dist/lib/learn-pvp.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{copyFileSync as e,existsSync as o,mkdirSync as t,readFileSync as a,writeFileSync as n}from"node:fs";import{homedir as r}from"node:os";import{join as s}from"node:path";import chalk from"chalk";import{playSavedReplay as l,resolveEngineDir as i,runMobLocal as c,saveJudgeReplay as p}from"../commands/battle.js";import{getConfig as g}from"./config.js";import{runInteractive as d}from"./interactive-spawn.js";import{learnPost as y}from"./learn-contest.js";import{probePython as $}from"./python-setup.js";import{ARENA_VI_FLAGS as u}from"./vi-flags.js";export const PVP_RE=/^\/?(?:room|rooms|pvp|房间|对战房)(?:\s+(.*))?$/i;function b(e,o,t){return 0!==e&&1!==e?null:0===e?{blue:o,red:t}:{blue:t,red:o}}const m=e=>0===e?chalk.cyan(v(" 🟦 blue"," 🟦 蓝"," 🟦 น้ำเงิน")):chalk.red(v(" 🟥 red"," 🟥 红"," 🟥 แดง")),h=(e,o,t={},a=2e4)=>y(`/api/icoa/learn/pvp/${e}`,{token:o.toUpperCase(),...t},a),w=()=>{const e=(g().language||"en").toLowerCase();return e.startsWith("zh")?"zh":e.startsWith("th")?"th":"en"},v=(e,o,t)=>{const a=w();return"zh"===a?o:"th"===a?t:e},f=()=>"zh"===w(),k=new Set(["back","b","quit","q","exit","card","lesson","卡片"]);export const DEFAULT_PVP_BOT=s(r(),".icoa","battleai","bot.py");const _=e=>{let o=0;for(const t of e){const e=t.codePointAt(0)??0;3633===e||e>=3636&&e<=3642||e>=3655&&e<=3662||(o+=e>65535||e>=11904&&e<=42191||e>=44032&&e<=55203||e>=63744&&e<=64255?2:1)}return o},P=(e,o)=>e+" ".repeat(Math.max(0,o-_(e)));function T(e){console.log(chalk.gray(v(` knobs · set <KNOB> <value> · run (local test) · up (upload) · vs <nick> (challenge) · Enter (table) · log · replay 3 (game 3) · edit · template · guide · card (${e})`,` knobs · set <旋钮> <值> · run 试打 · up 上传 · vs <昵称> 挑战 · 回车 战绩表 · log · replay 3 看第 3 局 · edit · template · guide 说明 · card 回卡片 (${e})`,` knobs · set <KNOB> <ค่า> · run ทดลองเล่น · up อัปโหลด · vs <ชื่อเล่น> ท้าแข่ง · Enter ตารางคะแนน · log · replay 3 ดูเกมที่ 3 · edit · template · guide คู่มือ · card กลับไปที่การ์ด (${e})`)))}const E=e=>"rookie"===e?v("🔧 knobs","🔧 新手","🔧 knobs"):"pro"===e?v("✍ code","✍ 高手","✍ code"):"—";function N(e){const o=f(),t=e.public?v("Open room","公共房","ห้องสาธารณะ"):e.label||v("Room","房间","ห้อง");if(console.log(),console.log(chalk.bold.white(` ⚔ ${t} `)+chalk.bold.cyan(e.room)+chalk.gray(` · ${v("you are","你是","คุณคือ")} ${e.nick??"?"} · ${e.members.length} ${v("members","人","คน")} · ${v("today","今日","วันนี้")} ${e.day}${e.public?v(" · table resets daily"," · 战绩每天清零"," · ตารางเริ่มใหม่ทุกวัน"):""}`)),(e=>"distinct_beaten"===e.ranking&&e.members.every(e=>"number"==typeof e.today.beat))(e)){console.log(chalk.gray(v(" Ranked by how many different people you beat today, then win rate. The same two bot versions count once a day."," 排名先看今天赢过多少个不同的人,再看胜率。同一对 bot 版本每天只计一次。"," จัดอันดับตามจำนวนคนที่คุณชนะได้ (ไม่นับคนซ้ำ) ในวันนี้ แล้วจึงดูอัตราชนะ — bot คู่เวอร์ชันเดิมนับคะแนนได้วันละครั้ง"))),console.log(chalk.gray(o?` ${P("昵称",14)}${P("bot",6)}${P("组",9)}${P("赢过",6)}${P("今日 胜-负-平",15)}${P("打了",7)}累计`:` ${P("nick",14)}${P("bot",6)}${P("group",9)}${P("beat",6)}${P("today W-L-D",15)}${P("played",7)}all-time`));for(const o of e.members){const e=` ${P(o.nick,14)}${P(o.versions?`v${o.versions}`:"—",6)}${P(E(o.group),9)}${P(String(o.today.beat??0),6)}${P(`${o.today.w}-${o.today.l}-${o.today.d}`,15)}${P(String(o.today.played??o.today.n),7)}${o.all.w}-${o.all.l}-${o.all.d}`;console.log(o.me?chalk.bold.cyan(e):chalk.white(e))}}else{console.log(chalk.gray(o?` ${P("昵称",14)}${P("bot",6)}${P("组",9)}${P("今日 胜-负-平",16)}累计`:` ${P("nick",14)}${P("bot",6)}${P("group",9)}${P("today W-L-D",16)}all-time`));for(const o of e.members){const e=` ${P(o.nick,14)}${P(o.versions?`v${o.versions}`:"—",6)}${P(E(o.group),9)}${P(`${o.today.w}-${o.today.l}-${o.today.d}`,16)}${o.all.w}-${o.all.l}-${o.all.d}`;console.log(o.me?chalk.bold.cyan(e):chalk.white(e))}}if(e.my_versions.length||console.log(chalk.yellow(v(" You have no bot here yet — knobs / set, then up."," 你还没上传 bot —— 先 knobs / set,再 up。"," คุณยังไม่มี bot ในห้องนี้ — ใช้ knobs / set แล้วจึง up"))),e.recent.length){console.log(chalk.gray(v(" Today:"," 今日对局:"," แมตช์วันนี้:")));for(const o of e.recent.slice(0,6))console.log(chalk.gray(" ")+O(o))}}const A=()=>chalk.gray(v(" · not counted"," · 不计分"," · ไม่นับคะแนน"));function O(e){const o=null===e.wins_a||void 0===e.wins_a?"-":`${e.wins_a}-${e.wins_b}`,t="WIN"===e.verdict?chalk.green(o):"LOSS"===e.verdict?chalk.red(o):chalk.yellow(o),a=`${e.a} v${e.a_version??"?"} vs ${e.b} v${e.b_version??"?"}`,n=chalk.gray(`#${String(e.id).padEnd(4)} `),r=e.replays?chalk.gray(" 🎬"):"",s="WIN"===e.verdict||"LOSS"===e.verdict||"DRAW"===e.verdict;return`${n}${chalk.gray((e=>{const o=new Date(e);return Number.isNaN(o.getTime())?"":`${String(o.getHours()).padStart(2,"0")}:${String(o.getMinutes()).padStart(2,"0")}`})(e.ts))} ${e.mine?chalk.white(a):chalk.gray(a)} ${t}${r}${e.draws?chalk.gray(` (${e.draws} ${v("draw","平","เสมอ")})`):""}${s&&0===e.counted?A():""}${s?"":chalk.red(` ${e.verdict}`)}`}let B=!1;function S(e){const o=f();console.log();const t=`${e.wins_a}-${e.wins_b}${e.draws?` (${e.draws} ${v("draw","平","เสมอ")})`:""}`,a=chalk.gray(` vs ${e.opp.nick} v${e.opp.version}`),n=0===e.counted&&"repeat_pairing"===e.counted_reason?A():"";if("WIN"===e.verdict)console.log(chalk.bold.green(` 🏆 ${v("You win","你赢了","คุณชนะ")} ${t}`)+a+n);else if("LOSS"===e.verdict)console.log(chalk.bold.red(` ❌ ${v("You lose","你输了","คุณแพ้")} ${t}`)+a+n);else{if("DRAW"!==e.verdict)return void console.log(chalk.yellow(` ⚠ ${v("The judge could not finish this match","判分机没跑完这场","เครื่องตัดสินเล่นแมตช์นี้ไม่จบ")}: ${e.verdict}${e.note?` — ${e.note}`:""}`));console.log(chalk.bold.yellow(` 🤝 ${v("Draw","平局","เสมอ")} ${t}`)+a+n)}n&&(B?console.log(chalk.gray(v(" (same two versions as earlier today — up a new version to count)"," (和今天早些时候是同一对版本 —— 上传新版本才计分)"," (เป็นคู่เวอร์ชันเดิมของวันนี้ — up เวอร์ชันใหม่เพื่อให้นับคะแนน)"))):(B=!0,console.log(chalk.gray(v(" Not counted: these two bot versions already played each other today. Maps are fixed for the day, so the result"," 不计分:这两个 bot 版本今天已经交过手。当天的地图固定,结果不会变"," ไม่นับคะแนน: bot สองเวอร์ชันนี้แข่งกันไปแล้ววันนี้ แผนที่ของวันนี้ถูกกำหนดไว้แล้ว ผลจึงเหมือนเดิม"))),console.log(chalk.gray(v(" is the same (replays still work). To count again, one of you uploads a new version: "," (回放照样能看)。想再计分,任何一方上传新版本即可: "," (ยังดูรีเพลย์ได้ตามปกติ) ถ้าอยากให้นับคะแนนอีก ฝ่ายใดฝ่ายหนึ่งอัปโหลดเวอร์ชันใหม่: "))+chalk.bold.green("up"))),e.cached&&e.cached_from&&console.log(chalk.gray(v(` Same games as match #${e.cached_from} — served instantly, the judge was not needed.`,` 和第 ${e.cached_from} 场完全相同 —— 直接给出,没有占用判分机。`,` เป็นเกมเดียวกับแมตช์ #${e.cached_from} — แสดงผลทันทีโดยไม่ต้องใช้เครื่องตัดสิน`)))),e.load_error?.a&&console.log(chalk.red(` ${v("Your bot failed to load","你的 bot 装不上","bot ของคุณโหลดไม่ขึ้น")}: ${e.load_error.a}`)),e.load_error?.b&&console.log(chalk.gray(` ${v("Opponent's bot failed to load","对方的 bot 装不上","bot ของคู่แข่งโหลดไม่ขึ้น")}: ${e.load_error.b}`)),console.log(chalk.gray(o?` ${P("#",4)}${P("地图",11)}${P("席位",6)}${P("结果",8)}${P("原因",10)}${P("回合",7)}兵力价值 你/对方`:` ${P("#",4)}${P("map",11)}${P("seat",6)}${P("result",8)}${P("how",10)}${P("turns",7)}army value you/them`));for(const t of e.games){const a="a"===t.winner?o?"胜":"win":"b"===t.winner?o?"负":"loss":o?"平":"draw",n="a"===t.winner?chalk.green(P(a,8)):"b"===t.winner?chalk.red(P(a,8)):chalk.yellow(P(a,8)),r="warrens"===t.reason?o?"拆家":"warrens":"timeout"===t.reason?o?"超时":"timeout":"crash"===t.reason?o?"崩溃":"crash":"load_error"===t.reason?o?"装不上":"no load":o?"回合满":"turn cap";console.log(` ${P(String(t.game??e.games.indexOf(t)+1),4)}${P(t.map,11)}${P(String(t.seat_a),6)}${n}${P(r,10)}${P(String(t.turns),7)}${Math.round((t.value??t.lost)[0])}/${Math.round((t.value??t.lost)[1])}${t.error?chalk.gray(` ${t.error}`):""}`)}console.log(chalk.gray(` ${v("seeds","种子","seeds")} ${e.seeds.join(",")} · ${v("destroy their warren to win; at the turn cap the higher army value wins (live soldiers; wombats and warrens do not count), within 5% is a draw","拆掉对方的家就赢;打满回合比兵力价值(活着的兵,wombat 和家不算),相差不到 5% 平局","ทำลาย warren ของอีกฝ่ายได้ก็ชนะ ถ้าครบจำนวนเทิร์น ฝ่ายที่มีมูลค่ากองทัพสูงกว่าชนะ (นับเฉพาะทหารที่ยังรอด ไม่นับ wombat และ warren) ต่างกันไม่ถึง 5% ถือว่าเสมอ")}`)),e.games.length>3&&e.games.some(e=>1===e.seat_a)&&console.log(chalk.gray(v(" ⚖ The seat-swap check came out different (a bot acts differently by seat), so every map was played from both seats."," ⚖ 换席位抽查结果不一样(有 bot 按座位做不同的事),所以每张图两边都打了一遍。"," ⚖ ผลตรวจสลับที่นั่งออกมาไม่เหมือนกัน (มี bot ที่เล่นต่างกันตามที่นั่ง) จึงเล่นทุกแผนที่จากทั้งสองฝั่ง")));const r=e.games.findIndex(e=>"b"===e.winner)+1,s=e.games.find(e=>"b"===e.winner);e.replay&&p(e.replay,s?b(s.seat_a,e.me.nick,e.opp.nick):null),e.replays?console.log(chalk.gray(" ▸ ")+chalk.bold.green("replay 3")+chalk.gray(v(` watch game 3 (any of 1–${e.games.length}) · `,` 看第 3 局(1–${e.games.length} 任选)· `,` ดูเกมที่ 3 (เลือกได้ 1–${e.games.length}) · `))+chalk.bold.green("replay")+chalk.gray(r?v(` the game you lost (#${r}) · `,` 看你输掉的第 ${r} 局 · `,` เกมที่คุณแพ้ (#${r}) · `):v(" game 1 · "," 看第 1 局 · "," เกมที่ 1 · "))+chalk.bold.green(`replay ${e.match_id} 3`)+chalk.gray(v(" this match later, from log"," 以后从 log 里回看这场"," ดูแมตช์นี้ภายหลังจาก log"))):e.replay&&console.log(chalk.gray(" ▸ ")+chalk.bold.green("replay")+chalk.gray(e.wins_b?v(" watch the first game you lost"," 看你输掉的第一局"," ดูเกมแรกที่คุณแพ้"):v(" watch game 1"," 看第一局"," ดูเกมที่ 1")))}const x=e=>{const o=e.search(/^# ── KNOBS/m);let t=e;if(o>=0){const a=e.slice(o).split("\n").slice(1),n=a.findIndex(e=>/^# ───/.test(e));t=(n>=0?a.slice(0,n):a).join("\n")}return[...new Set([...t.matchAll(/^([A-Z][A-Z0-9_]*)\s*=\s*[^#\n]+/gm)].map(e=>e[1]))]},L=(e,o)=>{const t=new RegExp(`^${o}\\s*=\\s*([^#\n]*?)\\s*(?:#.*)?$`,"m").exec(e);return t?t[1]:null},U=(e,o)=>{const t=new RegExp(`^${o}\\s*=[^#\n]*#\\s*(.*)$`,"m").exec(e);return t?t[1].trim():""},j=()=>{try{return a(DEFAULT_PVP_BOT,"utf8")}catch{return null}},D=e=>e.split("\n").map(e=>e.replace(/\s+#.*$/,"").trimEnd()).filter(e=>e.trim()&&!e.trim().startsWith("#")&&!/^[A-Z][A-Z0-9_]*\s*=/.test(e));async function C(e){const o=await i();if(!o)return null;try{const t=a(s(o,"bots","knob_bot.py"),"utf8");return D(t).join("\n")===D(e).join("\n")?"rookie":"pro"}catch{return null}}export async function writeTemplate(a,n,l){const c=await i();if(!c)return console.log(chalk.yellow(v(" The arena engine is not on this machine yet (one online fetch needed)."," 引擎还没下载到本机(需要联网一次)。"," เครื่องนี้ยังไม่มี arena engine (ต้องต่ออินเทอร์เน็ตดาวน์โหลดหนึ่งครั้ง)"))),!1;const p=s(c,"bots","knobs"===a?"knob_bot.py":l?"template_bot_zh.py":"template_bot.py");if(!o(p))return console.log(chalk.yellow(` ${v("Template missing in the engine","引擎里没有模板","ไม่พบเทมเพลตใน engine")}: ${p}`)),!1;if(t(s(r(),".icoa","battleai"),{recursive:!0}),o(DEFAULT_PVP_BOT)){if(!n)return console.log(chalk.yellow(v(" bot.py already exists — not overwritten."," bot.py 已经存在,不覆盖。"," มี bot.py อยู่แล้ว — ไม่เขียนทับ"))+chalk.gray(v(" To replace it: "," 确定要换: "," ถ้าต้องการแทนที่: "))+chalk.bold.green(`template ${a} force`)+chalk.gray(v(" (the old file is kept as bot.py.bak)","(旧文件留作 bot.py.bak)"," (ไฟล์เดิมจะเก็บไว้เป็น bot.py.bak)"))),!1;e(DEFAULT_PVP_BOT,`${DEFAULT_PVP_BOT}.bak`)}return e(p,DEFAULT_PVP_BOT),console.log(chalk.green(" ✓ ")+chalk.white("knobs"===a?v("The 15-knob starter is now your bot.py","15 个旋钮的新手模板已放到 bot.py","ตอนนี้ bot.py ของคุณคือเทมเพลตเริ่มต้นแบบ 15 knobs แล้ว"):v("The blank code template is now your bot.py (pro)","空白代码模板已放到 bot.py(高手组)","ตอนนี้ bot.py ของคุณคือเทมเพลตโค้ดเปล่า (กลุ่ม pro)"))+chalk.gray(` (${DEFAULT_PVP_BOT})`)),!0}export function printKnobs(e){const o=x(e);if(o.length){console.log(chalk.gray(v(" Your knobs (set <KNOB> <value> changes one):"," 你的旋钮(set <旋钮> <值> 改一个):"," knobs ของคุณ (เปลี่ยนทีละตัวด้วย set <KNOB> <ค่า>):")));for(const t of o)console.log(` ${chalk.bold.white(t.padEnd(10))}${chalk.green((L(e,t)??"").padEnd(12))}${chalk.gray(U(e,t))}`)}else console.log(chalk.gray(v(" Your bot.py has no knobs (the NAME = value lines at the top) — it is custom code (pro). For the knob starter type template knobs."," 你的 bot.py 没有旋钮(顶部那种 NAME = value 行)—— 它是高手组的自定义代码。要旋钮版敲 template knobs。"," bot.py ของคุณไม่มี knobs (บรรทัดแบบ NAME = value ด้านบน) — เป็นโค้ดที่เขียนเอง (pro) ถ้าต้องการแบบ knobs พิมพ์ template knobs")))}export async function myBotsCommand(a,l,i){const c=a.trim().toLowerCase();if(/^(?:bots|mybots|my bots|我的版本|เวอร์ชันของฉัน)$/i.test(c)){const e=await h("mybots",l);if(!e.ok||!e.data)return console.log(chalk.yellow(" "+V(e.code,e.message))),!0;const o=e.data.bots;if(!o.length)return console.log(chalk.gray(v(" No uploads yet — up sends bot.py."," 还没上传过 —— up 上传 bot.py。"," ยังไม่เคยอัปโหลด — up ส่ง bot.py"))),!0;const t=Array.from(new Set(o.map(e=>e.room))).sort((e,o)=>e===i?-1:o===i?1:0);for(const e of t){const t=o.filter(o=>o.room===e),a=e.startsWith("CUP-")?v(`cup ${e.slice(4)}`,`杯赛 ${e.slice(4)}`,`ถ้วย ${e.slice(4)}`):v(`room ${e}`,`房间 ${e}`,`ห้อง ${e}`);console.log(chalk.bold.white(` ${a}`)+chalk.gray(` · ${t.length} ${v("versions","个版本","เวอร์ชัน")}${e===i?v(" (here)","(当前)"," (ที่นี่)"):""}`));const n=t.slice().reverse().slice(0,e===i?20:12);for(const e of n)console.log(chalk.gray(" ")+chalk.bold.green(`v${e.version}`.padEnd(6))+chalk.gray(`${(e.ts||"").slice(5,16).replace("T"," ")} UTC `)+chalk.gray(`${e.grp?E(e.grp).padEnd(10):"".padEnd(10)}${e.bytes??"?"} B`));t.length>n.length&&console.log(chalk.gray(` … ${t.length-n.length} ${v("older","个更早的","เก่ากว่า")}`))}return console.log(chalk.gray(v(" show N = see vN (knobs or code) · get N = save it as bot-vN.py · restore N = put it back into bot.py · other room: show TH26 N"," show N 看第 N 版(旋钮或代码)· get N 存成 bot-vN.py · restore N 放回 bot.py · 别的房间:show TH26 N"," show N = ดูเวอร์ชัน N (knobs หรือโค้ด) · get N = บันทึกเป็น bot-vN.py · restore N = ใส่กลับเข้า bot.py · ห้องอื่น: show TH26 N"))),!0}const p=/^(show|get|restore|看|取回|恢复)\s+(?:([A-Za-z][A-Za-z0-9-]*)\s+)?v?(\d+)(?:\s+(code|代码|โค้ด))?$/i.exec(a.trim());if(!p)return!1;const g={"看":"show","取回":"get","恢复":"restore"}[p[1]]??p[1].toLowerCase(),d=(p[2]??i).toUpperCase(),y=Number(p[3]),$=await h("mybot",l,{bot_room:d,version:y});if(!$.ok||!$.data)return console.log(chalk.yellow(" "+("no_bot"===$.code?v(`You have no v${y} in ${d} — type bots.`,`你在 ${d} 没有 v${y} —— 敲 bots 看列表。`,`คุณไม่มี v${y} ใน ${d} — พิมพ์ bots`):V($.code,$.message)))),!0;const u=$.data.code,b=chalk.bold.white(` ${d} v${y}`)+chalk.gray(` · ${($.data.ts||"").slice(0,16).replace("T"," ")} UTC`);if("show"===g){console.log(b);const e=x(u);if(e.length&&!p[4]){for(const o of e)console.log(` ${chalk.bold.white(o.padEnd(10))}${chalk.green((L(u,o)??"").padEnd(12))}${chalk.gray(U(u,o))}`);console.log(chalk.gray(v(` full file: show ${y} code`,` 完整代码:show ${y} code`,` ทั้งไฟล์: show ${y} code`)))}else{const e=u.split("\n"),o=String(e.length).length;for(const[t,a]of e.entries())console.log(chalk.gray(` ${String(t+1).padStart(o)} `)+chalk.white(a))}return console.log(chalk.gray(v(` get ${y} = save as bot-v${y}.py · restore ${y} = put back into bot.py`,` get ${y} 存成 bot-v${y}.py · restore ${y} 放回 bot.py`,` get ${y} = บันทึกเป็น bot-v${y}.py · restore ${y} = ใส่กลับเข้า bot.py`))),!0}const m=s(r(),".icoa","battleai");if(t(m,{recursive:!0}),"get"===g){const e=s(m,`bot-${d.toLowerCase()}-v${y}.py`);return n(e,u),console.log(chalk.green(" ✓ ")+chalk.gray(v("saved ","已存到 ","บันทึกที่ "))+chalk.white(e)),console.log(chalk.gray(v(" bot.py is unchanged · restore puts a version back into bot.py"," bot.py 没动 · restore 才会放回 bot.py"," bot.py ไม่เปลี่ยน · restore จะใส่กลับเข้า bot.py"))),!0}return o(DEFAULT_PVP_BOT)&&e(DEFAULT_PVP_BOT,`${DEFAULT_PVP_BOT}.bak`),n(DEFAULT_PVP_BOT,u),console.log(b),console.log(chalk.green(" ✓ ")+chalk.gray(v(`bot.py is now ${d} v${y} (the old bot.py is bot.py.bak). Type up to upload it as a new version here.`,`bot.py 现在是 ${d} v${y}(原来的留作 bot.py.bak)。敲 up 把它上传成这里的新版本。`,`bot.py ตอนนี้คือ ${d} v${y} (ไฟล์เดิมเก็บเป็น bot.py.bak) พิมพ์ up เพื่ออัปโหลดเป็นเวอร์ชันใหม่ที่นี่`))),!0}export function setKnob(e,o,t){const a=x(e),r=/^([A-Za-z][A-Za-z0-9_]*)\s*(?:=|\s)\s*(.+)$/.exec(o.trim());if(!r)return console.log(chalk.yellow(v(" Usage: "," 用法: "," วิธีใช้: "))+chalk.bold.green(v("set <KNOB> <value>","set <旋钮> <值>","set <KNOB> <ค่า>"))+chalk.gray(v(" e.g. set WOMBATS 6"," 例如 set WOMBATS 6"," เช่น set WOMBATS 6"))),printKnobs(e),!1;const s=r[1].toUpperCase(),l=r[2].trim();if(!a.includes(s))return console.log(chalk.yellow(v(` No knob called ${s}.`,` 没有 ${s} 这个旋钮。`,` ไม่มี knob ชื่อ ${s}`))+chalk.gray(" ")+a.map(e=>chalk.bold.white(e)).join(chalk.gray(" · "))),!1;const i=L(e,s)??"",c=i.trim();let p=l;if(/^(?:True|False)$/.test(c)?/^(?:on|yes|y|true|1)$/i.test(l)?p="True":/^(?:off|no|n|false|0)$/i.test(l)&&(p="False"):/^(['"]).*\1$/.test(c)&&/^[A-Za-z_]+$/.test(l)&&(p=`'${l.toLowerCase()}'`),c===p)return console.log(chalk.gray(" ")+chalk.bold.white(s)+chalk.gray(v(` is already ${p}.`,` 已经是 ${p} 了。`,` เป็น ${p} อยู่แล้ว`))),!1;const g=new RegExp(`^(${s}\\s*=\\s*)([^#\n]*?)(\\s*)(#.*)?$`,"m"),d=e.replace(g,(e,o,t,a,n)=>`${o}${p}${n?(a||" ")+n:""}`);return n(DEFAULT_PVP_BOT,d),console.log(chalk.gray(" ")+chalk.bold.white(s)+chalk.gray(" ")+chalk.gray(i.trim())+chalk.gray(" → ")+chalk.bold.green(p)+chalk.gray(t??v(" next: run to test, up to upload"," 下一步: run 试打,up 上传"," ขั้นต่อไป: run เพื่อทดลอง, up เพื่ออัปโหลด"))),!0}function F(e){const t=o(DEFAULT_PVP_BOT),a=!!e&&e.my_versions.length>0,n=!!e&&e.recent.some(e=>e.mine),r=(e,o,t,a,n=!1)=>` ${chalk.gray(e)} ${((e,o=!1)=>e?chalk.green("✅"):o?chalk.gray("○ "):chalk.white("⬜"))(o,n)} ${chalk.bold.green(P(t,13))}${chalk.gray(a)}`,s=new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`,"g"),l=!("th"===w()),i=e=>l?`${e}${" ".repeat(Math.max(0,70-_(e.replace(s,""))))}`:e,c=[r("1",t,"template",t?v("bot.py is ready (~/.icoa/battleai/bot.py)","bot.py 已就绪(~/.icoa/battleai/bot.py)","bot.py พร้อมแล้ว (~/.icoa/battleai/bot.py)"):v("get the 15-knob starter (pro: template code)","拿 15 个旋钮的新手模板(高手: template code)","รับเทมเพลต 15 knobs (pro: template code)")),r("2",!1,"knobs · set",v("see the knobs; set WOMBATS 6 changes one — no code","看旋钮;set WOMBATS 6 改一个,不用写代码","ดู knobs; set WOMBATS 6 เปลี่ยนทีละตัว"),!0),` ${chalk.gray(v("✍ pro:","✍ 高手:","✍ pro:"))} ${chalk.bold.green("edit")} ${chalk.gray(v("opens the file — rewrite act(u) below the knobs","打开文件,旋钮下面的 act(u) 随便重写","เปิดไฟล์ แล้วเขียน act(u) ใต้ knobs ใหม่ได้เลย"))}`,r("3",!1,"run",v("one local test game — does the bot run? (optional)","本地试打一场,看 bot 跑不跑得起来(可跳过)","ทดลองในเครื่อง 1 เกม ดูว่า bot รันได้ไหม (ข้ามได้)"),!0),r("4",a,"up",a?v(`uploaded, now v${e?.my_versions.length} (edit + up again = new version)`,`已上传到 v${e?.my_versions.length}(改完再 up = 新版本)`,`อัปโหลดแล้ว v${e?.my_versions.length} (แก้แล้ว up อีกครั้ง = เวอร์ชันใหม่)`):v("upload the bot → v1 (tagged 🔧 knobs / ✍ code)","上传 bot → v1(自动标 🔧 新手 / ✍ 高手)","อัปโหลด bot → v1 (ติดป้าย 🔧 / ✍ ให้เอง)")),r("5",n,f()?"vs <昵称>":"vs <nick>",n?v("you played today — go again","今天打过了 —— 再来一场","วันนี้คุณแข่งไปแล้ว — ลองอีกสักแมตช์"):v("challenge someone: 3 maps decide","挑战一个人:3 张图定胜负","ท้าแข่งกับใครสักคน: ตัดสินกันด้วย 3 แผนที่")),r("6",!1,"replay 3",v("game 3 of your last match · replay <#> <game>: any","最近一场第 3 局 · replay <场号> <局>: 任一场","เกมที่ 3 ล่าสุด · replay <#> <เกม>: นัดใดก็ได้"),!0),r("7",!1,v("Enter","回车","Enter"),v("today's table · log matches · card back to the card","今日战绩表 · log 对局 · card 回卡片","ตารางคะแนนวันนี้ · log แมตช์ · card กลับไปที่การ์ด"),!0)],p=` ${v("How to play","怎么玩","วิธีเล่น")} · ${e?.room??"room"} `;console.log(),console.log(chalk.cyan(` ╭─${chalk.bold.white(p)}${"─".repeat(Math.max(0,70-_(p)-1))}${l?"╮":"─"}`));for(const e of c)console.log(`${chalk.cyan(" │")}${i(e)}${l?chalk.cyan("│"):""}`);console.log(chalk.cyan(` ╰${"─".repeat(70)}${l?"╯":"─"}`));const g=t?a?n?"":v("vs <nick>","vs <昵称>","vs <ชื่อเล่น>"):"up":"template";g&&console.log(chalk.gray(v(" ▸ next: "," ▸ 下一步敲: "," ▸ ขั้นต่อไป พิมพ์: "))+chalk.bold.green(g))}function M(e){const o=e=>chalk.bold.green(e),t=e=>chalk.gray(e),a=e=>chalk.bold.white(e),n=w(),r="zh"===n?[a(` BattleAI PvP 房间 · 怎么玩(房号 ${e})`),"",a(" 进房 / 开房"),` ${o("room new 名字")} ${t("开一个房 → 起昵称 → 得到 4 个字母的房号,发给朋友")}`,` ${o("room KZE6")} ${t("进朋友的房(昵称只问一次)")}`,` ${o("room open")} ${t("公共房,谁都能进;战绩表每天清零")}`,"",a(" 房里(提示符 icoa room XXXX>)—— 进房的面板会把做过的步骤打勾"),` ${o("template")} ${t("把 15 个旋钮的新手模板放到 ~/.icoa/battleai/bot.py(高手: template code = 空白代码模板)")}`,` ${o("knobs")} ${t("列出 15 个旋钮和含义")}`,` ${o("set WOMBATS 6")} ${t("改一个旋钮,不写代码(新手玩法)")}`,` ${o("edit")} ${t("用 vi 打开 bot.py,旋钮下面的 act(u) 随便重写(高手玩法;i 输入 · Esc · :wq 存盘)")}`,` ${o("run")} ${t("本地试打一场,只看 bot 跑不跑得起来(可跳过,需要 python setup)")}`,` ${o("up")} ${t("上传 bot → v1、v2、v3 …(每次上传 = 新版本;自动标 🔧 旋钮 / ✍ 代码)")}`,` ${o("vs <昵称>")} ${t("挑战一个人:3 张图各 1 局(地图对称,换席位结果一样),5–30 秒出结果表")}`,` ${o("vs <昵称>")} ${t("只能挑战对方的最新版本(旧版本不能挑战,防刷分)")}`,"",a(" 我以前的版本(旋钮设置 / 代码都在服务器上)"),` ${o("bots")} ${t("列出你上传过的所有版本(这个房间 + 其他房间 + 杯赛)")}`,` ${o("show 12")} ${t("看第 12 版:旋钮版显示旋钮值,代码版显示代码;show 12 code = 完整代码")}`,` ${o("get 12")} ${t("把第 12 版存成一个文件(bot.py 不动)")}`,` ${o("restore 12")} ${t("把第 12 版放回 bot.py(原来的留作 bot.py.bak),再 up")}`,"",a(" 看回放 —— 两个数字:场号 + 局号"),` ${o("log")} ${t("① 列出今日对局,每行最前面的 #12 就是场号;带 🎬 的才有回放")}`,` ${o("history")} ${t(" 同上,但列出所有天")}`,` ${o("replay 12 3")} ${t("② 看第 12 场的第 3 局(每场 3 局,局号 1–3;别人打的也能看)")}`,` ${o("replay 12")} ${t(" 只写场号 = 那场的第 1 局")}`,` ${o("replay 3")} ${t(" 刚打完不用场号:最近一场的第 3 局")}`,` ${o("replay")} ${t(" 最近一场你输掉的那局")}`,t(" ③ 播放时:空格 暂停 · ←→ 单步 · ↑↓ 调速 · q 退出回房间"),t(" 例:log 里有「#387 … 2-1 🎬」→ replay 387 1 … replay 387 3 逐局看"),"",a(" 战绩(公平规则)"),` ${o("回车")} ${t("今日战绩表:先比今天赢过几个不同的人,再比胜率,再比胜场")}`,t(" · 同一对 bot 版本每天只计一次分;再打照样能打、能看回放,但标「不计分」。任何一方上传新版本 = 新的一对,重新计分。"),t(" · 当天的地图是固定的:同一对版本再打,结果一模一样(重赌运气没用)。"),t(" · 同一台电脑上的两个账号不能互相挑战 —— PvP 要两个不同的人。"),` ${o("help")} ${t("再看步骤面板")} ${o("guide")} ${t("再看这份说明")} ${o("card")} ${t("回卡片")}`,"",t(" 规则一句话:拆掉对方的家就赢;打满 200 回合时,兵力价值(活着的兵,wombat 和家不算)高的一方赢,相差不到 5% 平局。每 30 秒只能发起一场。"),t(" 看到「判分机暂时不可用」就等一分钟再 vs。")]:"th"===n?[a(` ห้อง PvP ของ BattleAI · วิธีเล่น (ห้อง ${e})`),"",a(" เปิดห้องหรือเข้าห้อง"),` ${o("room new Mock")} ${t("เปิดห้องใหม่ → ตั้งชื่อเล่น → ได้รหัสห้อง 4 ตัวอักษร → ส่งให้เพื่อน")}`,` ${o("room KZE6")} ${t("เข้าห้องของเพื่อน (ตั้งชื่อเล่นครั้งเดียว)")}`,` ${o("room open")} ${t("ห้องสาธารณะ ใครก็เข้าได้ ตารางคะแนนเริ่มใหม่ทุกวัน")}`,"",a(" ในห้อง (prompt icoa room XXXX>) — แผงตอนเข้าห้องจะติ๊กขั้นตอนที่คุณทำแล้ว"),` ${o("template")} ${t("วางเทมเพลตเริ่มต้น 15 knobs ไว้ที่ ~/.icoa/battleai/bot.py (pro: template code = เทมเพลตโค้ดเปล่า)")}`,` ${o("knobs")} ${t("แสดง knobs ทั้ง 15 ตัวพร้อมความหมาย")}`,` ${o("set WOMBATS 6")} ${t("เปลี่ยน knob ทีละตัว ไม่ต้องเขียนโค้ด (แบบมือใหม่)")}`,` ${o("edit")} ${t("เปิด bot.py ด้วย vi แล้วเขียน act(u) ใต้ knobs ใหม่ (แบบ pro; i = พิมพ์ · Esc · :wq = บันทึก)")}`,` ${o("run")} ${t("ทดลองเล่นในเครื่อง 1 เกม แค่ดูว่า bot รันได้ (ข้ามได้ ต้องมี python setup)")}`,` ${o("up")} ${t("อัปโหลด bot → v1, v2, v3 … (อัปโหลดแต่ละครั้ง = เวอร์ชันใหม่; ติดป้าย 🔧 knobs หรือ ✍ code)")}`,` ${o("vs <nick>")} ${t("ท้าแข่ง: แผนที่ละ 1 เกม รวม 3 แผนที่ (แผนที่สมมาตร สลับที่นั่งผลเหมือนเดิม) รู้ผลใน 5–30 วินาที")}`,` ${o("vs <nick> v1")} ${t("แข่งกับ bot เวอร์ชันเก่าของอีกฝ่าย")}`,"",a(" เวอร์ชันเก่าของฉัน (knobs / โค้ดเก็บไว้บนเซิร์ฟเวอร์)"),` ${o("bots")} ${t("ทุกเวอร์ชันที่คุณอัปโหลด (ห้องนี้ + ห้องอื่น + ถ้วย)")}`,` ${o("show 12")} ${t("ดูเวอร์ชัน 12: knobs หรือโค้ด; show 12 code = ทั้งไฟล์")}`,` ${o("get 12")} ${t("บันทึกเวอร์ชัน 12 เป็นไฟล์ (bot.py ไม่เปลี่ยน)")}`,` ${o("restore 12")} ${t("ใส่เวอร์ชัน 12 กลับเข้า bot.py (ไฟล์เดิมเป็น bot.py.bak) แล้ว up")}`,"",a(" ดูรีเพลย์ — ใช้ตัวเลขสองตัว: เลขแมตช์ + เลขเกม"),` ${o("log")} ${t("① แมตช์วันนี้ เลข #12 ต้นบรรทัดคือเลขแมตช์; 🎬 = มีรีเพลย์")}`,` ${o("history")} ${t(" เหมือนกัน แต่แสดงทุกวัน")}`,` ${o("replay 12 3")} ${t("② แมตช์ #12 เกมที่ 3 (แมตช์ละ 3 เกม: 1–3; ดูของคนอื่นได้ด้วย)")}`,` ${o("replay 12")} ${t(" ใส่แค่เลขแมตช์ = เกมที่ 1 ของแมตช์นั้น")}`,` ${o("replay 3")} ${t(" เพิ่งแข่งเสร็จ? ไม่ต้องใส่เลขแมตช์: เกมที่ 3 ของแมตช์ล่าสุด")}`,` ${o("replay")} ${t(" เกมที่คุณแพ้ในแมตช์ล่าสุด")}`,t(" ③ ระหว่างเล่น: space = หยุด · ← → = ทีละขั้น · ↑ ↓ = ความเร็ว · q = กลับห้อง"),t(' ตัวอย่าง: log แสดง "#387 … 2-1 🎬" → replay 387 1 … replay 387 3'),"",a(" ตารางคะแนน (กติกาที่ยุติธรรม)"),` ${o("Enter")} ${t("ตารางวันนี้: ดูจำนวนคนที่คุณชนะได้ (ไม่นับคนซ้ำ) ก่อน แล้วจึงดูอัตราชนะ แล้วจำนวนครั้งที่ชนะ")}`,t(' · bot คู่เวอร์ชันเดิมนับคะแนนได้วันละครั้ง แข่งซ้ำได้และดูรีเพลย์ได้ แต่จะขึ้นว่า "ไม่นับคะแนน"'),t(" ฝ่ายใดฝ่ายหนึ่งอัปโหลดเวอร์ชันใหม่ = เป็นคู่ใหม่ นับคะแนนอีกครั้ง"),t(" · แผนที่ของแต่ละวันถูกกำหนดไว้แล้ว: คู่เวอร์ชันเดิมแข่งซ้ำ ผลจะเหมือนเดิมทุกครั้ง"),t(" · สองบัญชีบนเครื่องเดียวกันท้าแข่งกันไม่ได้ — PvP ต้องเป็นคนสองคน"),` ${o("help")} ${t("ดูแผงขั้นตอนอีกครั้ง")} ${o("guide")} ${t("ดูคู่มือนี้อีกครั้ง")} ${o("card")} ${t("กลับไปที่การ์ด")}`,"",t(" กติกาสั้น ๆ: ทำลาย warren ของอีกฝ่ายได้ก็ชนะ ถ้าครบ 200 เทิร์น ฝ่ายที่มีมูลค่ากองทัพสูงกว่าชนะ"),t(" (นับเฉพาะทหารที่ยังรอด ไม่นับ wombat และ warren) ต่างกันไม่ถึง 5% ถือว่าเสมอ ท้าแข่งได้ทุก 30 วินาที"),t(" ถ้าเห็นข้อความว่าเครื่องตัดสินไม่พร้อม รอสักหนึ่งนาทีแล้วลอง vs อีกครั้ง")]:[a(` BattleAI PvP room · how to play (room ${e})`),"",a(" Open or join a room"),` ${o("room new Mock")} ${t("open a room → pick a nickname → you get a 4-letter code → give it to the others")}`,` ${o("room KZE6")} ${t("join a friend's room (nickname once)")}`,` ${o("room open")} ${t("the public room, anyone can enter; its table resets every day")}`,"",a(" Inside the room (prompt icoa room XXXX>) — the panel on entry ticks the steps you did"),` ${o("template")} ${t("puts the 15-knob starter at ~/.icoa/battleai/bot.py (pro: template code = blank code template)")}`,` ${o("knobs")} ${t("list the 15 knobs with their meaning")}`,` ${o("set WOMBATS 6")} ${t("change one knob, no coding (rookie way)")}`,` ${o("edit")} ${t("open bot.py in vi and rewrite act(u) below the knobs (pro way; i = type, Esc, :wq = save)")}`,` ${o("run")} ${t("one local test game, just to see that the bot runs (optional, needs python setup)")}`,` ${o("up")} ${t("upload your bot → v1, v2, v3 … (each upload is a new version; tagged 🔧 knobs or ✍ code)")}`,` ${o("vs <nick>")} ${t("challenge someone: one game on each of the 3 maps (symmetric maps, swapping seats changes nothing), result in 5–30 s")}`,` ${o("vs <nick>")} ${t("only their CURRENT bot can be challenged (old versions can't — no score farming)")}`,"",a(" My old versions (knobs / code are kept on the server)"),` ${o("bots")} ${t("every version you uploaded (this room + other rooms + cups)")}`,` ${o("show 12")} ${t("see v12: its knobs, or its code; show 12 code = the whole file")}`,` ${o("get 12")} ${t("save v12 as a file (bot.py is not touched)")}`,` ${o("restore 12")} ${t("put v12 back into bot.py (the old one becomes bot.py.bak), then up")}`,"",a(" Watching replays — two numbers: match # + game #"),` ${o("log")} ${t("① today's matches; #12 at the line start = match number; 🎬 = replay kept")}`,` ${o("history")} ${t(" the same, for all days")}`,` ${o("replay 12 3")} ${t("② match #12, game 3 (3 games per match: 1–3; any player)")}`,` ${o("replay 12")} ${t(" match number only = game 1 of that match")}`,` ${o("replay 3")} ${t(" just played? skip the match #: game 3 of your last match")}`,` ${o("replay")} ${t(" the game you lost in your last match")}`,t(" ③ while it plays: space = pause · ← → = step · ↑ ↓ = speed · q = back to the room"),t(' e.g. log shows "#387 … 2-1 🎬" → replay 387 1 … replay 387 3'),"",a(" Table (fair rules)"),` ${o("Enter")} ${t("today's table: most different people beaten first, then win rate, then wins")}`,t(' · The same two bot versions count once a day. You can play them again and watch the replays, but it says "not counted".'),t(" Either side uploading a new version makes a new pair, which counts again."),t(" · The day's maps are fixed: the same two versions always get the same result, so re-rolling luck does nothing."),t(" · Two accounts on the same computer cannot challenge each other — PvP needs two different people."),` ${o("help")} ${t("the step panel again")} ${o("guide")} ${t("this sheet again")} ${o("card")} ${t("back to your card")}`,"",t(" Rule in one line: destroy their warren to win; at the 200-turn cap the higher army value wins (live soldiers; wombats and warrens do not count), within 5% is a draw. One challenge every 30 s."),t(' If you see "the judge is unavailable", wait a minute and try vs again.')];console.log();for(const e of r)console.log(e)}export async function runPvpRoom(e,t,n,i={}){const g=i.interactive??d,y=f(),w=n.trim();let _="",E="",A=!1;const B=/^(?:new|create|开房|建)(?:\s+(.*))?$/i.exec(w),x=/^(?:join|enter|进)\s+(\S+)$/i.exec(w);if(B?(A=!0,E=(B[1]??"").trim().slice(0,40)):x?_=x[1]:/^(?:open|public|公共)$/i.test(w)?_="OPEN":w&&(_=w),_=_.toUpperCase().replace(/[^A-Z0-9]/g,"").slice(0,8),!A&&!_){const o=await h("status",e);if(!o.ok||!o.data)return console.log(chalk.yellow(" "+V(o.code,o.message))),"back";if(console.log(),console.log(chalk.bold.white(v(" ⚔ PvP rooms"," ⚔ PvP 房间"," ⚔ ห้อง PvP"))+chalk.gray(v(" — your bot against real people, one game on each of 3 maps."," —— 和真人的 bot 对打,3 张图定胜负。"," — bot ของคุณสู้กับ bot ของคนจริง แผนที่ละ 1 เกม รวม 3 แผนที่"))),o.data.rooms.length)for(const e of o.data.rooms)console.log(` ${chalk.bold.cyan(P(e.room,6))} ${chalk.white(e.public?v("open room","公共房","ห้องสาธารณะ"):e.label||"")} ${chalk.gray(`· ${e.members} ${v("members","人","คน")} · ${v("you are","你是","คุณคือ")} ${e.nick}`)}`);else console.log(chalk.gray(v(" You are not in any room yet."," 你还没进过任何房间。"," คุณยังไม่ได้อยู่ในห้องใดเลย")));return console.log(chalk.gray(" ▸ ")+chalk.bold.green("room open")+chalk.gray(v(" the public room — anyone can enter, the table resets daily"," 公共房,谁都能进,战绩每天清零"," ห้องสาธารณะ — ใครก็เข้าได้ ตารางคะแนนเริ่มใหม่ทุกวัน"))),console.log(chalk.gray(" ▸ ")+chalk.bold.green("room <CODE>")+chalk.gray(v(" enter a friend's room (4-letter code)"," 进朋友开的房(4 个字母)"," เข้าห้องของเพื่อน (รหัส 4 ตัวอักษร)"))),console.log(chalk.gray(" ▸ ")+chalk.bold.green(v("room new [label]","room new [名字]","room new [ชื่อห้อง]"))+chalk.gray(v(" open a new room and hand out its code"," 开一个新房,把房号发给朋友"," เปิดห้องใหม่แล้วส่งรหัสให้เพื่อน"))),"back"}let L=null;if(A){const o=await W(t);if(null===o)return"back";const a=await h("create",e,{label:E,nick:o});if(!a.ok||!a.data)return console.log(chalk.yellow(" "+V(a.code,a.message))),"back";L=a.data,console.log(chalk.green(" ✓ ")+chalk.white(v("Room created — the code is ","房间开好了,房号 ","สร้างห้องแล้ว — รหัสห้องคือ "))+chalk.bold.cyan(L.room)+chalk.white(v(`. Friends type room ${L.room}`,`,告诉朋友敲 room ${L.room}`,` ให้เพื่อนพิมพ์ room ${L.room}`)))}else{const o=await h("status",e,{room:_});if(o.ok&&o.data)L=o.data;else{if("not_member"!==o.code)return console.log(chalk.yellow(" "+V(o.code,o.message))),"back";{const o=await h("join",e,{room:_,probe:!0}),a=o.data?.label||("OPEN"===_?v("Open room","公共房","ห้องสาธารณะ"):_);console.log(chalk.white(` ${v("Entering","进入","กำลังเข้าห้อง")} `)+chalk.bold.cyan(_)+chalk.gray(` ${a} · ${o.data?.members??"?"} ${v("members","人","คน")}`));for(let o=0;o<4&&!L;o++){const o=await W(t);if(null===o)return"back";const a=await h("join",e,{room:_,nick:o});a.ok&&a.data?L=a.data:console.log(chalk.yellow(" "+V(a.code,a.message)))}if(!L)return"back"}}}const U=L.room,D=chalk.bold.magenta(`icoa room ${U}> `);let K=L.recent.find(e=>e.mine&&e.replays)?.id??0;for(o(DEFAULT_PVP_BOT)||L.my_versions.length||M(U),F(L),console.log(chalk.gray(" ▸ ")+chalk.bold.green("guide")+chalk.gray(v(" the full command sheet"," 完整命令说明"," คู่มือคำสั่งฉบับเต็ม"))),N(L),T(U);;){const n=await t(D);if(null===n)return"back";const i=n.trim(),d=i.toLowerCase();if(k.has(d))return"back";if("menu"===d||"home"===d)return"menu";if(""===d||"who"===d||"board"===d||"table"===d||"r"===d||"refresh"===d){const o=await h("status",e,{room:U});o.ok&&o.data?N(o.data):console.log(chalk.yellow(" "+V(o.code,o.message)));continue}if("guide"===d||"howto"===d||"how"===d||"说明"===d||"教程"===d||"คู่มือ"===d){M(U),T(U);continue}if("help"===d||"?"===d){const o=await h("status",e,{room:U});F(o.ok&&o.data?o.data:null),T(U);continue}if("log"===d||"matches"===d||"history"===d){const o=await h("matches",e,{room:U,limit:20,all:"history"===d});if(o.ok&&o.data){o.data.matches.length||console.log(chalk.gray(v(" No matches today yet."," 今天还没有对局。"," วันนี้ยังไม่มีแมตช์")));for(const e of o.data.matches)console.log(" "+O(e));o.data.matches.length&&console.log(chalk.gray(v(" 🎬 = replays kept: replay <match#> <game#>, e.g. replay 12 3; matches without 🎬 were played before replays were stored."," 🎬 = 有回放:replay <场号> <局号>,例如 replay 12 3;没有 🎬 的是旧对局,回放没存。"," 🎬 = มีรีเพลย์: replay <เลขแมตช์> <เลขเกม> เช่น replay 12 3; แมตช์ที่ไม่มี 🎬 แข่งก่อนที่จะเริ่มเก็บรีเพลย์"))),o.data.matches.some(e=>0===e.counted)&&console.log(chalk.gray(v(" not counted = the same two bot versions already played that day; up a new version to count again."," 不计分 = 这一对 bot 版本当天已经打过;上传新版本才重新计分。"," ไม่นับคะแนน = bot คู่เวอร์ชันนี้แข่งกันไปแล้ววันนั้น; up เวอร์ชันใหม่เพื่อให้นับคะแนนอีกครั้ง")))}else console.log(chalk.yellow(" "+V(o.code,o.message)));continue}const w=/^(?:replay|回放)(?:\s+(last|\d+))?(?:\s+(\d+))?$/i.exec(i);if(w){const t=s(r(),".icoa","battleai","last.mobreplay"),a=()=>console.log(chalk.yellow(v(" The replay is saved here, but the viewer needs Python 3.12 and the arena engine: run python setup, open battle once (it fetches the engine), then replay again."," 回放已存在本机,但播放器需要 Python 3.12 和竞技场引擎:先 python setup,再进一次 battle(它会下载引擎),回来再敲 replay。"," บันทึกรีเพลย์ไว้ในเครื่องแล้ว แต่ตัวเล่นต้องใช้ Python 3.12 และ arena engine: รัน python setup แล้วเปิด battle หนึ่งครั้ง (จะดาวน์โหลด engine ให้) จากนั้นพิมพ์ replay อีกครั้ง")));let n=0,i=0;const c=w[1]&&"last"!==w[1].toLowerCase()?Number(w[1]):0,d=w[2]?Number(w[2]):0;if(c&&d)n=c,i=d;else if(c>=1&&c<=6){if(n=K,i=c,!n){console.log(chalk.gray(v(" No match to replay yet — play one (vs), or replay <match#> <game> for a 🎬 match from log."," 还没有可回看的对局 —— 先 vs 打一场,或 replay <场号> <局> 指定 log 里带 🎬 的一场。"," ยังไม่มีแมตช์ให้ดูรีเพลย์ — แข่งก่อนหนึ่งแมตช์ (vs) หรือ replay <เลขแมตช์> <เกม> สำหรับแมตช์ที่มี 🎬 ใน log")));continue}}else c>6&&(n=c,i=1);if(n&&i){const o=await h("replay",e,{room:U,match_id:n,game:i},3e4);if(!o.ok||!o.data){console.log(chalk.yellow(" "+V(o.code,o.message)));continue}const t=b(o.data.seat_a,o.data.a,o.data.b),r="a"===o.data.winner?o.data.a:"b"===o.data.winner?o.data.b:null,s=e=>t?t.blue===e?m(0):m(1):"",c=e=>chalk.bold.white(e)+s(e);if(console.log(chalk.gray(` #${n} ${v(`game ${i}`,`第 ${i} 局`,`เกมที่ ${i}`)} · ${o.data.map} · `)+(t?`${m(0).trim()} ${chalk.bold.white(t.blue)}${chalk.gray(" vs ")}${m(1).trim()} ${chalk.bold.white(t.red)}`:`${c(o.data.a)}${chalk.gray(" vs ")}${c(o.data.b)}`)+chalk.gray(` · ${v("winner","胜者","ผู้ชนะ")}: `)+(r?c(r):chalk.gray(v("draw","平局","เสมอ")))),!p(o.data.replay,t)){console.log(chalk.yellow(v(" Could not save the replay."," 回放存不下来。"," บันทึกรีเพลย์ไม่ได้")));continue}await l(g)||a();continue}if(!o(t)){console.log(chalk.gray(v(" No replay yet — play a match (vs); then replay 3 shows game 3 and replay shows the game you lost."," 还没有回放 —— 先 vs 打一场;打完 replay 3 看第 3 局,replay 看你输的那局。"," ยังไม่มีรีเพลย์ — แข่งหนึ่งแมตช์ (vs) ก่อน แล้ว replay 3 จะแสดงเกมที่ 3 และ replay จะแสดงเกมที่คุณแพ้")));continue}await l(g)||a();continue}if(await myBotsCommand(i,e,U))continue;if("knobs"===d||"knob"===d||"旋钮"===d||"set"===d){const e=j();null===e?F(null):printKnobs(e);continue}const f=/^(?:set|改)\s+(.+)$/i.exec(i);if(f){const e=j();null===e?F(null):setKnob(e,f[1]);continue}const _=/^(?:template|模板)(?:\s+(knobs?|code|新手|高手))?(?:\s+(force|覆盖))?$/i.exec(i);if(_){const e=/^(?:code|高手)$/i.test(_[1]??"")?"code":"knobs";await writeTemplate(e,!!_[2],y);continue}if("edit"===d||"vi"===d||"编辑"===d){if(!o(DEFAULT_PVP_BOT)){F(null);continue}console.log(chalk.gray(v(" vi survival: i = edit · Esc = stop editing · :wq = save and leave · :q! = discard"," vi 三键: i 进入编辑 · Esc 退出编辑 · :wq 存盘离开 · :q! 放弃"," vi เบื้องต้น: i = เริ่มแก้ไข · Esc = หยุดแก้ไข · :wq = บันทึกแล้วออก · :q! = ไม่บันทึก"))),await g("vi",[...u,DEFAULT_PVP_BOT]);continue}if("run"===d||"test"===d||"play"===d||"试打"===d){if(!o(DEFAULT_PVP_BOT)){F(null);continue}if(!$().ok){console.log(chalk.gray(v(" No Python 3.12 here — python setup first; up / vs still work without it (the judge is server-side)."," 本机没有 Python 3.12,先 python setup;没有它也能 up / vs(判分在服务器)。"," เครื่องนี้ไม่มี Python 3.12 — รัน python setup ก่อน; ถึงไม่มีก็ยังใช้ up / vs ได้ (การตัดสินทำบนเซิร์ฟเวอร์)")));continue}console.log(chalk.gray(v(" One local game (the card-12 sparring bot) to see that the bot runs…"," 本地打一场(对卡 12 的陪练),看看 bot 跑不跑得起来…"," ทดลองเล่นในเครื่อง 1 เกม (กับ bot คู่ซ้อมของการ์ด 12) เพื่อดูว่า bot รันได้…"))),await c(DEFAULT_PVP_BOT,12,0,void 0,g);continue}const P=/^(?:up|upload|submit|上传)(?:\s+(.+))?$/i.exec(i);if(P){const t=(P[1]??"").trim()||DEFAULT_PVP_BOT;if(!o(t)){console.log(chalk.yellow(` ${v("Not found","找不到","ไม่พบไฟล์")}: ${t}`)),F(null);continue}let n="";try{n=a(t,"utf8")}catch{console.log(chalk.yellow(` ${v("Could not read","读不了","อ่านไฟล์ไม่ได้")}: ${t}`));continue}const r=await C(n),s=await h("upload",e,{room:U,code:n,group:r},3e4);if(!s.ok||!s.data){console.log(chalk.yellow(" "+V(s.code,s.message)));continue}s.data.unchanged?console.log(chalk.gray(v(` Identical to v${s.data.version} — nothing new.`,` 和 v${s.data.version} 一字不差,没有新版本。`,` เหมือนกับ v${s.data.version} ทุกตัวอักษร — ไม่มีเวอร์ชันใหม่`))):console.log(chalk.green(" ✓ ")+chalk.white(v(`Uploaded as v${s.data.version}`,`已上传为 v${s.data.version}`,`อัปโหลดเป็น v${s.data.version} แล้ว`))+chalk.gray(` (${t})`)+(r?chalk.gray("rookie"===r?v(" · 🔧 knobs only (rookie)"," · 🔧 新手组(只动了旋钮)"," · 🔧 แก้เฉพาะ knobs (มือใหม่)"):v(" · ✍ custom code (pro)"," · ✍ 高手组(改了代码)"," · ✍ เขียนโค้ดเอง (pro)")):""));continue}const E=/^(?:vs|challenge|fight|挑战|打)\s+(\S+)(?:\s+v?(\d+))?$/i.exec(i);if(E){const o=E[2]?Number(E[2]):void 0;console.log(chalk.gray(v(" ⚖ The judge is playing the 3 maps — usually 5–20 s, up to 3 min…"," ⚖ 判分机在打 3 张图,通常 5–20 秒,最多 3 分钟…"," ⚖ เครื่องตัดสินกำลังเล่น 3 แผนที่ — ปกติ 5–20 วินาที นานสุด 3 นาที…")));const t=await h("challenge",e,{room:U,nick:E[1],version:o},2e5);if(!t.ok||!t.data){console.log(chalk.yellow(" "+V(t.code,t.message)));continue}t.data.replays&&(K=t.data.match_id),S(t.data),N(t.data.status);continue}/^(?:vs|challenge|挑战|打)$/i.test(i)?console.log(chalk.gray(v(" Usage: vs <nick> or vs <nick> v2 (their version 2)"," 用法: vs <昵称> 或 vs <昵称> v2(打对方的第 2 版)"," วิธีใช้: vs <ชื่อเล่น> หรือ vs <ชื่อเล่น> v2 (เวอร์ชัน 2 ของอีกฝ่าย)"))):(console.log(chalk.gray(v(` Unknown: "${i}".`,` 不认识「${i}」。`,` ไม่รู้จักคำสั่ง "${i}"`))),T(U))}}async function W(e){for(let o=0;o<4;o++){const o=await e(chalk.bold.cyan(v(" Your nickname (2–12 letters/digits, not your real name; back to cancel): "," 你的昵称(2–12 个字母/数字,别用真名;back 取消): "," ชื่อเล่นของคุณ (ตัวอักษร/ตัวเลข 2–12 ตัว ไม่ใช่ชื่อจริง; back เพื่อยกเลิก): ")));if(null===o||k.has(o.toLowerCase()))return null;if(/^[A-Za-z0-9_\-一-鿿]{2,12}$/.test(o))return o;console.log(chalk.gray(v(" 2–12 letters, digits, _ or -; no spaces."," 2–12 个字母、数字、_ 或 -,不能有空格。"," ใช้ตัวอักษรภาษาอังกฤษ ตัวเลข _ หรือ - ได้ 2–12 ตัว ห้ามเว้นวรรค")))}return null}function V(e,o){switch(e){case"wrong_course":return v("PvP rooms are for BattleAI (battleai-48) tokens.","PvP 房间只对 BattleAI(battleai-48)token 开放。","ห้อง PvP ใช้ได้กับ token ของ BattleAI (battleai-48) เท่านั้น");case"demo_not_supported":return v("Demo tokens cannot enter PvP rooms.","demo token 进不了 PvP 房间。","token ทดลองเข้าห้อง PvP ไม่ได้");case"no_room":return v("No room with that code — check the four letters.","没有这个房号 —— 检查一下 4 个字母。","ไม่มีห้องรหัสนี้ — ตรวจสอบตัวอักษรทั้ง 4 ตัวอีกครั้ง");case"nick_taken":return v("That nickname is taken in this room — pick another.","这个昵称在房里已经有人用了,换一个。","ชื่อเล่นนี้มีคนใช้แล้วในห้องนี้ — กรุณาเลือกชื่ออื่น");case"bad_nick":return v("Nickname: 2–12 letters/digits, no spaces.","昵称要 2–12 个字母/数字,不能有空格。","ชื่อเล่น: ตัวอักษร/ตัวเลข 2–12 ตัว ห้ามเว้นวรรค");case"no_bot":return v("Upload your bot first: up","先 up 上传你的 bot。","อัปโหลด bot ของคุณก่อน: up");case"old_version":return v(`Only the current bot can be challenged${o?.match(/v\d+/)?` (now ${o.match(/v\d+/)?.[0]})`:""} — type vs <nick> without a version.`,`只能挑战对方的最新版本${o?.match(/v\d+/)?`(现在是 ${o.match(/v\d+/)?.[0]})`:""} —— 敲 vs <昵称>,不要带版本号。`,`ท้าได้เฉพาะ bot เวอร์ชันล่าสุด${o?.match(/v\d+/)?` (ตอนนี้ ${o.match(/v\d+/)?.[0]})`:""} — พิมพ์ vs <ชื่อ> โดยไม่ใส่เวอร์ชัน`);case"opp_no_bot":return o||v("They have no bot yet.","对方还没上传 bot。","อีกฝ่ายยังไม่มี bot");case"no_such_nick":return v("Nobody by that name here — press Enter for the table.","房里没有这个昵称 —— 回车看名单。","ไม่มีคนชื่อนี้ในห้อง — กด Enter เพื่อดูตาราง");case"self":return v("You cannot challenge yourself.","不能挑战自己。","คุณท้าแข่งกับตัวเองไม่ได้");case"same_device":return v("These two accounts are on the same device — PvP needs two different people.","这两个账号在同一台设备上 —— PvP 需要两个不同的人。","สองบัญชีนี้อยู่บนเครื่องเดียวกัน — PvP ต้องเป็นคนสองคนที่ต่างกัน");case"cooldown":return v("One challenge every 30 seconds.","每 30 秒只能发起一场。","ท้าแข่งได้ทุก 30 วินาที กรุณารอสักครู่");case"no_match":return v("No match with that number in this room — see log for the #.","这个房间里没有这个场号 —— log 看场号(#)。","ไม่มีแมตช์เลขนี้ในห้องนี้ — ดูเลข # ได้จาก log");case"no_replay":return v("No replay was kept for that match (played before replays were stored).","这一场没有存回放(是回放功能上线前打的)。","แมตช์นั้นไม่มีรีเพลย์ (แข่งก่อนที่จะเริ่มเก็บรีเพลย์)");case"bad_game":return v("The game number is 1 to 6.","局号是 1 到 6。","เลขเกมคือ 1 ถึง 6");case"no_act":return v("That file has no act(u) — is it your bot.py?","这个文件里没有 act(u) —— 确定是你的 bot.py?","ไฟล์นี้ไม่มี act(u) — ใช่ bot.py ของคุณหรือเปล่า?");case"judge_unreachable":case"judge_timeout":case"judge_rejected":case"judge_not_configured":return v("The judge is unavailable right now — try again in a minute.","判分机暂时不可用,一分钟后再试。","ตอนนี้เครื่องตัดสินยังไม่พร้อม — กรุณาลองใหม่ในอีกหนึ่งนาที");default:return o||v("Could not reach the server.","连不上服务器。","เชื่อมต่อเซิร์ฟเวอร์ไม่ได้")}}
|
|
1
|
+
import{copyFileSync as e,existsSync as o,mkdirSync as t,readFileSync as a,writeFileSync as n}from"node:fs";import{homedir as r}from"node:os";import{join as s}from"node:path";import chalk from"chalk";import{playSavedReplay as l,resolveEngineDir as i,runMobLocal as c,saveJudgeReplay as g}from"../commands/battle.js";import{getConfig as p}from"./config.js";import{runInteractive as y}from"./interactive-spawn.js";import{learnPost as d}from"./learn-contest.js";import{probePython as $}from"./python-setup.js";import{ARENA_VI_FLAGS as b}from"./vi-flags.js";export const PVP_RE=/^\/?(?:room|rooms|pvp|房间|对战房)(?:\s+(.*))?$/i;function u(e,o,t){return 0!==e&&1!==e?null:0===e?{blue:o,red:t}:{blue:t,red:o}}const m=e=>0===e?chalk.cyan(v(" 🟦 blue"," 🟦 蓝"," 🟦 น้ำเงิน")):chalk.red(v(" 🟥 red"," 🟥 红"," 🟥 แดง")),h=(e,o,t={},a=2e4)=>d(`/api/icoa/learn/pvp/${e}`,{token:o.toUpperCase(),...t},a),w=()=>{const e=(p().language||"en").toLowerCase();return e.startsWith("zh")?"zh":e.startsWith("th")?"th":"en"},v=(e,o,t)=>{const a=w();return"zh"===a?o:"th"===a?t:e},f=()=>"zh"===w(),k=new Set(["back","b","quit","q","exit","card","lesson","卡片"]);export const DEFAULT_PVP_BOT=s(r(),".icoa","battleai","bot.py");const _=e=>{let o=0;for(const t of e){const e=t.codePointAt(0)??0;3633===e||e>=3636&&e<=3642||e>=3655&&e<=3662||(o+=e>65535||e>=11904&&e<=42191||e>=44032&&e<=55203||e>=63744&&e<=64255?2:1)}return o},P=(e,o)=>e+" ".repeat(Math.max(0,o-_(e)));function T(e){console.log(chalk.gray(v(` knobs · set <KNOB> <value> · run (local test) · up (upload) · vs <nick> (challenge) · Enter (table) · log · replay 3 (game 3) · edit · template · guide · card (${e})`,` knobs · set <旋钮> <值> · run 试打 · up 上传 · vs <昵称> 挑战 · 回车 战绩表 · log · replay 3 看第 3 局 · edit · template · guide 说明 · card 回卡片 (${e})`,` knobs · set <KNOB> <ค่า> · run ทดลองเล่น · up อัปโหลด · vs <ชื่อเล่น> ท้าแข่ง · Enter ตารางคะแนน · log · replay 3 ดูเกมที่ 3 · edit · template · guide คู่มือ · card กลับไปที่การ์ด (${e})`)))}const E=e=>"rookie"===e?v("🔧 knobs","🔧 新手","🔧 knobs"):"pro"===e?v("✍ code","✍ 高手","✍ code"):"—";function N(e){const o=f(),t=e.public?v("Open room","公共房","ห้องสาธารณะ"):e.label||v("Room","房间","ห้อง");if(console.log(),console.log(chalk.bold.white(` ⚔ ${t} `)+chalk.bold.cyan(e.room)+chalk.gray(` · ${v("you are","你是","คุณคือ")} ${e.nick??"?"} · ${e.members.length} ${v("members","人","คน")} · ${v("today","今日","วันนี้")} ${e.day}${e.public?v(" · table resets daily"," · 战绩每天清零"," · ตารางเริ่มใหม่ทุกวัน"):""}`)),(e=>"distinct_beaten"===e.ranking&&e.members.every(e=>"number"==typeof e.today.beat))(e)){console.log(chalk.gray(v(" Ranked by how many different people you beat today, then win rate. The same two bot versions count once a day."," 排名先看今天赢过多少个不同的人,再看胜率。同一对 bot 版本每天只计一次。"," จัดอันดับตามจำนวนคนที่คุณชนะได้ (ไม่นับคนซ้ำ) ในวันนี้ แล้วจึงดูอัตราชนะ — bot คู่เวอร์ชันเดิมนับคะแนนได้วันละครั้ง"))),console.log(chalk.gray(o?` ${P("昵称",14)}${P("bot",6)}${P("组",9)}${P("赢过",6)}${P("今日 胜-负-平",15)}${P("打了",7)}累计`:` ${P("nick",14)}${P("bot",6)}${P("group",9)}${P("beat",6)}${P("today W-L-D",15)}${P("played",7)}all-time`));for(const o of e.members){const e=` ${P(o.nick,14)}${P(o.versions?`v${o.versions}`:"—",6)}${P(E(o.group),9)}${P(String(o.today.beat??0),6)}${P(`${o.today.w}-${o.today.l}-${o.today.d}`,15)}${P(String(o.today.played??o.today.n),7)}${o.all.w}-${o.all.l}-${o.all.d}`;console.log(o.me?chalk.bold.cyan(e):chalk.white(e))}}else{console.log(chalk.gray(o?` ${P("昵称",14)}${P("bot",6)}${P("组",9)}${P("今日 胜-负-平",16)}累计`:` ${P("nick",14)}${P("bot",6)}${P("group",9)}${P("today W-L-D",16)}all-time`));for(const o of e.members){const e=` ${P(o.nick,14)}${P(o.versions?`v${o.versions}`:"—",6)}${P(E(o.group),9)}${P(`${o.today.w}-${o.today.l}-${o.today.d}`,16)}${o.all.w}-${o.all.l}-${o.all.d}`;console.log(o.me?chalk.bold.cyan(e):chalk.white(e))}}if(e.my_versions.length||console.log(chalk.yellow(v(" You have no bot here yet — knobs / set, then up."," 你还没上传 bot —— 先 knobs / set,再 up。"," คุณยังไม่มี bot ในห้องนี้ — ใช้ knobs / set แล้วจึง up"))),e.recent.length){console.log(chalk.gray(v(" Today:"," 今日对局:"," แมตช์วันนี้:")));for(const o of e.recent.slice(0,6))console.log(chalk.gray(" ")+O(o))}}const A=()=>chalk.gray(v(" · not counted"," · 不计分"," · ไม่นับคะแนน"));function O(e){const o=null===e.wins_a||void 0===e.wins_a?"-":`${e.wins_a}-${e.wins_b}`,t="WIN"===e.verdict?chalk.green(o):"LOSS"===e.verdict?chalk.red(o):chalk.yellow(o),a=`${e.a} v${e.a_version??"?"} vs ${e.b} v${e.b_version??"?"}`,n=chalk.gray(`#${String(e.id).padEnd(4)} `),r=e.replays?chalk.gray(" 🎬"):"",s="WIN"===e.verdict||"LOSS"===e.verdict||"DRAW"===e.verdict;return`${n}${chalk.gray((e=>{const o=new Date(e);return Number.isNaN(o.getTime())?"":`${String(o.getHours()).padStart(2,"0")}:${String(o.getMinutes()).padStart(2,"0")}`})(e.ts))} ${e.mine?chalk.white(a):chalk.gray(a)} ${t}${r}${e.draws?chalk.gray(` (${e.draws} ${v("draw","平","เสมอ")})`):""}${s&&0===e.counted?A():""}${s?"":chalk.red(` ${e.verdict}`)}`}let B=!1;function S(e){const o=f();console.log();const t=`${e.wins_a}-${e.wins_b}${e.draws?` (${e.draws} ${v("draw","平","เสมอ")})`:""}`,a=chalk.gray(` vs ${e.opp.nick} v${e.opp.version}`),n=0===e.counted&&"repeat_pairing"===e.counted_reason?A():"";if("WIN"===e.verdict)console.log(chalk.bold.green(` 🏆 ${v("You win","你赢了","คุณชนะ")} ${t}`)+a+n);else if("LOSS"===e.verdict)console.log(chalk.bold.red(` ❌ ${v("You lose","你输了","คุณแพ้")} ${t}`)+a+n);else{if("DRAW"!==e.verdict)return void console.log(chalk.yellow(` ⚠ ${v("The judge could not finish this match","判分机没跑完这场","เครื่องตัดสินเล่นแมตช์นี้ไม่จบ")}: ${e.verdict}${e.note?` — ${e.note}`:""}`));console.log(chalk.bold.yellow(` 🤝 ${v("Draw","平局","เสมอ")} ${t}`)+a+n)}n&&(B?console.log(chalk.gray(v(" (same two versions as earlier today — up a new version to count)"," (和今天早些时候是同一对版本 —— 上传新版本才计分)"," (เป็นคู่เวอร์ชันเดิมของวันนี้ — up เวอร์ชันใหม่เพื่อให้นับคะแนน)"))):(B=!0,console.log(chalk.gray(v(" Not counted: these two bot versions already played each other today. Maps are fixed for the day, so the result"," 不计分:这两个 bot 版本今天已经交过手。当天的地图固定,结果不会变"," ไม่นับคะแนน: bot สองเวอร์ชันนี้แข่งกันไปแล้ววันนี้ แผนที่ของวันนี้ถูกกำหนดไว้แล้ว ผลจึงเหมือนเดิม"))),console.log(chalk.gray(v(" is the same (replays still work). To count again, one of you uploads a new version: "," (回放照样能看)。想再计分,任何一方上传新版本即可: "," (ยังดูรีเพลย์ได้ตามปกติ) ถ้าอยากให้นับคะแนนอีก ฝ่ายใดฝ่ายหนึ่งอัปโหลดเวอร์ชันใหม่: "))+chalk.bold.green("up"))),e.cached&&e.cached_from&&console.log(chalk.gray(v(` Same games as match #${e.cached_from} — served instantly, the judge was not needed.`,` 和第 ${e.cached_from} 场完全相同 —— 直接给出,没有占用判分机。`,` เป็นเกมเดียวกับแมตช์ #${e.cached_from} — แสดงผลทันทีโดยไม่ต้องใช้เครื่องตัดสิน`)))),e.load_error?.a&&console.log(chalk.red(` ${v("Your bot failed to load","你的 bot 装不上","bot ของคุณโหลดไม่ขึ้น")}: ${e.load_error.a}`)),e.load_error?.b&&console.log(chalk.gray(` ${v("Opponent's bot failed to load","对方的 bot 装不上","bot ของคู่แข่งโหลดไม่ขึ้น")}: ${e.load_error.b}`)),console.log(chalk.gray(o?` ${P("#",4)}${P("地图",11)}${P("席位",6)}${P("结果",8)}${P("原因",10)}${P("回合",7)}兵力价值 你/对方`:` ${P("#",4)}${P("map",11)}${P("seat",6)}${P("result",8)}${P("how",10)}${P("turns",7)}army value you/them`));for(const t of e.games){const a="a"===t.winner?o?"胜":"win":"b"===t.winner?o?"负":"loss":o?"平":"draw",n="a"===t.winner?chalk.green(P(a,8)):"b"===t.winner?chalk.red(P(a,8)):chalk.yellow(P(a,8)),r="warrens"===t.reason?o?"拆家":"warrens":"timeout"===t.reason?o?"超时":"timeout":"crash"===t.reason?o?"崩溃":"crash":"load_error"===t.reason?o?"装不上":"no load":o?"回合满":"turn cap";console.log(` ${P(String(t.game??e.games.indexOf(t)+1),4)}${P(t.map,11)}${P(String(t.seat_a),6)}${n}${P(r,10)}${P(String(t.turns),7)}${Math.round((t.value??t.lost)[0])}/${Math.round((t.value??t.lost)[1])}${t.error?chalk.gray(` ${t.error}`):""}`)}console.log(chalk.gray(` ${v("seeds","种子","seeds")} ${e.seeds.join(",")} · ${v("destroy their warren to win; at the turn cap the higher army value wins (live soldiers; wombats and warrens do not count), within 5% is a draw","拆掉对方的家就赢;打满回合比兵力价值(活着的兵,wombat 和家不算),相差不到 5% 平局","ทำลาย warren ของอีกฝ่ายได้ก็ชนะ ถ้าครบจำนวนเทิร์น ฝ่ายที่มีมูลค่ากองทัพสูงกว่าชนะ (นับเฉพาะทหารที่ยังรอด ไม่นับ wombat และ warren) ต่างกันไม่ถึง 5% ถือว่าเสมอ")}`)),e.games.length>3&&e.games.some(e=>1===e.seat_a)&&console.log(chalk.gray(v(" ⚖ The seat-swap check came out different (a bot acts differently by seat), so every map was played from both seats."," ⚖ 换席位抽查结果不一样(有 bot 按座位做不同的事),所以每张图两边都打了一遍。"," ⚖ ผลตรวจสลับที่นั่งออกมาไม่เหมือนกัน (มี bot ที่เล่นต่างกันตามที่นั่ง) จึงเล่นทุกแผนที่จากทั้งสองฝั่ง")));const r=e.games.findIndex(e=>"b"===e.winner)+1,s=e.games.find(e=>"b"===e.winner);e.replay&&g(e.replay,s?u(s.seat_a,e.me.nick,e.opp.nick):null),e.replays?console.log(chalk.gray(" ▸ ")+chalk.bold.green("replay 3")+chalk.gray(v(` watch game 3 (any of 1–${e.games.length}) · `,` 看第 3 局(1–${e.games.length} 任选)· `,` ดูเกมที่ 3 (เลือกได้ 1–${e.games.length}) · `))+chalk.bold.green("replay")+chalk.gray(r?v(` the game you lost (#${r}) · `,` 看你输掉的第 ${r} 局 · `,` เกมที่คุณแพ้ (#${r}) · `):v(" game 1 · "," 看第 1 局 · "," เกมที่ 1 · "))+chalk.bold.green(`replay ${e.match_id} 3`)+chalk.gray(v(" this match later, from log"," 以后从 log 里回看这场"," ดูแมตช์นี้ภายหลังจาก log"))):e.replay&&console.log(chalk.gray(" ▸ ")+chalk.bold.green("replay")+chalk.gray(e.wins_b?v(" watch the first game you lost"," 看你输掉的第一局"," ดูเกมแรกที่คุณแพ้"):v(" watch game 1"," 看第一局"," ดูเกมที่ 1")))}const x=e=>{const o=e.search(/^# ── KNOBS/m);let t=e;if(o>=0){const a=e.slice(o).split("\n").slice(1),n=a.findIndex(e=>/^# ───/.test(e));t=(n>=0?a.slice(0,n):a).join("\n")}return[...new Set([...t.matchAll(/^([A-Z][A-Z0-9_]*)\s*=\s*[^#\n]+/gm)].map(e=>e[1]))]},L=(e,o)=>{const t=new RegExp(`^${o}\\s*=\\s*([^#\n]*?)\\s*(?:#.*)?$`,"m").exec(e);return t?t[1]:null},U=(e,o)=>{const t=new RegExp(`^${o}\\s*=[^#\n]*#\\s*(.*)$`,"m").exec(e);return t?t[1].trim():""},j=()=>{try{return a(DEFAULT_PVP_BOT,"utf8")}catch{return null}},D=e=>e.split("\n").map(e=>e.replace(/\s+#.*$/,"").trimEnd()).filter(e=>e.trim()&&!e.trim().startsWith("#")&&!/^[A-Z][A-Z0-9_]*\s*=/.test(e));async function C(e){const o=await i();if(!o)return null;try{const t=a(s(o,"bots","knob_bot.py"),"utf8");return D(t).join("\n")===D(e).join("\n")?"rookie":"pro"}catch{return null}}export async function writeTemplate(a,n,l){const c=await i();if(!c)return console.log(chalk.yellow(v(" The arena engine is not on this machine yet (one online fetch needed)."," 引擎还没下载到本机(需要联网一次)。"," เครื่องนี้ยังไม่มี arena engine (ต้องต่ออินเทอร์เน็ตดาวน์โหลดหนึ่งครั้ง)"))),!1;const g=s(c,"bots","knobs"===a?"knob_bot.py":l?"template_bot_zh.py":"template_bot.py");if(!o(g))return console.log(chalk.yellow(` ${v("Template missing in the engine","引擎里没有模板","ไม่พบเทมเพลตใน engine")}: ${g}`)),!1;if(t(s(r(),".icoa","battleai"),{recursive:!0}),o(DEFAULT_PVP_BOT)){if(!n)return console.log(chalk.yellow(v(" bot.py already exists — not overwritten."," bot.py 已经存在,不覆盖。"," มี bot.py อยู่แล้ว — ไม่เขียนทับ"))+chalk.gray(v(" To replace it: "," 确定要换: "," ถ้าต้องการแทนที่: "))+chalk.bold.green(`template ${a} force`)+chalk.gray(v(" (the old file is kept as bot.py.bak)","(旧文件留作 bot.py.bak)"," (ไฟล์เดิมจะเก็บไว้เป็น bot.py.bak)"))),console.log(chalk.gray(" ▸ ")+chalk.gray(v("That is your own bot — the same bot.py you use in the PvP room. ","那就是你自己的 bot —— 和 PvP 房间里用的是同一个 bot.py。","นั่นคือ bot ของคุณเอง — bot.py ไฟล์เดียวกับที่ใช้ในห้อง PvP "))+chalk.bold.green("knobs")+chalk.gray(v(" = see its settings · "," 看它的设置 · "," = ดูการตั้งค่า · "))+chalk.bold.green("up")+chalk.gray(v(" = send it as it is"," 原样上传"," = ส่งไปตามนี้"))),!1;e(DEFAULT_PVP_BOT,`${DEFAULT_PVP_BOT}.bak`)}return e(g,DEFAULT_PVP_BOT),console.log(chalk.green(" ✓ ")+chalk.white("knobs"===a?v("The 15-knob starter is now your bot.py","15 个旋钮的新手模板已放到 bot.py","ตอนนี้ bot.py ของคุณคือเทมเพลตเริ่มต้นแบบ 15 knobs แล้ว"):v("The blank code template is now your bot.py (pro)","空白代码模板已放到 bot.py(高手组)","ตอนนี้ bot.py ของคุณคือเทมเพลตโค้ดเปล่า (กลุ่ม pro)"))+chalk.gray(` (${DEFAULT_PVP_BOT})`)),!0}export function printKnobs(e){const o=x(e);if(o.length){console.log(chalk.gray(v(" Your knobs (set <KNOB> <value> changes one):"," 你的旋钮(set <旋钮> <值> 改一个):"," knobs ของคุณ (เปลี่ยนทีละตัวด้วย set <KNOB> <ค่า>):")));for(const t of o)console.log(` ${chalk.bold.white(t.padEnd(10))}${chalk.green(`${(L(e,t)??"").padEnd(12)} `)}${chalk.gray(U(e,t))}`)}else console.log(chalk.gray(v(" Your bot.py has no knobs (the NAME = value lines at the top) — it is custom code (pro). For the knob starter type template knobs."," 你的 bot.py 没有旋钮(顶部那种 NAME = value 行)—— 它是高手组的自定义代码。要旋钮版敲 template knobs。"," bot.py ของคุณไม่มี knobs (บรรทัดแบบ NAME = value ด้านบน) — เป็นโค้ดที่เขียนเอง (pro) ถ้าต้องการแบบ knobs พิมพ์ template knobs")))}export async function myBotsCommand(a,l,i){const c=a.trim().toLowerCase();if(/^(?:bots|mybots|my bots|我的版本|เวอร์ชันของฉัน)$/i.test(c)){const e=await h("mybots",l);if(!e.ok||!e.data)return console.log(chalk.yellow(" "+V(e.code,e.message))),!0;const o=e.data.bots;if(!o.length)return console.log(chalk.gray(v(" No uploads yet — up sends bot.py."," 还没上传过 —— up 上传 bot.py。"," ยังไม่เคยอัปโหลด — up ส่ง bot.py"))),!0;const t=Array.from(new Set(o.map(e=>e.room))).sort((e,o)=>e===i?-1:o===i?1:0);for(const e of t){const t=o.filter(o=>o.room===e),a=e.startsWith("CUP-")?v(`cup ${e.slice(4)}`,`杯赛 ${e.slice(4)}`,`ถ้วย ${e.slice(4)}`):v(`room ${e}`,`房间 ${e}`,`ห้อง ${e}`);console.log(chalk.bold.white(` ${a}`)+chalk.gray(` · ${t.length} ${v("versions","个版本","เวอร์ชัน")}${e===i?v(" (here)","(当前)"," (ที่นี่)"):""}`));const n=t.slice().reverse().slice(0,e===i?20:12);for(const e of n)console.log(chalk.gray(" ")+chalk.bold.green(`v${e.version}`.padEnd(6))+chalk.gray(`${(e.ts||"").slice(5,16).replace("T"," ")} UTC `)+chalk.gray(`${e.grp?E(e.grp).padEnd(10):"".padEnd(10)}${e.bytes??"?"} B`));t.length>n.length&&console.log(chalk.gray(` … ${t.length-n.length} ${v("older","个更早的","เก่ากว่า")}`))}return console.log(chalk.gray(v(" show N = see vN (knobs or code) · get N = save it as bot-vN.py · restore N = put it back into bot.py · other room: show TH26 N"," show N 看第 N 版(旋钮或代码)· get N 存成 bot-vN.py · restore N 放回 bot.py · 别的房间:show TH26 N"," show N = ดูเวอร์ชัน N (knobs หรือโค้ด) · get N = บันทึกเป็น bot-vN.py · restore N = ใส่กลับเข้า bot.py · ห้องอื่น: show TH26 N"))),!0}const g=/^(show|get|restore|看|取回|恢复)\s+(?:([A-Za-z][A-Za-z0-9-]*)\s+)?v?(\d+)(?:\s+(code|代码|โค้ด))?$/i.exec(a.trim());if(!g)return!1;const p={"看":"show","取回":"get","恢复":"restore"}[g[1]]??g[1].toLowerCase(),y=(g[2]??i).toUpperCase(),d=Number(g[3]),$=await h("mybot",l,{bot_room:y,version:d});if(!$.ok||!$.data)return console.log(chalk.yellow(" "+("no_bot"===$.code?v(`You have no v${d} in ${y} — type bots.`,`你在 ${y} 没有 v${d} —— 敲 bots 看列表。`,`คุณไม่มี v${d} ใน ${y} — พิมพ์ bots`):V($.code,$.message)))),!0;const b=$.data.code,u=chalk.bold.white(` ${y} v${d}`)+chalk.gray(` · ${($.data.ts||"").slice(0,16).replace("T"," ")} UTC`);if("show"===p){console.log(u);const e=x(b);if(e.length&&!g[4]){for(const o of e)console.log(` ${chalk.bold.white(o.padEnd(10))}${chalk.green(`${(L(b,o)??"").padEnd(12)} `)}${chalk.gray(U(b,o))}`);console.log(chalk.gray(v(` full file: show ${d} code`,` 完整代码:show ${d} code`,` ทั้งไฟล์: show ${d} code`)))}else{const e=b.split("\n"),o=String(e.length).length;for(const[t,a]of e.entries())console.log(chalk.gray(` ${String(t+1).padStart(o)} `)+chalk.white(a))}return console.log(chalk.gray(v(` get ${d} = save as bot-v${d}.py · restore ${d} = put back into bot.py`,` get ${d} 存成 bot-v${d}.py · restore ${d} 放回 bot.py`,` get ${d} = บันทึกเป็น bot-v${d}.py · restore ${d} = ใส่กลับเข้า bot.py`))),!0}const m=s(r(),".icoa","battleai");if(t(m,{recursive:!0}),"get"===p){const e=s(m,`bot-${y.toLowerCase()}-v${d}.py`);return n(e,b),console.log(chalk.green(" ✓ ")+chalk.gray(v("saved ","已存到 ","บันทึกที่ "))+chalk.white(e)),console.log(chalk.gray(v(" bot.py is unchanged · restore puts a version back into bot.py"," bot.py 没动 · restore 才会放回 bot.py"," bot.py ไม่เปลี่ยน · restore จะใส่กลับเข้า bot.py"))),!0}return o(DEFAULT_PVP_BOT)&&e(DEFAULT_PVP_BOT,`${DEFAULT_PVP_BOT}.bak`),n(DEFAULT_PVP_BOT,b),console.log(u),console.log(chalk.green(" ✓ ")+chalk.gray(v(`bot.py is now ${y} v${d} (the old bot.py is bot.py.bak). Type up to upload it as a new version here.`,`bot.py 现在是 ${y} v${d}(原来的留作 bot.py.bak)。敲 up 把它上传成这里的新版本。`,`bot.py ตอนนี้คือ ${y} v${d} (ไฟล์เดิมเก็บเป็น bot.py.bak) พิมพ์ up เพื่ออัปโหลดเป็นเวอร์ชันใหม่ที่นี่`))),!0}export function setKnob(e,o,t){const a=x(e),r=/^([A-Za-z][A-Za-z0-9_]*)\s*(?:=|\s)\s*(.+)$/.exec(o.trim());if(!r)return console.log(chalk.yellow(v(" Usage: "," 用法: "," วิธีใช้: "))+chalk.bold.green(v("set <KNOB> <value>","set <旋钮> <值>","set <KNOB> <ค่า>"))+chalk.gray(v(" e.g. set WOMBATS 6"," 例如 set WOMBATS 6"," เช่น set WOMBATS 6"))),printKnobs(e),!1;const s=r[1].toUpperCase(),l=r[2].trim();if(!a.includes(s))return console.log(chalk.yellow(v(` No knob called ${s}.`,` 没有 ${s} 这个旋钮。`,` ไม่มี knob ชื่อ ${s}`))+chalk.gray(" ")+a.map(e=>chalk.bold.white(e)).join(chalk.gray(" · "))),!1;const i=L(e,s)??"",c=i.trim();let g=l;if(/^(?:True|False)$/.test(c)?/^(?:on|yes|y|true|1)$/i.test(l)?g="True":/^(?:off|no|n|false|0)$/i.test(l)&&(g="False"):/^(['"]).*\1$/.test(c)&&/^[A-Za-z_]+$/.test(l)&&(g=`'${l.toLowerCase()}'`),c===g)return console.log(chalk.gray(" ")+chalk.bold.white(s)+chalk.gray(v(` is already ${g}.`,` 已经是 ${g} 了。`,` เป็น ${g} อยู่แล้ว`))),!1;const p=new RegExp(`^(${s}\\s*=\\s*)([^#\n]*?)(\\s*)(#.*)?$`,"m"),y=e.replace(p,(e,o,t,a,n)=>`${o}${g}${n?(a||" ")+n:""}`);return n(DEFAULT_PVP_BOT,y),console.log(chalk.gray(" ")+chalk.bold.white(s)+chalk.gray(" ")+chalk.gray(i.trim())+chalk.gray(" → ")+chalk.bold.green(g)+chalk.gray(t??v(" next: run to test, up to upload"," 下一步: run 试打,up 上传"," ขั้นต่อไป: run เพื่อทดลอง, up เพื่ออัปโหลด"))),!0}function F(e){const t=o(DEFAULT_PVP_BOT),a=!!e&&e.my_versions.length>0,n=!!e&&e.recent.some(e=>e.mine),r=(e,o,t,a,n=!1)=>` ${chalk.gray(e)} ${((e,o=!1)=>e?chalk.green("✅"):o?chalk.gray("○ "):chalk.white("⬜"))(o,n)} ${chalk.bold.green(P(t,13))}${chalk.gray(a)}`,s=new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`,"g"),l=!("th"===w()),i=e=>l?`${e}${" ".repeat(Math.max(0,70-_(e.replace(s,""))))}`:e,c=[r("1",t,"template",t?v("bot.py is ready (~/.icoa/battleai/bot.py)","bot.py 已就绪(~/.icoa/battleai/bot.py)","bot.py พร้อมแล้ว (~/.icoa/battleai/bot.py)"):v("get the 15-knob starter (pro: template code)","拿 15 个旋钮的新手模板(高手: template code)","รับเทมเพลต 15 knobs (pro: template code)")),r("2",!1,"knobs · set",v("see the knobs; set WOMBATS 6 changes one — no code","看旋钮;set WOMBATS 6 改一个,不用写代码","ดู knobs; set WOMBATS 6 เปลี่ยนทีละตัว"),!0),` ${chalk.gray(v("✍ pro:","✍ 高手:","✍ pro:"))} ${chalk.bold.green("edit")} ${chalk.gray(v("opens the file — rewrite act(u) below the knobs","打开文件,旋钮下面的 act(u) 随便重写","เปิดไฟล์ แล้วเขียน act(u) ใต้ knobs ใหม่ได้เลย"))}`,r("3",!1,"run",v("one local test game — does the bot run? (optional)","本地试打一场,看 bot 跑不跑得起来(可跳过)","ทดลองในเครื่อง 1 เกม ดูว่า bot รันได้ไหม (ข้ามได้)"),!0),r("4",a,"up",a?v(`uploaded, now v${e?.my_versions.length} (edit + up again = new version)`,`已上传到 v${e?.my_versions.length}(改完再 up = 新版本)`,`อัปโหลดแล้ว v${e?.my_versions.length} (แก้แล้ว up อีกครั้ง = เวอร์ชันใหม่)`):v("upload the bot → v1 (tagged 🔧 knobs / ✍ code)","上传 bot → v1(自动标 🔧 新手 / ✍ 高手)","อัปโหลด bot → v1 (ติดป้าย 🔧 / ✍ ให้เอง)")),r("5",n,f()?"vs <昵称>":"vs <nick>",n?v("you played today — go again","今天打过了 —— 再来一场","วันนี้คุณแข่งไปแล้ว — ลองอีกสักแมตช์"):v("challenge someone: 3 maps decide","挑战一个人:3 张图定胜负","ท้าแข่งกับใครสักคน: ตัดสินกันด้วย 3 แผนที่")),r("6",!1,"replay 3",v("game 3 of your last match · replay <#> <game>: any","最近一场第 3 局 · replay <场号> <局>: 任一场","เกมที่ 3 ล่าสุด · replay <#> <เกม>: นัดใดก็ได้"),!0),r("7",!1,v("Enter","回车","Enter"),v("today's table · log matches · card back to the card","今日战绩表 · log 对局 · card 回卡片","ตารางคะแนนวันนี้ · log แมตช์ · card กลับไปที่การ์ด"),!0)],g=` ${v("How to play","怎么玩","วิธีเล่น")} · ${e?.room??"room"} `;console.log(),console.log(chalk.cyan(` ╭─${chalk.bold.white(g)}${"─".repeat(Math.max(0,70-_(g)-1))}${l?"╮":"─"}`));for(const e of c)console.log(`${chalk.cyan(" │")}${i(e)}${l?chalk.cyan("│"):""}`);console.log(chalk.cyan(` ╰${"─".repeat(70)}${l?"╯":"─"}`));const p=t?a?n?"":v("vs <nick>","vs <昵称>","vs <ชื่อเล่น>"):"up":"template";p&&console.log(chalk.gray(v(" ▸ next: "," ▸ 下一步敲: "," ▸ ขั้นต่อไป พิมพ์: "))+chalk.bold.green(p))}function M(e){const o=e=>chalk.bold.green(e),t=e=>chalk.gray(e),a=e=>chalk.bold.white(e),n=w(),r="zh"===n?[a(` BattleAI PvP 房间 · 怎么玩(房号 ${e})`),"",a(" 进房 / 开房"),` ${o("room new 名字")} ${t("开一个房 → 起昵称 → 得到 4 个字母的房号,发给朋友")}`,` ${o("room KZE6")} ${t("进朋友的房(昵称只问一次)")}`,` ${o("room open")} ${t("公共房,谁都能进;战绩表每天清零")}`,"",a(" 房里(提示符 icoa room XXXX>)—— 进房的面板会把做过的步骤打勾"),` ${o("template")} ${t("把 15 个旋钮的新手模板放到 ~/.icoa/battleai/bot.py(高手: template code = 空白代码模板)")}`,` ${o("knobs")} ${t("列出 15 个旋钮和含义")}`,` ${o("set WOMBATS 6")} ${t("改一个旋钮,不写代码(新手玩法)")}`,` ${o("edit")} ${t("用 vi 打开 bot.py,旋钮下面的 act(u) 随便重写(高手玩法;i 输入 · Esc · :wq 存盘)")}`,` ${o("run")} ${t("本地试打一场,只看 bot 跑不跑得起来(可跳过,需要 python setup)")}`,` ${o("up")} ${t("上传 bot → v1、v2、v3 …(每次上传 = 新版本;自动标 🔧 旋钮 / ✍ 代码)")}`,` ${o("vs <昵称>")} ${t("挑战一个人:3 张图各 1 局(地图对称,换席位结果一样),5–30 秒出结果表")}`,` ${o("vs <昵称>")} ${t("只能挑战对方的最新版本(旧版本不能挑战,防刷分)")}`,"",a(" 我以前的版本(旋钮设置 / 代码都在服务器上)"),` ${o("bots")} ${t("列出你上传过的所有版本(这个房间 + 其他房间 + 杯赛)")}`,` ${o("show 12")} ${t("看第 12 版:旋钮版显示旋钮值,代码版显示代码;show 12 code = 完整代码")}`,` ${o("get 12")} ${t("把第 12 版存成一个文件(bot.py 不动)")}`,` ${o("restore 12")} ${t("把第 12 版放回 bot.py(原来的留作 bot.py.bak),再 up")}`,"",a(" 看回放 —— 两个数字:场号 + 局号"),` ${o("log")} ${t("① 列出今日对局,每行最前面的 #12 就是场号;带 🎬 的才有回放")}`,` ${o("history")} ${t(" 同上,但列出所有天")}`,` ${o("replay 12 3")} ${t("② 看第 12 场的第 3 局(每场 3 局,局号 1–3;别人打的也能看)")}`,` ${o("replay 12")} ${t(" 只写场号 = 那场的第 1 局")}`,` ${o("replay 3")} ${t(" 刚打完不用场号:最近一场的第 3 局")}`,` ${o("replay")} ${t(" 最近一场你输掉的那局")}`,t(" ③ 播放时:空格 暂停 · ←→ 单步 · ↑↓ 调速 · q 退出回房间"),t(" 例:log 里有「#387 … 2-1 🎬」→ replay 387 1 … replay 387 3 逐局看"),"",a(" 战绩(公平规则)"),` ${o("回车")} ${t("今日战绩表:先比今天赢过几个不同的人,再比胜率,再比胜场")}`,t(" · 同一对 bot 版本每天只计一次分;再打照样能打、能看回放,但标「不计分」。任何一方上传新版本 = 新的一对,重新计分。"),t(" · 当天的地图是固定的:同一对版本再打,结果一模一样(重赌运气没用)。"),t(" · 同一台电脑上的两个账号不能互相挑战 —— PvP 要两个不同的人。"),` ${o("help")} ${t("再看步骤面板")} ${o("guide")} ${t("再看这份说明")} ${o("card")} ${t("回卡片")}`,"",t(" 规则一句话:拆掉对方的家就赢;打满 200 回合时,兵力价值(活着的兵,wombat 和家不算)高的一方赢,相差不到 5% 平局。每 30 秒只能发起一场。"),t(" 看到「判分机暂时不可用」就等一分钟再 vs。")]:"th"===n?[a(` ห้อง PvP ของ BattleAI · วิธีเล่น (ห้อง ${e})`),"",a(" เปิดห้องหรือเข้าห้อง"),` ${o("room new Mock")} ${t("เปิดห้องใหม่ → ตั้งชื่อเล่น → ได้รหัสห้อง 4 ตัวอักษร → ส่งให้เพื่อน")}`,` ${o("room KZE6")} ${t("เข้าห้องของเพื่อน (ตั้งชื่อเล่นครั้งเดียว)")}`,` ${o("room open")} ${t("ห้องสาธารณะ ใครก็เข้าได้ ตารางคะแนนเริ่มใหม่ทุกวัน")}`,"",a(" ในห้อง (prompt icoa room XXXX>) — แผงตอนเข้าห้องจะติ๊กขั้นตอนที่คุณทำแล้ว"),` ${o("template")} ${t("วางเทมเพลตเริ่มต้น 15 knobs ไว้ที่ ~/.icoa/battleai/bot.py (pro: template code = เทมเพลตโค้ดเปล่า)")}`,` ${o("knobs")} ${t("แสดง knobs ทั้ง 15 ตัวพร้อมความหมาย")}`,` ${o("set WOMBATS 6")} ${t("เปลี่ยน knob ทีละตัว ไม่ต้องเขียนโค้ด (แบบมือใหม่)")}`,` ${o("edit")} ${t("เปิด bot.py ด้วย vi แล้วเขียน act(u) ใต้ knobs ใหม่ (แบบ pro; i = พิมพ์ · Esc · :wq = บันทึก)")}`,` ${o("run")} ${t("ทดลองเล่นในเครื่อง 1 เกม แค่ดูว่า bot รันได้ (ข้ามได้ ต้องมี python setup)")}`,` ${o("up")} ${t("อัปโหลด bot → v1, v2, v3 … (อัปโหลดแต่ละครั้ง = เวอร์ชันใหม่; ติดป้าย 🔧 knobs หรือ ✍ code)")}`,` ${o("vs <nick>")} ${t("ท้าแข่ง: แผนที่ละ 1 เกม รวม 3 แผนที่ (แผนที่สมมาตร สลับที่นั่งผลเหมือนเดิม) รู้ผลใน 5–30 วินาที")}`,` ${o("vs <nick> v1")} ${t("แข่งกับ bot เวอร์ชันเก่าของอีกฝ่าย")}`,"",a(" เวอร์ชันเก่าของฉัน (knobs / โค้ดเก็บไว้บนเซิร์ฟเวอร์)"),` ${o("bots")} ${t("ทุกเวอร์ชันที่คุณอัปโหลด (ห้องนี้ + ห้องอื่น + ถ้วย)")}`,` ${o("show 12")} ${t("ดูเวอร์ชัน 12: knobs หรือโค้ด; show 12 code = ทั้งไฟล์")}`,` ${o("get 12")} ${t("บันทึกเวอร์ชัน 12 เป็นไฟล์ (bot.py ไม่เปลี่ยน)")}`,` ${o("restore 12")} ${t("ใส่เวอร์ชัน 12 กลับเข้า bot.py (ไฟล์เดิมเป็น bot.py.bak) แล้ว up")}`,"",a(" ดูรีเพลย์ — ใช้ตัวเลขสองตัว: เลขแมตช์ + เลขเกม"),` ${o("log")} ${t("① แมตช์วันนี้ เลข #12 ต้นบรรทัดคือเลขแมตช์; 🎬 = มีรีเพลย์")}`,` ${o("history")} ${t(" เหมือนกัน แต่แสดงทุกวัน")}`,` ${o("replay 12 3")} ${t("② แมตช์ #12 เกมที่ 3 (แมตช์ละ 3 เกม: 1–3; ดูของคนอื่นได้ด้วย)")}`,` ${o("replay 12")} ${t(" ใส่แค่เลขแมตช์ = เกมที่ 1 ของแมตช์นั้น")}`,` ${o("replay 3")} ${t(" เพิ่งแข่งเสร็จ? ไม่ต้องใส่เลขแมตช์: เกมที่ 3 ของแมตช์ล่าสุด")}`,` ${o("replay")} ${t(" เกมที่คุณแพ้ในแมตช์ล่าสุด")}`,t(" ③ ระหว่างเล่น: space = หยุด · ← → = ทีละขั้น · ↑ ↓ = ความเร็ว · q = กลับห้อง"),t(' ตัวอย่าง: log แสดง "#387 … 2-1 🎬" → replay 387 1 … replay 387 3'),"",a(" ตารางคะแนน (กติกาที่ยุติธรรม)"),` ${o("Enter")} ${t("ตารางวันนี้: ดูจำนวนคนที่คุณชนะได้ (ไม่นับคนซ้ำ) ก่อน แล้วจึงดูอัตราชนะ แล้วจำนวนครั้งที่ชนะ")}`,t(' · bot คู่เวอร์ชันเดิมนับคะแนนได้วันละครั้ง แข่งซ้ำได้และดูรีเพลย์ได้ แต่จะขึ้นว่า "ไม่นับคะแนน"'),t(" ฝ่ายใดฝ่ายหนึ่งอัปโหลดเวอร์ชันใหม่ = เป็นคู่ใหม่ นับคะแนนอีกครั้ง"),t(" · แผนที่ของแต่ละวันถูกกำหนดไว้แล้ว: คู่เวอร์ชันเดิมแข่งซ้ำ ผลจะเหมือนเดิมทุกครั้ง"),t(" · สองบัญชีบนเครื่องเดียวกันท้าแข่งกันไม่ได้ — PvP ต้องเป็นคนสองคน"),` ${o("help")} ${t("ดูแผงขั้นตอนอีกครั้ง")} ${o("guide")} ${t("ดูคู่มือนี้อีกครั้ง")} ${o("card")} ${t("กลับไปที่การ์ด")}`,"",t(" กติกาสั้น ๆ: ทำลาย warren ของอีกฝ่ายได้ก็ชนะ ถ้าครบ 200 เทิร์น ฝ่ายที่มีมูลค่ากองทัพสูงกว่าชนะ"),t(" (นับเฉพาะทหารที่ยังรอด ไม่นับ wombat และ warren) ต่างกันไม่ถึง 5% ถือว่าเสมอ ท้าแข่งได้ทุก 30 วินาที"),t(" ถ้าเห็นข้อความว่าเครื่องตัดสินไม่พร้อม รอสักหนึ่งนาทีแล้วลอง vs อีกครั้ง")]:[a(` BattleAI PvP room · how to play (room ${e})`),"",a(" Open or join a room"),` ${o("room new Mock")} ${t("open a room → pick a nickname → you get a 4-letter code → give it to the others")}`,` ${o("room KZE6")} ${t("join a friend's room (nickname once)")}`,` ${o("room open")} ${t("the public room, anyone can enter; its table resets every day")}`,"",a(" Inside the room (prompt icoa room XXXX>) — the panel on entry ticks the steps you did"),` ${o("template")} ${t("puts the 15-knob starter at ~/.icoa/battleai/bot.py (pro: template code = blank code template)")}`,` ${o("knobs")} ${t("list the 15 knobs with their meaning")}`,` ${o("set WOMBATS 6")} ${t("change one knob, no coding (rookie way)")}`,` ${o("edit")} ${t("open bot.py in vi and rewrite act(u) below the knobs (pro way; i = type, Esc, :wq = save)")}`,` ${o("run")} ${t("one local test game, just to see that the bot runs (optional, needs python setup)")}`,` ${o("up")} ${t("upload your bot → v1, v2, v3 … (each upload is a new version; tagged 🔧 knobs or ✍ code)")}`,` ${o("vs <nick>")} ${t("challenge someone: one game on each of the 3 maps (symmetric maps, swapping seats changes nothing), result in 5–30 s")}`,` ${o("vs <nick>")} ${t("only their CURRENT bot can be challenged (old versions can't — no score farming)")}`,"",a(" My old versions (knobs / code are kept on the server)"),` ${o("bots")} ${t("every version you uploaded (this room + other rooms + cups)")}`,` ${o("show 12")} ${t("see v12: its knobs, or its code; show 12 code = the whole file")}`,` ${o("get 12")} ${t("save v12 as a file (bot.py is not touched)")}`,` ${o("restore 12")} ${t("put v12 back into bot.py (the old one becomes bot.py.bak), then up")}`,"",a(" Watching replays — two numbers: match # + game #"),` ${o("log")} ${t("① today's matches; #12 at the line start = match number; 🎬 = replay kept")}`,` ${o("history")} ${t(" the same, for all days")}`,` ${o("replay 12 3")} ${t("② match #12, game 3 (3 games per match: 1–3; any player)")}`,` ${o("replay 12")} ${t(" match number only = game 1 of that match")}`,` ${o("replay 3")} ${t(" just played? skip the match #: game 3 of your last match")}`,` ${o("replay")} ${t(" the game you lost in your last match")}`,t(" ③ while it plays: space = pause · ← → = step · ↑ ↓ = speed · q = back to the room"),t(' e.g. log shows "#387 … 2-1 🎬" → replay 387 1 … replay 387 3'),"",a(" Table (fair rules)"),` ${o("Enter")} ${t("today's table: most different people beaten first, then win rate, then wins")}`,t(' · The same two bot versions count once a day. You can play them again and watch the replays, but it says "not counted".'),t(" Either side uploading a new version makes a new pair, which counts again."),t(" · The day's maps are fixed: the same two versions always get the same result, so re-rolling luck does nothing."),t(" · Two accounts on the same computer cannot challenge each other — PvP needs two different people."),` ${o("help")} ${t("the step panel again")} ${o("guide")} ${t("this sheet again")} ${o("card")} ${t("back to your card")}`,"",t(" Rule in one line: destroy their warren to win; at the 200-turn cap the higher army value wins (live soldiers; wombats and warrens do not count), within 5% is a draw. One challenge every 30 s."),t(' If you see "the judge is unavailable", wait a minute and try vs again.')];console.log();for(const e of r)console.log(e)}export async function runPvpRoom(e,t,n,i={}){const p=i.interactive??y,d=f(),w=n.trim();let _="",E="",A=!1;const B=/^(?:new|create|开房|建)(?:\s+(.*))?$/i.exec(w),x=/^(?:join|enter|进)\s+(\S+)$/i.exec(w);if(B?(A=!0,E=(B[1]??"").trim().slice(0,40)):x?_=x[1]:/^(?:open|public|公共)$/i.test(w)?_="OPEN":w&&(_=w),_=_.toUpperCase().replace(/[^A-Z0-9]/g,"").slice(0,8),!A&&!_){const o=await h("status",e);if(!o.ok||!o.data)return console.log(chalk.yellow(" "+V(o.code,o.message))),"back";if(console.log(),console.log(chalk.bold.white(v(" ⚔ PvP rooms"," ⚔ PvP 房间"," ⚔ ห้อง PvP"))+chalk.gray(v(" — your bot against real people, one game on each of 3 maps."," —— 和真人的 bot 对打,3 张图定胜负。"," — bot ของคุณสู้กับ bot ของคนจริง แผนที่ละ 1 เกม รวม 3 แผนที่"))),o.data.rooms.length)for(const e of o.data.rooms)console.log(` ${chalk.bold.cyan(P(e.room,6))} ${chalk.white(e.public?v("open room","公共房","ห้องสาธารณะ"):e.label||"")} ${chalk.gray(`· ${e.members} ${v("members","人","คน")} · ${v("you are","你是","คุณคือ")} ${e.nick}`)}`);else console.log(chalk.gray(v(" You are not in any room yet."," 你还没进过任何房间。"," คุณยังไม่ได้อยู่ในห้องใดเลย")));return console.log(chalk.gray(" ▸ ")+chalk.bold.green("room open")+chalk.gray(v(" the public room — anyone can enter, the table resets daily"," 公共房,谁都能进,战绩每天清零"," ห้องสาธารณะ — ใครก็เข้าได้ ตารางคะแนนเริ่มใหม่ทุกวัน"))),console.log(chalk.gray(" ▸ ")+chalk.bold.green("room <CODE>")+chalk.gray(v(" enter a friend's room (4-letter code)"," 进朋友开的房(4 个字母)"," เข้าห้องของเพื่อน (รหัส 4 ตัวอักษร)"))),console.log(chalk.gray(" ▸ ")+chalk.bold.green(v("room new [label]","room new [名字]","room new [ชื่อห้อง]"))+chalk.gray(v(" open a new room and hand out its code"," 开一个新房,把房号发给朋友"," เปิดห้องใหม่แล้วส่งรหัสให้เพื่อน"))),"back"}let L=null;if(A){const o=await W(t);if(null===o)return"back";const a=await h("create",e,{label:E,nick:o});if(!a.ok||!a.data)return console.log(chalk.yellow(" "+V(a.code,a.message))),"back";L=a.data,console.log(chalk.green(" ✓ ")+chalk.white(v("Room created — the code is ","房间开好了,房号 ","สร้างห้องแล้ว — รหัสห้องคือ "))+chalk.bold.cyan(L.room)+chalk.white(v(`. Friends type room ${L.room}`,`,告诉朋友敲 room ${L.room}`,` ให้เพื่อนพิมพ์ room ${L.room}`)))}else{const o=await h("status",e,{room:_});if(o.ok&&o.data)L=o.data;else{if("not_member"!==o.code)return console.log(chalk.yellow(" "+V(o.code,o.message))),"back";{const o=await h("join",e,{room:_,probe:!0}),a=o.data?.label||("OPEN"===_?v("Open room","公共房","ห้องสาธารณะ"):_);console.log(chalk.white(` ${v("Entering","进入","กำลังเข้าห้อง")} `)+chalk.bold.cyan(_)+chalk.gray(` ${a} · ${o.data?.members??"?"} ${v("members","人","คน")}`));for(let o=0;o<4&&!L;o++){const o=await W(t);if(null===o)return"back";const a=await h("join",e,{room:_,nick:o});a.ok&&a.data?L=a.data:console.log(chalk.yellow(" "+V(a.code,a.message)))}if(!L)return"back"}}}const U=L.room,D=chalk.bold.magenta(`icoa room ${U}> `);let K=L.recent.find(e=>e.mine&&e.replays)?.id??0;for(o(DEFAULT_PVP_BOT)||L.my_versions.length||M(U),F(L),console.log(chalk.gray(" ▸ ")+chalk.bold.green("guide")+chalk.gray(v(" the full command sheet"," 完整命令说明"," คู่มือคำสั่งฉบับเต็ม"))),N(L),T(U);;){const n=await t(D);if(null===n)return"back";const i=n.trim(),y=i.toLowerCase();if(k.has(y))return"back";if("menu"===y||"home"===y)return"menu";if(""===y||"who"===y||"board"===y||"table"===y||"r"===y||"refresh"===y){const o=await h("status",e,{room:U});o.ok&&o.data?N(o.data):console.log(chalk.yellow(" "+V(o.code,o.message)));continue}if("guide"===y||"howto"===y||"how"===y||"说明"===y||"教程"===y||"คู่มือ"===y){M(U),T(U);continue}if("help"===y||"?"===y){const o=await h("status",e,{room:U});F(o.ok&&o.data?o.data:null),T(U);continue}if("log"===y||"matches"===y||"history"===y){const o=await h("matches",e,{room:U,limit:20,all:"history"===y});if(o.ok&&o.data){o.data.matches.length||console.log(chalk.gray(v(" No matches today yet."," 今天还没有对局。"," วันนี้ยังไม่มีแมตช์")));for(const e of o.data.matches)console.log(" "+O(e));o.data.matches.length&&console.log(chalk.gray(v(" 🎬 = replays kept: replay <match#> <game#>, e.g. replay 12 3; matches without 🎬 were played before replays were stored."," 🎬 = 有回放:replay <场号> <局号>,例如 replay 12 3;没有 🎬 的是旧对局,回放没存。"," 🎬 = มีรีเพลย์: replay <เลขแมตช์> <เลขเกม> เช่น replay 12 3; แมตช์ที่ไม่มี 🎬 แข่งก่อนที่จะเริ่มเก็บรีเพลย์"))),o.data.matches.some(e=>0===e.counted)&&console.log(chalk.gray(v(" not counted = the same two bot versions already played that day; up a new version to count again."," 不计分 = 这一对 bot 版本当天已经打过;上传新版本才重新计分。"," ไม่นับคะแนน = bot คู่เวอร์ชันนี้แข่งกันไปแล้ววันนั้น; up เวอร์ชันใหม่เพื่อให้นับคะแนนอีกครั้ง")))}else console.log(chalk.yellow(" "+V(o.code,o.message)));continue}const w=/^(?:replay|回放)(?:\s+(last|\d+))?(?:\s+(\d+))?$/i.exec(i);if(w){const t=s(r(),".icoa","battleai","last.mobreplay"),a=()=>console.log(chalk.yellow(v(" The replay is saved here, but the viewer needs Python 3.12 and the arena engine: run python setup, open battle once (it fetches the engine), then replay again."," 回放已存在本机,但播放器需要 Python 3.12 和竞技场引擎:先 python setup,再进一次 battle(它会下载引擎),回来再敲 replay。"," บันทึกรีเพลย์ไว้ในเครื่องแล้ว แต่ตัวเล่นต้องใช้ Python 3.12 และ arena engine: รัน python setup แล้วเปิด battle หนึ่งครั้ง (จะดาวน์โหลด engine ให้) จากนั้นพิมพ์ replay อีกครั้ง")));let n=0,i=0;const c=w[1]&&"last"!==w[1].toLowerCase()?Number(w[1]):0,y=w[2]?Number(w[2]):0;if(c&&y)n=c,i=y;else if(c>=1&&c<=6){if(n=K,i=c,!n){console.log(chalk.gray(v(" No match to replay yet — play one (vs), or replay <match#> <game> for a 🎬 match from log."," 还没有可回看的对局 —— 先 vs 打一场,或 replay <场号> <局> 指定 log 里带 🎬 的一场。"," ยังไม่มีแมตช์ให้ดูรีเพลย์ — แข่งก่อนหนึ่งแมตช์ (vs) หรือ replay <เลขแมตช์> <เกม> สำหรับแมตช์ที่มี 🎬 ใน log")));continue}}else c>6&&(n=c,i=1);if(n&&i){const o=await h("replay",e,{room:U,match_id:n,game:i},3e4);if(!o.ok||!o.data){console.log(chalk.yellow(" "+V(o.code,o.message)));continue}const t=u(o.data.seat_a,o.data.a,o.data.b),r="a"===o.data.winner?o.data.a:"b"===o.data.winner?o.data.b:null,s=e=>t?t.blue===e?m(0):m(1):"",c=e=>chalk.bold.white(e)+s(e);if(console.log(chalk.gray(` #${n} ${v(`game ${i}`,`第 ${i} 局`,`เกมที่ ${i}`)} · ${o.data.map} · `)+(t?`${m(0).trim()} ${chalk.bold.white(t.blue)}${chalk.gray(" vs ")}${m(1).trim()} ${chalk.bold.white(t.red)}`:`${c(o.data.a)}${chalk.gray(" vs ")}${c(o.data.b)}`)+chalk.gray(` · ${v("winner","胜者","ผู้ชนะ")}: `)+(r?c(r):chalk.gray(v("draw","平局","เสมอ")))),!g(o.data.replay,t)){console.log(chalk.yellow(v(" Could not save the replay."," 回放存不下来。"," บันทึกรีเพลย์ไม่ได้")));continue}await l(p)||a();continue}if(!o(t)){console.log(chalk.gray(v(" No replay yet — play a match (vs); then replay 3 shows game 3 and replay shows the game you lost."," 还没有回放 —— 先 vs 打一场;打完 replay 3 看第 3 局,replay 看你输的那局。"," ยังไม่มีรีเพลย์ — แข่งหนึ่งแมตช์ (vs) ก่อน แล้ว replay 3 จะแสดงเกมที่ 3 และ replay จะแสดงเกมที่คุณแพ้")));continue}await l(p)||a();continue}if(await myBotsCommand(i,e,U))continue;if("knobs"===y||"knob"===y||"旋钮"===y||"set"===y){const e=j();null===e?F(null):printKnobs(e);continue}const f=/^(?:set|改)\s+(.+)$/i.exec(i);if(f){const e=j();null===e?F(null):setKnob(e,f[1]);continue}const _=/^(?:template|模板)(?:\s+(knobs?|code|新手|高手))?(?:\s+(force|覆盖))?$/i.exec(i);if(_){const e=/^(?:code|高手)$/i.test(_[1]??"")?"code":"knobs";await writeTemplate(e,!!_[2],d);continue}if("edit"===y||"vi"===y||"编辑"===y){if(!o(DEFAULT_PVP_BOT)){F(null);continue}console.log(chalk.gray(v(" vi survival: i = edit · Esc = stop editing · :wq = save and leave · :q! = discard"," vi 三键: i 进入编辑 · Esc 退出编辑 · :wq 存盘离开 · :q! 放弃"," vi เบื้องต้น: i = เริ่มแก้ไข · Esc = หยุดแก้ไข · :wq = บันทึกแล้วออก · :q! = ไม่บันทึก"))),await p("vi",[...b,DEFAULT_PVP_BOT]);continue}if("run"===y||"test"===y||"play"===y||"试打"===y){if(!o(DEFAULT_PVP_BOT)){F(null);continue}if(!$().ok){console.log(chalk.gray(v(" No Python 3.12 here — python setup first; up / vs still work without it (the judge is server-side)."," 本机没有 Python 3.12,先 python setup;没有它也能 up / vs(判分在服务器)。"," เครื่องนี้ไม่มี Python 3.12 — รัน python setup ก่อน; ถึงไม่มีก็ยังใช้ up / vs ได้ (การตัดสินทำบนเซิร์ฟเวอร์)")));continue}console.log(chalk.gray(v(" One local game (the card-12 sparring bot) to see that the bot runs…"," 本地打一场(对卡 12 的陪练),看看 bot 跑不跑得起来…"," ทดลองเล่นในเครื่อง 1 เกม (กับ bot คู่ซ้อมของการ์ด 12) เพื่อดูว่า bot รันได้…"))),await c(DEFAULT_PVP_BOT,12,0,void 0,p);continue}const P=/^(?:up|upload|submit|上传)(?:\s+(.+))?$/i.exec(i);if(P){const t=(P[1]??"").trim()||DEFAULT_PVP_BOT;if(!o(t)){console.log(chalk.yellow(` ${v("Not found","找不到","ไม่พบไฟล์")}: ${t}`)),F(null);continue}let n="";try{n=a(t,"utf8")}catch{console.log(chalk.yellow(` ${v("Could not read","读不了","อ่านไฟล์ไม่ได้")}: ${t}`));continue}const r=await C(n),s=await h("upload",e,{room:U,code:n,group:r},3e4);if(!s.ok||!s.data){console.log(chalk.yellow(" "+V(s.code,s.message)));continue}s.data.unchanged?console.log(chalk.gray(v(` Identical to v${s.data.version} — nothing new.`,` 和 v${s.data.version} 一字不差,没有新版本。`,` เหมือนกับ v${s.data.version} ทุกตัวอักษร — ไม่มีเวอร์ชันใหม่`))):console.log(chalk.green(" ✓ ")+chalk.white(v(`Uploaded as v${s.data.version}`,`已上传为 v${s.data.version}`,`อัปโหลดเป็น v${s.data.version} แล้ว`))+chalk.gray(` (${t})`)+(r?chalk.gray("rookie"===r?v(" · 🔧 knobs only (rookie)"," · 🔧 新手组(只动了旋钮)"," · 🔧 แก้เฉพาะ knobs (มือใหม่)"):v(" · ✍ custom code (pro)"," · ✍ 高手组(改了代码)"," · ✍ เขียนโค้ดเอง (pro)")):""));continue}const E=/^(?:vs|challenge|fight|挑战|打)\s+(\S+)(?:\s+v?(\d+))?$/i.exec(i);if(E){const o=E[2]?Number(E[2]):void 0;console.log(chalk.gray(v(" ⚖ The judge is playing the 3 maps — usually 5–20 s, up to 3 min…"," ⚖ 判分机在打 3 张图,通常 5–20 秒,最多 3 分钟…"," ⚖ เครื่องตัดสินกำลังเล่น 3 แผนที่ — ปกติ 5–20 วินาที นานสุด 3 นาที…")));const t=await h("challenge",e,{room:U,nick:E[1],version:o},2e5);if(!t.ok||!t.data){console.log(chalk.yellow(" "+V(t.code,t.message)));continue}t.data.replays&&(K=t.data.match_id),S(t.data),N(t.data.status);continue}/^(?:vs|challenge|挑战|打)$/i.test(i)?console.log(chalk.gray(v(" Usage: vs <nick> or vs <nick> v2 (their version 2)"," 用法: vs <昵称> 或 vs <昵称> v2(打对方的第 2 版)"," วิธีใช้: vs <ชื่อเล่น> หรือ vs <ชื่อเล่น> v2 (เวอร์ชัน 2 ของอีกฝ่าย)"))):(console.log(chalk.gray(v(` Unknown: "${i}".`,` 不认识「${i}」。`,` ไม่รู้จักคำสั่ง "${i}"`))),T(U))}}async function W(e){for(let o=0;o<4;o++){const o=await e(chalk.bold.cyan(v(" Your nickname (2–12 letters/digits, not your real name; back to cancel): "," 你的昵称(2–12 个字母/数字,别用真名;back 取消): "," ชื่อเล่นของคุณ (ตัวอักษร/ตัวเลข 2–12 ตัว ไม่ใช่ชื่อจริง; back เพื่อยกเลิก): ")));if(null===o||k.has(o.toLowerCase()))return null;if(/^[A-Za-z0-9_\-一-鿿]{2,12}$/.test(o))return o;console.log(chalk.gray(v(" 2–12 letters, digits, _ or -; no spaces."," 2–12 个字母、数字、_ 或 -,不能有空格。"," ใช้ตัวอักษรภาษาอังกฤษ ตัวเลข _ หรือ - ได้ 2–12 ตัว ห้ามเว้นวรรค")))}return null}function V(e,o){switch(e){case"wrong_course":return v("PvP rooms are for BattleAI (battleai-48) tokens.","PvP 房间只对 BattleAI(battleai-48)token 开放。","ห้อง PvP ใช้ได้กับ token ของ BattleAI (battleai-48) เท่านั้น");case"demo_not_supported":return v("Demo tokens cannot enter PvP rooms.","demo token 进不了 PvP 房间。","token ทดลองเข้าห้อง PvP ไม่ได้");case"no_room":return v("No room with that code — check the four letters.","没有这个房号 —— 检查一下 4 个字母。","ไม่มีห้องรหัสนี้ — ตรวจสอบตัวอักษรทั้ง 4 ตัวอีกครั้ง");case"nick_taken":return v("That nickname is taken in this room — pick another.","这个昵称在房里已经有人用了,换一个。","ชื่อเล่นนี้มีคนใช้แล้วในห้องนี้ — กรุณาเลือกชื่ออื่น");case"bad_nick":return v("Nickname: 2–12 letters/digits, no spaces.","昵称要 2–12 个字母/数字,不能有空格。","ชื่อเล่น: ตัวอักษร/ตัวเลข 2–12 ตัว ห้ามเว้นวรรค");case"no_bot":return v("Upload your bot first: up","先 up 上传你的 bot。","อัปโหลด bot ของคุณก่อน: up");case"old_version":return v(`Only the current bot can be challenged${o?.match(/v\d+/)?` (now ${o.match(/v\d+/)?.[0]})`:""} — type vs <nick> without a version.`,`只能挑战对方的最新版本${o?.match(/v\d+/)?`(现在是 ${o.match(/v\d+/)?.[0]})`:""} —— 敲 vs <昵称>,不要带版本号。`,`ท้าได้เฉพาะ bot เวอร์ชันล่าสุด${o?.match(/v\d+/)?` (ตอนนี้ ${o.match(/v\d+/)?.[0]})`:""} — พิมพ์ vs <ชื่อ> โดยไม่ใส่เวอร์ชัน`);case"opp_no_bot":return o||v("They have no bot yet.","对方还没上传 bot。","อีกฝ่ายยังไม่มี bot");case"no_such_nick":return v("Nobody by that name here — press Enter for the table.","房里没有这个昵称 —— 回车看名单。","ไม่มีคนชื่อนี้ในห้อง — กด Enter เพื่อดูตาราง");case"self":return v("You cannot challenge yourself.","不能挑战自己。","คุณท้าแข่งกับตัวเองไม่ได้");case"same_device":return v("These two accounts are on the same device — PvP needs two different people.","这两个账号在同一台设备上 —— PvP 需要两个不同的人。","สองบัญชีนี้อยู่บนเครื่องเดียวกัน — PvP ต้องเป็นคนสองคนที่ต่างกัน");case"cooldown":return v("One challenge every 30 seconds.","每 30 秒只能发起一场。","ท้าแข่งได้ทุก 30 วินาที กรุณารอสักครู่");case"no_match":return v("No match with that number in this room — see log for the #.","这个房间里没有这个场号 —— log 看场号(#)。","ไม่มีแมตช์เลขนี้ในห้องนี้ — ดูเลข # ได้จาก log");case"no_replay":return v("No replay was kept for that match (played before replays were stored).","这一场没有存回放(是回放功能上线前打的)。","แมตช์นั้นไม่มีรีเพลย์ (แข่งก่อนที่จะเริ่มเก็บรีเพลย์)");case"bad_game":return v("The game number is 1 to 6.","局号是 1 到 6。","เลขเกมคือ 1 ถึง 6");case"no_act":return v("That file has no act(u) — is it your bot.py?","这个文件里没有 act(u) —— 确定是你的 bot.py?","ไฟล์นี้ไม่มี act(u) — ใช่ bot.py ของคุณหรือเปล่า?");case"judge_unreachable":case"judge_timeout":case"judge_rejected":case"judge_not_configured":return v("The judge is unavailable right now — try again in a minute.","判分机暂时不可用,一分钟后再试。","ตอนนี้เครื่องตัดสินยังไม่พร้อม — กรุณาลองใหม่ในอีกหนึ่งนาที");default:return o||v("Could not reach the server.","连不上服务器。","เชื่อมต่อเซิร์ฟเวอร์ไม่ได้")}}
|