koishi-plugin-cocoyyy-console 1.1.3-alpha.2 → 1.1.3-alpha.3
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 -4
- 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`
|
|
@@ -2460,12 +2493,17 @@ function registerGameCommands(ctx, game_config, ai_config) {
|
|
|
2460
2493
|
await session.send("正在结束游戏...");
|
|
2461
2494
|
let resp_text = "";
|
|
2462
2495
|
switch (now_game) {
|
|
2496
|
+
case gameList[0].command:
|
|
2497
|
+
await session.send("正在结束游戏...");
|
|
2498
|
+
resp_text = await endSituationPuzzle(ai_config);
|
|
2499
|
+
now_game = null;
|
|
2500
|
+
return checkResp(resp_text);
|
|
2463
2501
|
case gameList[1].command:
|
|
2464
|
-
|
|
2502
|
+
resp_text = await getSolution();
|
|
2465
2503
|
resp_text = `答案: ${getSolution()}`;
|
|
2466
2504
|
now_game = null;
|
|
2467
2505
|
clearGameTimeout();
|
|
2468
|
-
return checkResp(
|
|
2506
|
+
return checkResp(resp_text);
|
|
2469
2507
|
default:
|
|
2470
2508
|
return;
|
|
2471
2509
|
}
|