本地调用大模型玩“谁是卧底”游戏

大过年的,大家都在讨论deepseek。睿睿想玩"谁是卧底"总是凑不齐人,我开发了一个AI驱动的《谁是卧底》游戏机器人,通过调用大模型生成角色描述和投票策略,但遇到了模型输出不稳定、格式错误等问题。经过多次调整模型和提示词,最终实现了基本功能,过程中充满了有趣的失误和挑战。

AI
‰“开页面时组件一直不显示。 // 解决方式:以最近的吸顶/固定祖先作为该组元素的容器, // 使可见性判断恒成立,入场动画保留且不再依赖主文档滚动。 const findPinnedContainer = (el) => { let node = el; while (node && node.nodeType === 1) { const pos = window.getComputedStyle(node).position; if (pos === 'sticky' || pos === 'fixed') return node; node = node.parentElement; } return null; }; // 最近的滚动容器(overflow-y: auto/scroll) // 吸顶容器内可能存在内部滚动容器(如侧栏 .widgets), // 若直接用吸顶容器做 reveal 容器,折叠区下方的元素永远不会进入视口,导致一直不显示。 const findScrollContainer = (el) => { let node = el.parentElement; while (node && node.nodeType === 1) { const oy = window.getComputedStyle(node).overflowY; if (oy === 'auto' || oy === 'scroll') return node; node = node.parentElement; } return null; }; const pinnedGroups = new Map(); // 容器 -> 元素列表 const targets = []; els.forEach((el) => { const pinned = findPinnedContainer(el); if (pinned) { // 优先使用最近的滚动容器,其次才用吸顶容器 const container = findScrollContainer(el) || pinned; const group = pinnedGroups.get(container) || []; group.push(el); pinnedGroups.set(container, group); } else { targets.push(el); } }); if (pinnedGroups.size === 0 && targets.length === 0) { clearTimeout(watchdog); return; } const slideUp = { distance: `8px`, duration: `1000`, interval: `100`, scale: `1`, opacity: 0, easing: "ease-out" }; utils.js(`https://gcore.jsdelivr.net/npm/scrollreveal@4.0/dist/scrollreveal.min.js`, { defer: true }) .then(() => { if (fallbackApplied) return; if (typeof ScrollReveal !== 'function') { revealFallback(); return; } try { const sr = ScrollReveal(); if (targets.length > 0) { sr.reveal(targets, { ...slideUp }); } pinnedGroups.forEach((group, container) => { sr.reveal(group, { ...slideUp, container: container }); }); clearTimeout(watchdog); } catch (err) { console.error('[Plugin scrollreveal] 初始化失败:', err); revealFallback(); } }) .catch((err) => { console.error('[Plugin scrollreveal] 加载失败:', err); revealFallback(); }); }, 'scrollreveal'); })();