Compare commits

...

11 Commits

Author SHA1 Message Date
4dfb17533d
out limit! 2024-05-10 23:09:30 +08:00
f83f7ceb0f
更新一大堆相关东西 2024-05-10 23:03:44 +08:00
c02ac6234f
加个这玩意 2024-05-10 23:01:19 +08:00
5a6e38274d
ruaaaa 2024-05-10 20:29:10 +08:00
769fd4b7cd
aaaa 2024-05-10 19:58:29 +08:00
49e89ad018
遭不住,遭不住 2024-05-10 19:46:21 +08:00
ae518e5c92
raaaaa 2024-05-10 19:42:01 +08:00
fd932e21fa
改一下 2024-05-10 19:39:46 +08:00
fdd5e03322
ennnn 2024-05-10 19:36:48 +08:00
9b96c69bbe
2024-05-10 19:34:32 +08:00
060f960320
api 大更新( 2024-05-10 19:32:51 +08:00
4 changed files with 144 additions and 49 deletions

View File

@ -62,7 +62,7 @@ function fight(names) {
* @returns * @returns
*/ */
function test_check(names) { function test_check(names) {
var have_test = names.startsWith("!test!"); var have_test = names.trim().startsWith("!test!");
return have_test; return have_test;
} }
/** /**
@ -141,34 +141,87 @@ function score_callback(names, callback) {
}); });
}); });
} }
// export { function run_any(names, round) {
// type FightResult, return __awaiter(this, void 0, void 0, function () {
// type WinRate, return __generator(this, function (_a) {
// type WinRateResult, switch (_a.label) {
// type WinRateCallback, case 0: return [4 /*yield*/, md5_module.run_any(names, round)];
// type Score, case 1: return [2 /*return*/, _a.sent()];
// type ScoreResult, }
// type ScoreCallback, });
// fight, });
// win_rate, }
// win_rate_callback, var out_limit = 1000;
// score, function wrap_any(names, round) {
// score_callback, return __awaiter(this, void 0, void 0, function () {
// }; var result, win_rate_1, win_rate_str, output_str_1, output_datas_1, win_rate_2, output_str_2, output_datas_2;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, run_any(names, round)];
case 1:
result = _a.sent();
if ('message' in result) {
// 对战结果
return [2 /*return*/, "\u8D62\u5BB6:|".concat(result.source_plr, "|")];
}
else if ('win_count' in result) {
win_rate_1 = result.win_count * 100 / round;
win_rate_str = win_rate_1.toFixed(4);
output_str_1 = "\u6700\u7EC8\u80DC\u7387:|".concat(win_rate_str, "%|(").concat(round, "\u8F6E)");
// 每 500 轮, 输出一次
if (round > out_limit) {
output_datas_1 = [];
result.raw_data.forEach(function (data, index) {
if (data.round % out_limit === 0) {
output_datas_1.push(data);
}
});
output_datas_1.forEach(function (data, index) {
var win_rate = data.win_count * 100 / data.round;
output_str_1 += "\n".concat(win_rate.toFixed(2), "%(").concat(data.round, ")");
});
}
return [2 /*return*/, output_str_1];
// } else if ('score' in result) {
}
else {
win_rate_2 = (result.score * 10000 / round).toFixed(2);
output_str_2 = "\u5206\u6570:|".concat(win_rate_2, "|(").concat(round, "\u8F6E)");
if (round > out_limit) {
output_datas_2 = [];
result.raw_data.forEach(function (data, index) {
if (data.round % out_limit === 0) {
output_datas_2.push(data);
}
});
output_datas_2.forEach(function (data, index) {
var win_rate = (data.score / data.round * 10000).toFixed(2);
output_str_2 += "\n".concat(win_rate, "(").concat(data.round, ")");
});
}
return [2 /*return*/, output_str_2];
}
return [2 /*return*/];
}
});
});
}
function main() { function main() {
return __awaiter(this, void 0, void 0, function () { return __awaiter(this, void 0, void 0, function () {
var fs, path, names, result; var fs, path, names, start_time, result, end_time;
return __generator(this, function (_a) { return __generator(this, function (_a) {
switch (_a.label) { switch (_a.label) {
case 0: case 0:
fs = require("fs"); fs = require("fs");
path = require("path"); path = require("path");
names = fs.readFileSync(path.resolve(__dirname, "input.txt"), "utf-8"); names = fs.readFileSync(path.resolve(__dirname, "input.txt"), "utf-8");
return [4 /*yield*/, md5_module.run_any(names, 50000)]; start_time = Date.now();
return [4 /*yield*/, wrap_any(names, 10000)];
case 1: case 1:
result = _a.sent(); result = _a.sent();
// console.log(`赢家:|${result.source_plr}|`); end_time = Date.now();
console.log(result); console.log(result);
console.log("Node.js \u8017\u65F6: ".concat(end_time - start_time, " ms"));
return [2 /*return*/]; return [2 /*return*/];
} }
}); });

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,58 @@ 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, const out_limit: number = 1000;
// type Score,
// type ScoreResult, async function wrap_any(names: string, round: number): Promise<string> {
// type ScoreCallback, const result = await run_any(names, round);
// fight, if ('message' in result) {
// win_rate, // 对战结果
// win_rate_callback, return `赢家:|${result.source_plr}|`;
// score, } else if ('win_count' in result) {
// score_callback, // 胜率结果
// }; 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;
}
}
async function main() { async function main() {
// 从相对位置导入内容 // 从相对位置导入内容
@ -157,9 +195,13 @@ 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 start_time = Date.now();
const result = await wrap_any(names, 10000);
const end_time = Date.now();
console.log(result); console.log(result);
console.log(`Node.js 耗时: ${end_time - start_time} ms`);
} }
main(); main();

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
const _version_ = "0.2.0"; const _version_ = "0.3.0";
// let name_input = "!test!\n\natest\n\ntest2"; // let name_input = "!test!\n\natest\n\ntest2";
// let name_input = "!test!\n\nthis_is_a"; // let name_input = "!test!\n\nthis_is_a";
@ -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++) {
@ -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) {

View File

@ -15,7 +15,7 @@ else:
IcaNewMessage = TypeVar("NewMessage") IcaNewMessage = TypeVar("NewMessage")
IcaClient = TypeVar("IcaClient") IcaClient = TypeVar("IcaClient")
_version_ = "0.4.0" _version_ = "0.4.1"
COMMAND = "/namerena" COMMAND = "/namerena"
@ -56,7 +56,7 @@ def on_ica_message(msg: IcaNewMessage, client: IcaClient) -> None:
# 发送结果 # 发送结果
end_time = time.time() end_time = time.time()
reply = msg.reply_with( reply = msg.reply_with(
f"{out_result}{err_result}\n耗时:{end_time - start_time:.2f}s\n版本:{_version_}" f"{out_result}{err_result}外部耗时:{end_time - start_time:.2f}s\n版本:{_version_}"
) )
client.send_message(reply) client.send_message(reply)
except Exception as e: except Exception as e: