文章摘要
GitHub用户datavorous开发了一个名为sameshi的迷你国际象棋引擎,其Elo评分约为1200,特别之处在于整个引擎的代码体积被压缩至2KB以内。该项目展示了在极小的代码空间内实现基本象棋AI功能的编程技巧。
文章总结
GitHub项目:datavorous/sameshi - 一个仅2KB大小的1200分国际象棋引擎
项目简介
sameshi是一个极简国际象棋引擎,其核心代码(sameshi.h)仅1.95KB,却具备约1200 Elo等级分的棋力(95%置信区间1110-1225)。该项目在240局与Stockfish(1320-1600等级)的测试中,固定搜索深度为5层,最大60步限制。
核心功能
- 120格邮箱式棋盘表示法
- 负极大值搜索算法
- Alpha-Beta剪枝优化
- 基于子力价值的简单评估
- 优先处理吃子的走法排序
- 完整的合法走子验证(包括将军/将死/逼和)
功能限制
未实现以下规则: - 王车易位 - 吃过路兵 - 兵升变 - 重复局面 - 50回合规则
技术特点
- 代码量极小(<2KB)
- 纯C语言实现(占比93.5%)
- 包含Makefile构建文件(占比6.5%)
- 属于demoscene风格的代码优化实践
项目状态
- GitHub星标:60
- 无分叉版本
- 持续维护中
演示视频可通过项目页面的"Watch Demo Video"链接查看。该项目展示了在极端代码体积限制下实现基本象棋AI的技术可能性。
(注:已过滤原始内容中GitHub导航菜单、页脚条款等非核心信息,保留项目技术细节和关键数据)
评论总结
以下是评论内容的总结:
代码压缩与可读性
- 有评论者赞赏代码体积小,但希望有可读版本(评论1:"Cool that you could keep it under 2k but it would nice to have a readable version")。
- 另一评论者提到代码混淆符合开源精神(评论7:"I love how you obfuscated your code, really in a spirit of FOSS!")。
功能与规则完整性
- 多个评论指出引擎缺少王车易位、吃过路兵等功能(评论2:"How did you handle games where Stockfish would castle or promote?";评论13:"not implemented: castling, en passant, promotion")。
- 有用户建议实现完整规则集(评论13:"make something tiny that supports full ruleset")。
性能与体积的权衡
- 评论者讨论引擎的ELO评分与体积关系(评论5:"What would be the elo gain for 4KB engine?";评论8:"The gap between your 1200 Elo in 2KB and the TCEC 4K engines at ~3000 Elo is interesting")。
- 有用户提到棋盘表示方法对体积的影响(评论8:"The mailbox board representation is a good call for size-constrained engines")。
技术细节与改进建议
- 用户提出具体Bug(评论10:"The pawn is not permitted to move two fields after it has already beeen moved once before")。
- 有建议使用现有工具优化代码(评论9提到Toledo引擎;评论10:"use the front-end of GNU chess")。
历史背景与工具参考
- 评论者引用历史案例(评论13:"Video Chess fit in 4k and supported fuller ruleset in 1980")。
- 推荐ELO评估工具(评论14:"cutechess [1], which uses SPRT [2]")。
关键引用保留:
- 代码可读性:"Cool that you could keep it under 2k but it would nice to have a readable version"(评论1)。
- 规则完整性:"not implemented: castling, en passant, promotion"(评论13)。
- 性能与体积:"The gap between your 1200 Elo in 2KB and the TCEC 4K engines at ~3000 Elo is interesting"(评论8)。