From 884c5a67fdd66701a0976e0185b4f9278229c201 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Fri, 10 May 2024 23:42:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E4=B8=80=E4=BA=9Bapi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- branch/latest/md5-api.ts | 49 ++++++++++++++++++++++++++++++++++++++++ branch/latest/md5.js | 14 ++++++------ 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/branch/latest/md5-api.ts b/branch/latest/md5-api.ts index 4236be5..5b2a450 100644 --- a/branch/latest/md5-api.ts +++ b/branch/latest/md5-api.ts @@ -138,6 +138,54 @@ async function run_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 * 100 / round; + let win_rate_str = win_rate.toFixed(4); + let output_str = `最终胜率:|${win_rate_str}%|(${round}轮)`; + // 每 500 轮, 输出一次 + if (round > out_limit) { + // 把所有要找的数据拿出来 + let output_datas: WinRate[] = []; + result.raw_data.forEach((data, index) => { + if (data.round % out_limit === 0) { + output_datas.push(data); + } + }); + output_datas.forEach((data, index) => { + const win_rate = data.win_count * 100 / 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 * 10000 / round).toFixed(2); + let output_str = `分数:|${win_rate}|(${round}轮)`; + if (round > out_limit) { + // 把所有要找的数据拿出来 + let output_datas: Score[] = []; + result.raw_data.forEach((data, index) => { + if (data.round % out_limit === 0) { + output_datas.push(data); + } + }); + output_datas.forEach((data, index) => { + const win_rate = (data.score / data.round * 10000).toFixed(2); + output_str += `\n${win_rate}(${data.round})`; + }); + } + return output_str; + } +} export { FightResult, @@ -153,4 +201,5 @@ export { score, score_callback, run_any, + wrap_any, }; diff --git a/branch/latest/md5.js b/branch/latest/md5.js index 5bdf77d..ca06164 100644 --- a/branch/latest/md5.js +++ b/branch/latest/md5.js @@ -26,9 +26,9 @@ let assets_data = { }; let run_env = { - from_code: (typeof window == "undefined"), - is_node: (typeof Bun == "undefined"), - is_bun: (typeof Bun != "undefined"), + from_code: (typeof window === "undefined"), + is_node: (typeof Bun === "undefined"), + is_bun: (typeof Bun !== "undefined"), version: _version_, }; @@ -196,16 +196,16 @@ if (run_env.from_code) { } global.document = { - createElement: function (tag) { + createElement: (tag) => { // return fake_element.fake_init(tag); return new fake_element(tag); }, - createTextNode: function (data) { + createTextNode: (data) => { let node = new fake_element("text"); node.innerHTML = data; return node; }, - querySelector: function (tag) { + querySelector: (tag) => { // 搜索一下有没有这个元素 logger.debug("querySelector", tag); for (let i = 0; i < stored_elements.length; i++) { @@ -12863,7 +12863,7 @@ V.ProfileMain.prototype = { outer_display.push(T.RunUpdate_init(benchmarking, null, null, C.JsInt.ag(this_.ch, 100), null, 0, 0, 0)) if (this_.ch >= this_.d) { // 阶段目标场数达到 - logger.info("分数: " + (this_.Q * 10000 / this_.ch)) + logger.debug("分数: " + (this_.Q * 10000 / this_.ch)) this_.eS() } result = new T.aq(outer_display, update_list)