-
Notifications
You must be signed in to change notification settings - Fork 1
Fix cards disappearing when played during round-end wait period #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…round ends Added roundClearIdRef to track which round a setTimeout belongs to. When a new round starts, the ref is incremented, causing any pending timeout from the previous round to skip clearing the cards. Co-authored-by: Roushelfy <104953631+Roushelfy@users.noreply.github.com>
|
@copilot bot有时候还是会出错: [2025-11-30T20:36:07.255Z] [INFO] Bot AI Bot 2 当前手牌数: 22 [2025-11-30T20:36:07.327Z] [ERROR] Bot响应超时,强制结束进程 [2025-11-30T20:36:08.756Z] [INFO] 开始调用BotService.getBotAction... [2025-11-30T20:36:08.756Z] [INFO] ========== WhoDesigned Bot 决策开始 ========== [2025-11-30T20:36:08.756Z] [INFO] 玩家ID: de5b5749-77a2-487a-b4c1-f6b432963360, 玩家索引: 2, 阶段: play [2025-11-30T20:36:08.756Z] [INFO] 手牌数量: 22, deliver牌数量: 0 [2025-11-30T20:36:08.756Z] [INFO] 历史记录: requests=4, responses=4 [2025-11-30T20:36:08.756Z] [INFO] 构建history: previousRoundCards长度=4, currentRoundCards长度=2, previousLeader=0, currentLeader=0 [2025-11-30T20:36:08.756Z] [INFO] [构建request] 当前阶段request: {"stage":"play","deliver":[],"global":{"first_round":true,"level":"10","banking":{"called":-1,"snatched":-1,"major":"s","banker":2},"total_score":0},"history":[[[48],[70],[24],[62]],[[98],[82]],0,0]} [2025-11-30T20:36:08.757Z] [INFO] [Bot输入] requests数量: 5, responses数量: 4 [2025-11-30T20:36:08.757Z] [INFO] 调用Bot脚本: /app/tractor-game-simulator/server/src/bots/WhoDesigned/main.py [2025-11-30T20:36:08.795Z] [WARN] Bot stderr: Traceback (most recent call last): File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/main.py", line 64, in [2025-11-30T20:36:08.796Z] [WARN] Bot stderr: setMajor(major, level) File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/myutils.py", line 15, in setMajor pointorder.remove(level) ValueError: list.remove(x): x not in list [2025-11-30T20:36:08.801Z] [INFO] Bot进程退出,代码: 1 [2025-11-30T20:36:08.801Z] [ERROR] Bot进程退出,代码: 1, 错误: Traceback (most recent call last): File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/main.py", line 64, in setMajor(major, level) File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/myutils.py", line 15, in setMajor pointorder.remove(level) ValueError: list.remove(x): x not in list [2025-11-30T20:36:08.801Z] [ERROR] [Bot决策失败] 阶段: play, 错误: Bot进程退出,代码: 1, 错误: Traceback (most recent call last): File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/main.py", line 64, in setMajor(major, level) File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/myutils.py", line 15, in setMajor pointorder.remove(level) ValueError: list.remove(x): x not in list [2025-11-30T20:36:08.801Z] [ERROR] [Bot决策失败] 错误堆栈: Error: Bot进程退出,代码: 1, 错误: Traceback (most recent call last): File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/main.py", line 64, in setMajor(major, level) File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/myutils.py", line 15, in setMajor pointorder.remove(level) ValueError: list.remove(x): x not in list at ChildProcess. (file:///app/tractor-game-simulator/server/src/services/WhoDesignedBotService.js:475:18) at ChildProcess.emit (node:events:517:28) at maybeClose (node:internal/child_process:1098:16) at ChildProcess._handle.onexit (node:internal/child_process:303:5) [2025-11-30T20:36:08.801Z] [INFO] [Fallback] play阶段: 返回空数组(跳过),将由gameHandlers的fallback处理 [2025-11-30T20:36:08.801Z] [INFO] [Fallback] 已将默认响应添加到历史,新responses长度: 5 [2025-11-30T20:36:08.801Z] [INFO] ========== WhoDesigned Bot 决策失败,使用Fallback ========== [2025-11-30T20:36:08.801Z] [INFO] Bot AI Bot 2 决策完成,选择出牌: 0 张,卡牌IDs: [] [2025-11-30T20:36:08.801Z] [INFO] 执行Bot AI Bot 2 出牌操作... [2025-11-30T20:36:08.801Z] [ERROR] Bot AI Bot 2 出牌失败: Error: 请选择要出的牌 at GameEngine.playCardsOrderedMode (file:///app/tractor-game-simulator/server/src/services/GameEngine.js:419:15) at GameEngine.playCards (file:///app/tractor-game-simulator/server/src/services/GameEngine.js:271:17) at triggerBotPlay (file:///app/tractor-game-simulator/server/src/socket/handlers/gameHandlers.js:109:31) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) [2025-11-30T20:36:08.802Z] [ERROR] 错误堆栈: Error: 请选择要出的牌 at GameEngine.playCardsOrderedMode (file:///app/tractor-game-simulator/server/src/services/GameEngine.js:419:15) at GameEngine.playCards (file:///app/tractor-game-simulator/server/src/services/GameEngine.js:271:17) at triggerBotPlay (file:///app/tractor-game-simulator/server/src/socket/handlers/gameHandlers.js:109:31) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) [2025-11-30T20:36:08.802Z] [INFO] 尝试Bot AI Bot 2 fallback策略:出 1 张牌, 类型: single [2025-11-30T20:36:08.802Z] [INFO] 房间 9450 玩家 AI Bot 2 出牌 1 张 [2025-11-30T20:36:08.802Z] [INFO] [调试] 调用 onPlayerPlayed 前: playersPlayedThisRound.size=2, players.length=4 [2025-11-30T20:36:08.802Z] [INFO] [调试] 调用 onPlayerPlayed 后: playersPlayedThisRound.size=3, roundUpdate.type=turn_changed [2025-11-30T20:36:08.802Z] [INFO] Bot AI Bot 2 fallback出牌成功 [2025-11-30T20:36:08.802Z] [INFO] 已更新玩家 de5b5749-77a2-487a-b4c1-f6b432963360 的最后响应为: [32] [2025-11-30T20:36:09.804Z] [INFO] === 检查是否需要触发Bot出牌 === [2025-11-30T20:36:09.804Z] [INFO] 房间ID: 9450, 游戏阶段: playing [2025-11-30T20:36:09.804Z] [INFO] --- 轮到Bot AI Bot 3 出牌 --- [2025-11-30T20:36:09.804Z] [INFO] 触发Bot AI Bot 3 自动出牌 [2025-11-30T20:36:09.804Z] [INFO] Bot AI Bot 3 当前手牌数: 22 [2025-11-30T20:36:09.872Z] [ERROR] Bot响应超时,强制结束进程 [2025-11-30T20:36:11.305Z] [INFO] 手牌数量: 22, deliver牌数量: 0 [2025-11-30T20:36:11.305Z] [INFO] 历史记录: requests=4, responses=4 [2025-11-30T20:36:11.306Z] [INFO] 构建history: previousRoundCards长度=4, currentRoundCards长度=3, previousLeader=0, currentLeader=0 [2025-11-30T20:36:11.306Z] [INFO] [构建request] 当前阶段request: {"stage":"play","deliver":[],"global":{"first_round":true,"level":"10","banking":{"called":-1,"snatched":-1,"major":"s","banker":2},"total_score":0},"history":[[[48],[70],[24],[62]],[[98],[82],[32]],0,0]} [2025-11-30T20:36:11.306Z] [INFO] [Bot输入] requests数量: 5, responses数量: 4 [2025-11-30T20:36:11.306Z] [INFO] 调用Bot脚本: /app/tractor-game-simulator/server/src/bots/WhoDesigned/main.py [2025-11-30T20:36:11.341Z] [WARN] Bot stderr: Traceback (most recent call last): File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/main.py", line 64, in setMajor(major, level) File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/myutils.py", line 15, in setMajor pointorder.remove(level) ValueError: list.remove(x): x not in list [2025-11-30T20:36:11.305Z] [INFO] 开始调用BotService.getBotAction... [2025-11-30T20:36:11.305Z] [INFO] ========== WhoDesigned Bot 决策开始 ========== [2025-11-30T20:36:11.305Z] [INFO] 玩家ID: bb69bb03-fee2-4588-8691-1e538e8d4624, 玩家索引: 3, 阶段: play [2025-11-30T20:36:11.345Z] [INFO] Bot进程退出,代码: 1 [2025-11-30T20:36:11.345Z] [ERROR] Bot进程退出,代码: 1, 错误: Traceback (most recent call last): File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/main.py", line 64, in setMajor(major, level) File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/myutils.py", line 15, in setMajor pointorder.remove(level) ValueError: list.remove(x): x not in list [2025-11-30T20:36:11.345Z] [ERROR] [Bot决策失败] 阶段: play, 错误: Bot进程退出,代码: 1, 错误: Traceback (most recent call last): File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/main.py", line 64, in setMajor(major, level) File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/myutils.py", line 15, in setMajor pointorder.remove(level) ValueError: list.remove(x): x not in list [2025-11-30T20:36:11.345Z] [ERROR] [Bot决策失败] 错误堆栈: Error: Bot进程退出,代码: 1, 错误: Traceback (most recent call last): File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/main.py", line 64, in setMajor(major, level) File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/myutils.py", line 15, in setMajor [2025-11-30T20:36:11.345Z] [INFO] Bot AI Bot 3 决策完成,选择出牌: 0 张,卡牌IDs: [] [2025-11-30T20:36:11.345Z] [INFO] 执行Bot AI Bot 3 出牌操作... [2025-11-30T20:36:11.345Z] [ERROR] Bot AI Bot 3 出牌失败: Error: 请选择要出的牌 at GameEngine.playCardsOrderedMode (file:///app/tractor-game-simulator/server/src/services/GameEngine.js:419:15) at GameEngine.playCards (file:///app/tractor-game-simulator/server/src/services/GameEngine.js:271:17) at triggerBotPlay (file:///app/tractor-game-simulator/server/src/socket/handlers/gameHandlers.js:109:31) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) pointorder.remove(level) ValueError: list.remove(x): x not in list at ChildProcess. (file:///app/tractor-game-simulator/server/src/services/WhoDesignedBotService.js:475:18) at ChildProcess.emit (node:events:517:28) at maybeClose (node:internal/child_process:1098:16) at ChildProcess._handle.onexit (node:internal/child_process:303:5) [2025-11-30T20:36:11.345Z] [INFO] [Fallback] play阶段: 返回空数组(跳过),将由gameHandlers的fallback处理 [2025-11-30T20:36:11.345Z] [INFO] [Fallback] 已将默认响应添加到历史,新responses长度: 5 [2025-11-30T20:36:11.345Z] [INFO] ========== WhoDesigned Bot 决策失败,使用Fallback ========== [2025-11-30T20:36:11.345Z] [ERROR] 错误堆栈: Error: 请选择要出的牌 at GameEngine.playCardsOrderedMode (file:///app/tractor-game-simulator/server/src/services/GameEngine.js:419:15) at GameEngine.playCards (file:///app/tractor-game-simulator/server/src/services/GameEngine.js:271:17) at triggerBotPlay (file:///app/tractor-game-simulator/server/src/socket/handlers/gameHandlers.js:109:31) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) |
This bot error is a separate issue from the card disappearing bug that this PR fixes. My changes only affected The error you're seeing is in the WhoDesigned bot's Python script ( If you'd like me to investigate the bot error, please open a new issue for it so we can track and fix it separately. |
Cards played during the 2-second wait period after a round ends were being cleared by the scheduled timeout from the previous round.
Problem
Race condition:
round_endedschedules asetTimeoutto clearplayedCardsafter 2s. If a player starts a new round during this window, the stale timeout still fires and clears the new round's cards.Solution
Added
roundClearIdRefto invalidate pending timeouts when a new round starts.round_started: Increments ref before clearing, invalidating any pending timeoutround_ended: Captures ref value; timeout only clears if unchangedgame_restarted/next_game_started: Increments ref to handle edge casesOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.