用代码生成游戏规则模型,让AI下棋更合法、更聪明。
Code World Models for General Game Playing
- 将游戏规则和进程转为可执行的Python代码模型
- 在10个游戏中9胜或平Gemini 2.5 Pro,包括4个新游戏
- 适合想提升推理深度与泛化能力的研究者
大型语言模型(LLM)的推理能力正被应用于经典棋类与卡牌游戏,但主流方法——通过提示直接生成走法——存在明显缺陷。该方法依赖模型脆弱的模式匹配能力,常导致非法走法和浅层策略。本文提出新方法:使用LLM将自然语言规则与游戏轨迹转化为形式化的可执行世界模型(即代码世界模型,CWM),以Python代码实现状态转移、合法走法枚举和终止判断。该模型作为可验证的仿真引擎,支持蒙特卡洛树搜索(MCTS)等高性能规划算法。同时,我们用提示引导LLM生成启发式价值函数(提升MCTS效率)与推断函数(估算不完美信息游戏中的隐藏状态)。相比直接将LLM作为策略,本方法具备三大优势:(1)可验证性:模型构成游戏规则的正式规范,规划器可算法化枚举合法动作,避免非法走法(前提是模型正确);(2)战略深度:融合LLM语义理解与经典规划器的深层搜索能力;(3)泛化性:引导LLM专注于数据到代码的元任务,更易适应新游戏。我们在10种不同游戏中评估该代理,其中4种为本研究新创,5种完全可观测(完美信息),5种部分可观测(不完美信息)。结果表明,本方法在9/10个游戏中优于或持平Gemini 2.5 Pro。
原文摘要 · Abstract (English)
Large Language Models (LLMs) reasoning abilities are increasingly being applied to classical board and card games, but the dominant approach -- involving prompting for direct move generation -- has significant drawbacks. It relies on the model's implicit fragile pattern-matching capabilities, leading to frequent illegal moves and strategically shallow play. Here we introduce an alternative approach: We use the LLM to translate natural language rules and game trajectories into a formal, executable world model represented as Python code. This generated model -- comprising functions for state transition, legal move enumeration, and termination checks -- serves as a verifiable simulation engine for high-performance planning algorithms like Monte Carlo tree search (MCTS). In addition, we prompt the LLM to generate heuristic value functions (to make MCTS more efficient), and inference functions (to estimate hidden states in imperfect information games). Our method offers three distinct advantages compared to directly using the LLM as a policy: (1) Verifiability: The generated CWM serves as a formal specification of the game's rules, allowing planners to algorithmically enumerate valid actions and avoid illegal moves, contingent on the correctness of the synthesized model; (2) Strategic Depth: We combine LLM semantic understanding with the deep search power of classical planners; and (3) Generalization: We direct the LLM to focus on the meta-task of data-to-code translation, enabling it to adapt to new games more easily. We evaluate our agent on 10 different games, of which 4 are novel and created for this paper. 5 of the games are fully observed (perfect information), and 5 are partially observed (imperfect information). We find that our method outperforms or matches Gemini 2.5 Pro in 9 out of the 10 considered games.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。