加一些api
This commit is contained in:
parent
6c321bc333
commit
884c5a67fd
@ -138,6 +138,54 @@ async function run_any(names: string, round: number): Promise<FightResult | WinR
|
|||||||
return await md5_module.run_any(names, round);
|
return await md5_module.run_any(names, round);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const out_limit: number = 1000;
|
||||||
|
|
||||||
|
async function wrap_any(names: string, round: number): Promise<string> {
|
||||||
|
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 {
|
export {
|
||||||
FightResult,
|
FightResult,
|
||||||
@ -153,4 +201,5 @@ export {
|
|||||||
score,
|
score,
|
||||||
score_callback,
|
score_callback,
|
||||||
run_any,
|
run_any,
|
||||||
|
wrap_any,
|
||||||
};
|
};
|
||||||
|
@ -26,9 +26,9 @@ let assets_data = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let run_env = {
|
let run_env = {
|
||||||
from_code: (typeof window == "undefined"),
|
from_code: (typeof window === "undefined"),
|
||||||
is_node: (typeof Bun == "undefined"),
|
is_node: (typeof Bun === "undefined"),
|
||||||
is_bun: (typeof Bun != "undefined"),
|
is_bun: (typeof Bun !== "undefined"),
|
||||||
version: _version_,
|
version: _version_,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -196,16 +196,16 @@ if (run_env.from_code) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
global.document = {
|
global.document = {
|
||||||
createElement: function (tag) {
|
createElement: (tag) => {
|
||||||
// return fake_element.fake_init(tag);
|
// return fake_element.fake_init(tag);
|
||||||
return new fake_element(tag);
|
return new fake_element(tag);
|
||||||
},
|
},
|
||||||
createTextNode: function (data) {
|
createTextNode: (data) => {
|
||||||
let node = new fake_element("text");
|
let node = new fake_element("text");
|
||||||
node.innerHTML = data;
|
node.innerHTML = data;
|
||||||
return node;
|
return node;
|
||||||
},
|
},
|
||||||
querySelector: function (tag) {
|
querySelector: (tag) => {
|
||||||
// 搜索一下有没有这个元素
|
// 搜索一下有没有这个元素
|
||||||
logger.debug("querySelector", tag);
|
logger.debug("querySelector", tag);
|
||||||
for (let i = 0; i < stored_elements.length; i++) {
|
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))
|
outer_display.push(T.RunUpdate_init(benchmarking, null, null, C.JsInt.ag(this_.ch, 100), null, 0, 0, 0))
|
||||||
if (this_.ch >= this_.d) {
|
if (this_.ch >= this_.d) {
|
||||||
// 阶段目标场数达到
|
// 阶段目标场数达到
|
||||||
logger.info("分数: " + (this_.Q * 10000 / this_.ch))
|
logger.debug("分数: " + (this_.Q * 10000 / this_.ch))
|
||||||
this_.eS()
|
this_.eS()
|
||||||
}
|
}
|
||||||
result = new T.aq(outer_display, update_list)
|
result = new T.aq(outer_display, update_list)
|
||||||
|
Loading…
Reference in New Issue
Block a user