api 大更新(

This commit is contained in:
shenjack 2024-05-10 19:32:51 +08:00
parent a99467dfbf
commit 060f960320
Signed by: shenjack
GPG Key ID: 7B1134A979775551
2 changed files with 59 additions and 22 deletions

View File

@ -24,7 +24,7 @@ type WinRate = {
* *
*/ */
type WinRateResult = { type WinRateResult = {
souce: number; win_count: number;
raw_data: WinRate[]; raw_data: WinRate[];
}; };
@ -46,7 +46,7 @@ type Score = {
* *
*/ */
type ScoreResult = { type ScoreResult = {
source: number; score: number;
raw_data: Score[]; raw_data: Score[];
}; };
@ -76,7 +76,7 @@ async function fight(names: string): Promise<FightResult> {
* @returns * @returns
*/ */
function test_check(names: string): boolean { function test_check(names: string): boolean {
const have_test = names.startsWith("!test!"); const have_test = names.trim().startsWith("!test!");
return have_test; return have_test;
} }
@ -135,20 +135,56 @@ async function score_callback(
return await md5_module.score_callback(names, callback); return await md5_module.score_callback(names, callback);
} }
// export { async function run_any(names: string, round: number): Promise<FightResult | WinRateResult | ScoreResult> {
// type FightResult, return await md5_module.run_any(names, round);
// type WinRate, }
// type WinRateResult,
// type WinRateCallback, async function wrap_any(names: string, round: number): Promise<string> {
// type Score, const result = await run_any(names, round);
// type ScoreResult, if ('message' in result) {
// type ScoreCallback, // 对战结果
// fight, return `赢家:|${result.source_plr}|`;
// win_rate, } else if ('win_count' in result) {
// win_rate_callback, // 胜率结果
// score, const win_rate = result.win_count / round;
// score_callback, 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() { async function main() {
// 从相对位置导入内容 // 从相对位置导入内容
@ -157,8 +193,9 @@ async function main() {
const names = fs.readFileSync(path.resolve(__dirname, "input.txt"), "utf-8"); const names = fs.readFileSync(path.resolve(__dirname, "input.txt"), "utf-8");
// const result = await fight(names); // 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}|`); // console.log(`赢家:|${result.source_plr}|`);
const result = await wrap_any(names, 1000);
console.log(result); console.log(result);
} }

View File

@ -21795,7 +21795,7 @@ const runner = {
// 如果数据长度等于 round说明数据已经全部返回 // 如果数据长度等于 round说明数据已经全部返回
if (run_round >= target_round) { if (run_round >= target_round) {
stop_bomb = true; stop_bomb = true;
resolve({ score: win_count, raw_data: win_datas }); resolve({ win_count: win_count, raw_data: win_datas });
} }
}); });
main(names); main(names);
@ -21811,7 +21811,7 @@ const runner = {
let result = callback(run_round, win_count); let result = callback(run_round, win_count);
if (!result) { if (!result) {
stop_bomb = true; stop_bomb = true;
resolve({ score: win_count, raw_data: win_datas }); resolve({ win_count: win_count, raw_data: win_datas });
} }
}); });
main(names); main(names);
@ -21856,7 +21856,7 @@ const runner = {
data.push({ round: run_round, win_count: win_count }); data.push({ round: run_round, win_count: win_count });
if (run_round >= round) { if (run_round >= round) {
stop_bomb = true; 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) => { finish_trigger.on("score_report", (run_round, score) => {
@ -21868,7 +21868,7 @@ const runner = {
}); });
main(names); main(names);
}) })
} },
}; };
if (run_env.from_code) { if (run_env.from_code) {