Skip to content

Chess engine in RPG IV free-format. Negamax alpha-beta, ~420 lines. First chess engine ever written in RPG.

Notifications You must be signed in to change notification settings

DukeDeSouth/rpg-chess

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RPG Chess Engine

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.

RPG Chess Engine

Files

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.

Compile and Run (IBM i)

CRTBNDRPG PGM(MYLIB/CHESS) SRCSTMF('/path/to/chess.rpgle') DBGVIEW(*SOURCE)
CALL PGM(MYLIB/CHESS)

Play Against It (Python)

python3 play.py

You're white. Enter moves as e2e4, g1f3, etc. Engine thinks ~0.2s per move at depth 4.

What's Inside

  • 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 minimax with 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

What's Missing

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.

Why

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

About

Chess engine in RPG IV free-format. Negamax alpha-beta, ~420 lines. First chess engine ever written in RPG.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages