A chess engine written in RPG IV free-format. Negamax with alpha-beta pruning, piece-square tables, recursive ILE procedure. ~420 lines.
As far as we know, this is the first chess engine ever written in RPG.
| File | What |
|---|---|
chess.rpgle |
The engine. RPG IV free-format, compiles on IBM i. |
play.py |
Python translation for testing. Same logic, same board, same search. You play white. |
verify.py |
Self-play verification — engine vs itself, 40 moves. |
The RPG source is the original. Python files are manual translations to verify the logic works before we got access to a real AS/400.
CRTBNDRPG PGM(MYLIB/CHESS) SRCSTMF('/path/to/chess.rpgle') DBGVIEW(*SOURCE)
CALL PGM(MYLIB/CHESS)
python3 play.py
You're white. Enter moves as e2e4, g1f3, etc. Engine thinks ~0.2s per move at depth 4.
- 64-square board:
packed(3:0) dim(64) - Move generation for all 6 piece types with direction tables
- Negamax alpha-beta via recursive
dcl-proc minimaxwith local move arrays - Material values (P=100, N=320, B=330, R=500, Q=900) + piece-square table bonuses
- Make/undo move stack for search rollback
- Algebraic notation output
chess.rpgle
├── Subroutines
│ ├── initTables / initBoard
│ ├── generateMoves / addMove
│ ├── makeMove / undoMove
│ ├── evaluate (material + PST)
│ ├── findBestMove (root search)
│ └── printBoard
├── ILE Procedures
│ ├── minimax(depth, alpha, beta, side) — recursive
│ └── sqToAlg(sq) — index to algebraic
└── Main — self-play loop
No castling, en passant, or promotion. No check detection — pseudo-legal moves only. Fixed depth 4, no opening book. These are deliberate omissions to keep the source readable. This is a search engine, not a tournament program.
RPG was designed in 1959 for business reports on punch cards. Nobody writes chess engines in it. The recursive dcl-proc minimax with local dim(256) move arrays is probably the most unhinged thing anyone has done with this language outside of a payroll system.
github.com/DukeDeSouth
