Compare commits

..

No commits in common. "4dfb17533d7068f377fefe68696b063a9a4098db" and "a99467dfbf7b8d6aca4367b595e7c4448fe25404" have entirely different histories.

4 changed files with 49 additions and 144 deletions

View File

@ -62,7 +62,7 @@ function fight(names) {
* @returns * @returns
*/ */
function test_check(names) { function test_check(names) {
var have_test = names.trim().startsWith("!test!"); var have_test = names.startsWith("!test!");
return have_test; return have_test;
} }
/** /**
@ -141,87 +141,34 @@ function score_callback(names, callback) {
}); });
}); });
} }
function run_any(names, round) { // export {
return __awaiter(this, void 0, void 0, function () { // type FightResult,
return __generator(this, function (_a) { // type WinRate,
switch (_a.label) { // type WinRateResult,
case 0: return [4 /*yield*/, md5_module.run_any(names, round)]; // type WinRateCallback,
case 1: return [2 /*return*/, _a.sent()]; // type Score,
} // type ScoreResult,
}); // type ScoreCallback,
}); // fight,
} // win_rate,
var out_limit = 1000; // win_rate_callback,
function wrap_any(names, round) { // score,
return __awaiter(this, void 0, void 0, function () { // score_callback,
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, start_time, result, end_time; var fs, path, names, result;
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");
start_time = Date.now(); return [4 /*yield*/, md5_module.run_any(names, 50000)];
return [4 /*yield*/, wrap_any(names, 10000)];
case 1: case 1:
result = _a.sent(); result = _a.sent();
end_time = Date.now(); // console.log(`赢家:|${result.source_plr}|`);
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 = {
win_count: number; souce: number;
raw_data: WinRate[]; raw_data: WinRate[];
}; };
@ -46,7 +46,7 @@ type Score = {
* *
*/ */
type ScoreResult = { type ScoreResult = {
score: number; source: 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.trim().startsWith("!test!"); const have_test = names.startsWith("!test!");
return have_test; return have_test;
} }
@ -135,58 +135,20 @@ 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> { // export {
return await md5_module.run_any(names, round); // type FightResult,
} // type WinRate,
// type WinRateResult,
const out_limit: number = 1000; // type WinRateCallback,
// type Score,
async function wrap_any(names: string, round: number): Promise<string> { // type ScoreResult,
const result = await run_any(names, round); // type ScoreCallback,
if ('message' in result) { // fight,
// 对战结果 // win_rate,
return `赢家:|${result.source_plr}|`; // win_rate_callback,
} else if ('win_count' in result) { // score,
// 胜率结果 // 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() {
// 从相对位置导入内容 // 从相对位置导入内容
@ -195,13 +157,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 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.3.0"; const _version_ = "0.2.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: (tag) => { createElement: function (tag) {
// return fake_element.fake_init(tag); // return fake_element.fake_init(tag);
return new fake_element(tag); return new fake_element(tag);
}, },
createTextNode: (data) => { createTextNode: function (data) {
let node = new fake_element("text"); let node = new fake_element("text");
node.innerHTML = data; node.innerHTML = data;
return node; return node;
}, },
querySelector: (tag) => { querySelector: function (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({ win_count: win_count, raw_data: win_datas }); resolve({ score: 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({ win_count: win_count, raw_data: win_datas }); resolve({ score: 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({ win_count: win_count, raw_data: data }); resolve({ score: 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.1" _version_ = "0.4.0"
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}外部耗时:{end_time - start_time:.2f}s\n版本:{_version_}" f"{out_result}{err_result}\n耗时:{end_time - start_time:.2f}s\n版本:{_version_}"
) )
client.send_message(reply) client.send_message(reply)
except Exception as e: except Exception as e: