This commit is contained in:
shenjack 2024-05-10 19:23:55 +08:00
parent b25253ebb8
commit cf5742a4df
Signed by: shenjack
GPG Key ID: 7B1134A979775551
2 changed files with 35 additions and 5 deletions

View File

@ -23,7 +23,7 @@ type WinRate = {
* *
*/ */
type WinRateResult = { type WinRateResult = {
souce: number; win_count: number;
raw_data: WinRate[]; raw_data: WinRate[];
}; };
@ -63,7 +63,7 @@ type ScoreCallback = (run_round: number, score: number) => boolean;
async function fight(names: string): Promise<FightResult> { async function fight(names: string): Promise<FightResult> {
// 检查一下输入是否合法 // 检查一下输入是否合法
// 比如里面有没有 !test! // 比如里面有没有 !test!
if (names.startsWith("!test!")) { if (names.indexOf("!test!") !== -1) {
throw new Error("你怎么在对战输入里加 !test!(恼)\n${names}"); throw new Error("你怎么在对战输入里加 !test!(恼)\n${names}");
} }
return await md5_module.fight(names); return await md5_module.fight(names);
@ -75,7 +75,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;
} }
@ -134,6 +134,11 @@ async function score_callback(
return await md5_module.score_callback(names, callback); return await md5_module.score_callback(names, callback);
} }
async function run_any(names: string, round: number): Promise<FightResult | WinRateResult | ScoreResult> {
return await md5_module.run_any(names, round);
}
export { export {
FightResult, FightResult,
WinRate, WinRate,
@ -147,4 +152,5 @@ export {
win_rate_callback, win_rate_callback,
score, score,
score_callback, score_callback,
run_any,
}; };

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);
@ -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) { if (run_env.from_code) {