From 060f96032045cf57523c6a331d369ce4d791f827 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Fri, 10 May 2024 19:32:51 +0800 Subject: [PATCH] =?UTF-8?q?api=20=E5=A4=A7=E6=9B=B4=E6=96=B0=EF=BC=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ica-rs/plugins/md5/md5-api.ts | 73 ++++++++++++++++++++++++++--------- ica-rs/plugins/md5/md5.js | 8 ++-- 2 files changed, 59 insertions(+), 22 deletions(-) diff --git a/ica-rs/plugins/md5/md5-api.ts b/ica-rs/plugins/md5/md5-api.ts index 6e3df0a..cb2d9f9 100644 --- a/ica-rs/plugins/md5/md5-api.ts +++ b/ica-rs/plugins/md5/md5-api.ts @@ -24,7 +24,7 @@ type WinRate = { * 胜率的数据结构 */ type WinRateResult = { - souce: number; + win_count: number; raw_data: WinRate[]; }; @@ -46,7 +46,7 @@ type Score = { * 分数的数据结构 */ type ScoreResult = { - source: number; + score: number; raw_data: Score[]; }; @@ -76,7 +76,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; } @@ -135,20 +135,56 @@ async function score_callback( return await md5_module.score_callback(names, callback); } -// export { -// type FightResult, -// type WinRate, -// type WinRateResult, -// type WinRateCallback, -// type Score, -// type ScoreResult, -// type ScoreCallback, -// fight, -// win_rate, -// win_rate_callback, -// score, -// score_callback, -// }; +async function run_any(names: string, round: number): Promise { + return await md5_module.run_any(names, round); +} + +async function wrap_any(names: string, round: number): Promise { + const result = await run_any(names, round); + if ('message' in result) { + // 对战结果 + return `赢家:|${result.source_plr}|`; + } else if ('win_count' in result) { + // 胜率结果 + const win_rate = result.win_count / round; + let win_rate_str = win_rate.toFixed(4); + let output_str = `最终胜率:|${win_rate_str}|(${round}轮)`; + // 每 500 轮, 输出一次 + if (round > 1000) { + // 把所有要找的数据拿出来 + let output_datas: WinRate[] = []; + result.raw_data.forEach((data, index) => { + if (index % 500 === 0) { + output_datas.push(data); + } + }); + output_datas.forEach((data, index) => { + const win_rate = data.win_count / data.round; + output_str += `\n${win_rate.toFixed(2)}%(${data.round})`; + }); + } + return output_str; + // } else if ('score' in result) { + } else { + // 分数结果其实还是个胜率, 不过需要 * 100 + const win_rate = (result.score / round * 100).toFixed(2); + let output_str = `分数:|${win_rate}%|(${round}轮)`; + if (round > 1000) { + // 把所有要找的数据拿出来 + let output_datas: Score[] = []; + result.raw_data.forEach((data, index) => { + if (index % 500 === 0) { + output_datas.push(data); + } + }); + output_datas.forEach((data, index) => { + const win_rate = (data.score / data.round * 100).toFixed(2); + output_str += `\n${win_rate}%(${data.round})`; + }); + } + return output_str; + } +} async function main() { // 从相对位置导入内容 @@ -157,8 +193,9 @@ async function main() { const names = fs.readFileSync(path.resolve(__dirname, "input.txt"), "utf-8"); // const result = await fight(names); - const result = await md5_module.run_any(names, 50000); + // const result = await md5_module.run_any(names, 50000); // console.log(`赢家:|${result.source_plr}|`); + const result = await wrap_any(names, 1000); console.log(result); } diff --git a/ica-rs/plugins/md5/md5.js b/ica-rs/plugins/md5/md5.js index 13662c6..ddac208 100644 --- a/ica-rs/plugins/md5/md5.js +++ b/ica-rs/plugins/md5/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); @@ -21856,7 +21856,7 @@ const runner = { data.push({ round: run_round, win_count: win_count }); if (run_round >= round) { stop_bomb = true; - resolve({ score: win_count, raw_data: data }); + resolve({ win_count: win_count, raw_data: data }); } }); finish_trigger.on("score_report", (run_round, score) => { @@ -21868,7 +21868,7 @@ const runner = { }); main(names); }) - } + }, }; if (run_env.from_code) {