From cf5742a4dfc96a124508511f34df84c8dcbb6482 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Fri, 10 May 2024 19:23:55 +0800 Subject: [PATCH] ruaaa --- branch/latest/{md5-api.mts => md5-api.ts} | 12 +++++++--- branch/latest/md5.js | 28 +++++++++++++++++++++-- 2 files changed, 35 insertions(+), 5 deletions(-) rename branch/latest/{md5-api.mts => md5-api.ts} (91%) diff --git a/branch/latest/md5-api.mts b/branch/latest/md5-api.ts similarity index 91% rename from branch/latest/md5-api.mts rename to branch/latest/md5-api.ts index 8f2a478..c7c94ca 100644 --- a/branch/latest/md5-api.mts +++ b/branch/latest/md5-api.ts @@ -23,7 +23,7 @@ type WinRate = { * 胜率的数据结构 */ type WinRateResult = { - souce: number; + win_count: number; raw_data: WinRate[]; }; @@ -63,7 +63,7 @@ type ScoreCallback = (run_round: number, score: number) => boolean; async function fight(names: string): Promise { // 检查一下输入是否合法 // 比如里面有没有 !test! - if (names.startsWith("!test!")) { + if (names.indexOf("!test!") !== -1) { throw new Error("你怎么在对战输入里加 !test!(恼)\n${names}"); } return await md5_module.fight(names); @@ -75,7 +75,7 @@ async function fight(names: string): Promise { * @returns */ function test_check(names: string): boolean { - const have_test = names.startsWith("!test!"); + const have_test = names.trim().startsWith("!test!"); return have_test; } @@ -134,6 +134,11 @@ async function score_callback( return await md5_module.score_callback(names, callback); } +async function run_any(names: string, round: number): Promise { + return await md5_module.run_any(names, round); +} + + export { FightResult, WinRate, @@ -147,4 +152,5 @@ export { win_rate_callback, score, score_callback, + run_any, }; diff --git a/branch/latest/md5.js b/branch/latest/md5.js index e69a501..ddac208 100644 --- a/branch/latest/md5.js +++ b/branch/latest/md5.js @@ -21795,7 +21795,7 @@ const runner = { // 如果数据长度等于 round,说明数据已经全部返回 if (run_round >= target_round) { stop_bomb = true; - resolve({ score: win_count, raw_data: win_datas }); + resolve({ win_count: win_count, raw_data: win_datas }); } }); main(names); @@ -21811,7 +21811,7 @@ const runner = { let result = callback(run_round, win_count); if (!result) { stop_bomb = true; - resolve({ score: win_count, raw_data: win_datas }); + resolve({ win_count: win_count, raw_data: win_datas }); } }); main(names); @@ -21845,6 +21845,30 @@ const runner = { }); }); }, + run_any: (names, round) => { + return new Promise((resolve, reject) => { + let data = []; + // 三种情况都带上 + finish_trigger.on("done_fight", (data) => { + resolve(fmt_RunUpdate(data)); + }); + finish_trigger.on("win_rate", (run_round, win_count) => { + data.push({ round: run_round, win_count: win_count }); + if (run_round >= round) { + stop_bomb = true; + resolve({ win_count: win_count, raw_data: data }); + } + }); + finish_trigger.on("score_report", (run_round, score) => { + data.push({ round: run_round, score: score }); + if (run_round >= round) { + stop_bomb = true; + resolve({ score: score, raw_data: data }); + } + }); + main(names); + }) + }, }; if (run_env.from_code) {