01 / Action model
Choose the action representation first
A KataGo-style policy head most naturally outputs one selected point, so a complex move can be decomposed into several selections.
Placement games
Gomoku, Hex, and Go variants are usually simplest: an action selects one empty point. Policy output, legal moves, and board state are almost one-to-one.
Movement games
Xiangqi, Ataxx, and Amazons can be split into selecting a piece and selecting its destination. Amazons adds a third selection for the arrow square. Every stage still chooses one position on the board.
Cost of decomposition
Staging makes one move deeper in the search tree, so state must record the current stage and previously selected points. The benefit is a simpler integration without redesigning the network output as a huge action table.
02 / File map
Core-file checklist
These are the most common modification points. In a specific branch, search for the same filenames or equivalent responsibilities.
| Module | Common files | Change | Checks | Games | Notes |
|---|---|---|---|---|---|
| Board state | cpp/game/board.hcpp/game/board.cpp |
Board dimensions, point contents, move execution, first-pass legality, and terminal helpers | Random play does not crash; piece counts and boundaries remain correct | All games | Movement games must retain origin, destination, and stage |
| Game history | cpp/game/boardhistory.hcpp/game/boardhistory.cpp |
Turn progression, result, repetition, pass/no legal move, score | Terminal results remain stable and loop rules match the design | All games | Many rules bugs hide in history and terminal logic |
| Rules options | cpp/game/rules.hcpp/game/rules.cpp |
Rules enums, komi/scoring parameters, variant switches, configuration parsing | Configurations do not leak into one another | Multi-rules branches | For one original ruleset, configuration can initially stay minimal |
| Coordinates & size | cpp/game/loc.hcpp/game/board.h |
Maximum board, coordinate conversion, special locations such as pass/resign | Readable GTP/log coordinates and correct rectangular boards | Non-standard boards | Rectangular boards need extra attention to network input dimensions |
| Network inputs | cpp/neuralnet/nninputs.cppcpp/neuralnet/nninputs.h |
Board and global features, history planes, current stage, previous selections | Input dimensions match model configuration and agree in training and inference | All games | Staged games must expose the stage to the network |
| Action mapping | cpp/neuralnet/nninputs.cppcpp/search files |
Map policy points to legal actions; handle pass and resign | Search samples no illegal points and omits no legal point | Staged games | Each stage has a different legal set and needs a staged mask |
| I/O formats | cpp/dataiocpp/commandcpp/program |
Position text, SGF/game records, GTP commands, debug output | Replay games, load test positions, and understand logs | Games intended for release | A prototype can simplify this, but long training must be reproducible |
03 / State machine
Implementing staged moves
For a move that first selects a piece and then a destination, a state machine is usually more robust than one monolithic action table.
- Add a stage field. Record a stage such as
select_piece,select_destination, orselect_arrowin board or history state, together with selected origin and intermediate points. - Generate legal points by stage. The first stage selects only movable friendly pieces; the second only destinations legal for that piece; an Amazons third stage only reachable arrow squares. Every stage returns a set of board points.
- Change player only after the complete action. Do not switch players or perform a full result check during an intermediate stage. After every sub-step, update the board, clear temporary fields, switch turns, and check the result.
- Expose the stage to the network. Add a stage plane or global feature in
nninputs.cpp, and encode selected origin/intermediate points as board planes. Otherwise the network cannot distinguish selecting a piece from selecting a destination. - Adapt records and replay. Prefer human-readable complete actions such as
a1-c3ord1-d4-a4in logs, while internal training data can retain the staged sequence.
- 增加阶段字段。 在棋盘或历史状态里记录当前阶段,例如
select_piece、select_destination、select_arrow。同时记录已经选中的起点或中间点。 - 分阶段生成合法点。 第一阶段只允许选择己方可动棋子;第二阶段只允许该棋子的合法落点;亚马逊棋第三阶段只允许射箭可达点。每个阶段都返回一个棋盘点集合。
- 只有完整行动才换手。 中间阶段不要切换玩家,也不要把半步当成完整胜负判断。等所有子步骤完成后,再更新棋盘、清空临时字段、切换回合并检查终局。
- 给网络看见阶段。 在
nninputs.cpp里加入阶段平面或全局特征,并把已选起点/中间点编码成棋盘平面。否则网络无法区分“现在该选棋子”还是“现在该选落点”。 - 调整记录与复盘。 日志里最好仍把完整行动打印成人能读懂的一步,例如
a1-c3或d1-d4-a4,但内部训练数据可以继续按拆步序列保存。
04 / Verification
Verification checklist
Rules checks
- The empty position has the correct number of legal moves.
- Edges, corners, captures, blocking, forbidden moves, pass, and no-move cases are covered.
- The winner does not fluctuate after the game has ended.
- 空局面合法着法数量正确。
- 边角、吃子、阻挡、禁手、pass 或无路可走都覆盖到。
- 终局后一方胜负不会反复变化。
Training checks
- Self-play continuously produces data without illegal-move errors.
- Training reads the data, exports a model, and the next generation loads it.
- The policy does not put substantial probability on points that are always illegal.
- 自对弈能连续生成数据,没有非法招法报错。
- 训练能读入数据,模型能导出,下一代自对弈能加载。
- 策略分布里没有大量概率压在永远非法的位置上。
Reproducibility checks
- Save the rules branch, configuration, board size, and training parameters.
- A complete game can be replayed from logs or a game record.
- After changing rules, train from scratch; do not mix old-rules data.
- 保存规则分支、配置、棋盘尺寸和训练脚本参数。
- 能从日志或棋谱复盘一局完整对局。
- 改规则后要从头训练,不要混用旧规则数据。
This checklist covers engineering integration. For the complete data and model route, see training AI for a game you invented. Treat the scripts in the selected KataGomo branch as the final authority for concrete parameters.
这份清单解决的是工程接入;完整的数据和模型训练路线见训练自己发明的新棋。具体参数仍以对应 KataGomo 分支的脚本为准。