koishi-plugin-cocoyyy-console 1.1.3-alpha.2 → 1.1.3-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +42 -5
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -2255,6 +2255,15 @@ async function questSituationPuzzle(content, config) {
|
|
|
2255
2255
|
chatPrompt = [];
|
|
2256
2256
|
chatHistory2 = [];
|
|
2257
2257
|
clearGameTimeout();
|
|
2258
|
+
} else {
|
|
2259
|
+
clearGameTimeout();
|
|
2260
|
+
setGameTimeout(async () => {
|
|
2261
|
+
logger.info(`[SituationPuzzle Timeout]: 游戏已超时(${GAME_TIMEOUT_MINUTES}分钟),自动结束游戏`);
|
|
2262
|
+
is_gaming = false;
|
|
2263
|
+
chatPrompt = [];
|
|
2264
|
+
chatHistory2 = [];
|
|
2265
|
+
setGameTimeout(null);
|
|
2266
|
+
}, GAME_TIMEOUT_MINUTES * 60 * 1e3);
|
|
2258
2267
|
}
|
|
2259
2268
|
return resp;
|
|
2260
2269
|
}
|
|
@@ -2337,18 +2346,42 @@ function solve24(nodes) {
|
|
|
2337
2346
|
return null;
|
|
2338
2347
|
}
|
|
2339
2348
|
__name(solve24, "solve24");
|
|
2340
|
-
function
|
|
2349
|
+
function calcDifficulty(expr) {
|
|
2350
|
+
let score = 0;
|
|
2351
|
+
if (expr.includes("/")) score += 2;
|
|
2352
|
+
if (expr.includes("-")) score += 1;
|
|
2353
|
+
let depth = 0;
|
|
2354
|
+
let maxDepth = 0;
|
|
2355
|
+
for (const ch of expr) {
|
|
2356
|
+
if (ch === "(") {
|
|
2357
|
+
depth++;
|
|
2358
|
+
maxDepth = Math.max(maxDepth, depth);
|
|
2359
|
+
} else if (ch === ")") {
|
|
2360
|
+
depth--;
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2363
|
+
score += maxDepth;
|
|
2364
|
+
if (expr.match(/\/\s*[1-9]/)) score += 1;
|
|
2365
|
+
return score;
|
|
2366
|
+
}
|
|
2367
|
+
__name(calcDifficulty, "calcDifficulty");
|
|
2368
|
+
function generate24Puzzle(minScore = 6) {
|
|
2341
2369
|
while (true) {
|
|
2342
2370
|
const numbers = Array.from(
|
|
2343
2371
|
{ length: 4 },
|
|
2344
2372
|
() => Math.floor(Math.random() * 13) + 1
|
|
2345
2373
|
);
|
|
2374
|
+
if (numbers.includes(1) && numbers.includes(2) && numbers.includes(3)) {
|
|
2375
|
+
continue;
|
|
2376
|
+
}
|
|
2346
2377
|
const nodes = numbers.map((n) => ({
|
|
2347
2378
|
value: n,
|
|
2348
2379
|
expr: n.toString()
|
|
2349
2380
|
}));
|
|
2350
2381
|
const solution = solve24(nodes);
|
|
2351
|
-
if (solution)
|
|
2382
|
+
if (!solution) continue;
|
|
2383
|
+
const score = calcDifficulty(solution);
|
|
2384
|
+
if (score >= minScore) {
|
|
2352
2385
|
return {
|
|
2353
2386
|
numbers,
|
|
2354
2387
|
solution: `${solution} = 24`
|
|
@@ -2453,19 +2486,23 @@ function registerGameCommands(ctx, game_config, ai_config) {
|
|
|
2453
2486
|
if (!is_at_bot(session)) return;
|
|
2454
2487
|
}
|
|
2455
2488
|
if (!now_game) return "未开始游戏";
|
|
2456
|
-
if (now_game == gameList[0].command) return;
|
|
2457
2489
|
if (is_thinking) return "正在思考,请耐心等待...";
|
|
2458
2490
|
try {
|
|
2459
2491
|
is_thinking = true;
|
|
2460
2492
|
await session.send("正在结束游戏...");
|
|
2461
2493
|
let resp_text = "";
|
|
2462
2494
|
switch (now_game) {
|
|
2495
|
+
case gameList[0].command:
|
|
2496
|
+
await session.send("正在结束游戏...");
|
|
2497
|
+
resp_text = await endSituationPuzzle(ai_config);
|
|
2498
|
+
now_game = null;
|
|
2499
|
+
return checkResp(resp_text);
|
|
2463
2500
|
case gameList[1].command:
|
|
2464
|
-
|
|
2501
|
+
resp_text = await getSolution();
|
|
2465
2502
|
resp_text = `答案: ${getSolution()}`;
|
|
2466
2503
|
now_game = null;
|
|
2467
2504
|
clearGameTimeout();
|
|
2468
|
-
return checkResp(
|
|
2505
|
+
return checkResp(resp_text);
|
|
2469
2506
|
default:
|
|
2470
2507
|
return;
|
|
2471
2508
|
}
|