Catalog · How the catalog works
TRGoChessPas
Translation of https://github.com/RickT34/TRGoChessC
- ★ 1 on GitHub
Anyone may press Interesting, signed in or not. It helps others find this project.
README
ChessPas
ChessPas is a Free Pascal port of the C Gomoku project in ../ChessC/.
The game is five-in-a-row on a 15 x 15 board, not standard chess.
ChessC is preserved as a read-only reference.
Author and Contribution
This project was created and extended by OpenCode, an AI software engineering assistant, working in the shared repository with the user.
I translated the original ChessC Gomoku project from C to Free Pascal and
implemented the following parts:
- Pascal units corresponding to the C source files, including the board, players, game manager, actions, stacks, queues, AI utilities, AC automaton, genetic algorithm, training code, and MT19937 random generator.
- A playable human-versus-AI command-line program in
TRGoChessPas.pas. - Coordinate input in forms such as
h8and8h. - Interactive commands for help, undo, serialization, and quitting.
- AI pattern evaluation using the original default pattern weights.
- A compiled Aho-Corasick matcher for efficient pattern detection.
- Alpha-beta search, negamax evaluation, tactical win detection, candidate ordering, and Zobrist caching.
- Multithreaded root-level AI search using Free Pascal threads and critical sections.
- Game save/load and game-record replay support.
- Debug and release build scripts.
- Regression tests covering board geometry, AI tactics, serialization, game state, coordinate parsing, pattern matching, random generators, and utilities.
Build and Run
Install Free Pascal (fpc). The native build has been verified with FPC 3.2.2
on Linux AArch64. On Debian/Ubuntu:
sudo apt update
sudo apt install fpcRun from this directory (ChessPas/):
sh build.sh
./TRGoChessPasThe build script recreates .build/ for compiler unit output and writes the
executable as TRGoChessPas. For Lazarus, open TRGoChessPas.lpi.
Alternatively, from the parent repository root:
sh ChessPas/build.sh
./ChessPas/TRGoChessPasPlaying
The human player is X and moves first. The AI player is O.
Complete five or more contiguous stones horizontally, vertically, or diagonally
to win. A full board without a winning line is a draw.
Enter coordinates such as h8 or 8h, using columns a through o and rows
1 through 15. Coordinates are case-insensitive; occupied squares and
trailing characters are rejected.
Commands during a game:
? Show help
- Undo the last round
> Print serialized game data
q QuitEnd-of-input also exits the program. Loading saved games is supported by the Pascal API, not by an interactive command.
Tests
From this directory, run:
sh test.shThe script rebuilds and runs all five regression programs with range, overflow,
I/O, assertion, and heap checks. Build output stays in .build/tests/.
Set FPC=/path/to/fpc to select a different compiler for the test script.
| Program | Coverage |
|---|---|
UtilitiesSmoke.pas |
All board points and directions, win detection, pattern matching, RNG isolation, C-compatible board serialization |
SupportingSmoke.pas |
Queue growth and ordering, genetic crossover, player setup and serialization |
Smoke.pas |
Turn validation, undo, pause, game/record round trips and malformed input |
AISmoke.pas |
Both-color wins and blocks, board preservation, state rebuilding, near-full and full boards |
TRGoChessPas.pas with PARSEPOINT_TEST |
Coordinate parsing without running AI search |
All five programs passed on Linux AArch64 with runtime checks enabled and zero leaked blocks reported by heap tracing. Full training runs and cross-platform builds have not been verified.
Cleanup
From this directory, run:
sh clean.shThis removes .build/, .release-build/, lib/, loose compiler output, and
local executables. It preserves Pascal sources, Lazarus project/settings files,
release artifacts, Git metadata, and everything under ../ChessC/.
Training and supporting units remain part of the port even though the
interactive executable does not invoke training.
Port Notes
Actions and integer fields retain the C eight-character, least-significant-nibble-first serialization. Raw board serialization converts Pascal's internal stone values to the C wire encoding. Game and record loaders reject malformed fields, illegal or duplicate moves, nonalternating turns, and inconsistent game state. Game loading preserves player types.
TGame does not own its players, matching FreeGame in C. Callers must free
players separately, including players created by a successful LoadGame call.
Correctness fixes include anti-diagonal bounds, shared five-in-a-row detection, negamax terminal scores, exact-only search caching, undo turn restoration, full-board handling, complete pattern failure-chain output, RNG isolation, queue capacity handling, and genetic crossover parent preservation.
Known Limitations
The AI rebuilds its evaluation state from the board before each move. It uses a six-placement search with neighboring candidates, immediate-threat filtering, and multithreaded root search. It is not expected to produce identical moves to the C engine.
General opening searches at the default depth can take more than 20 seconds.
The tactical tests are not a playing-strength or latency benchmark. Search depth
and worker count are configured by AIDepth and CoreCount in Globals.pas;
changing them requires a rebuild.
Release Builds
From this directory, run:
sh release.shThe script is configured for a Linux AArch64 host: it requires a Linux AArch64 build and attempts Linux x86_64 and Windows x86_64 cross builds. Successful binaries are placed in the parent repository's release directory:
../release/linux-aarch64/
../release/linux-x86_64/
../release/windows-x86_64/Each successful target also receives a BUILD_INFO.txt file. Cross builds
require the corresponding Free Pascal compiler, RTL units, linker, target
libraries, and, for Windows, MinGW-w64. Failed cross builds are skipped rather
than replaced with placeholder binaries. Set FPC=/path/to/fpc if needed.

