pg2podg
pg2podg · PostgreSQL extension for two-player open deterministic games.
Overview
PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18
| Relationships | |
|---|---|
| Requires | plpgsql |
Usage
Sources:
pg2podg is a SQL/PLpgSQL search engine for two-player, open-information, deterministic games. It supplies a reusable game-tree and move-evaluation workflow, but not a game implementation: another extension or schema must first provide the required game and move interface.
Required Game Interface
Before creating pg2podg, the database must define:
- Types
gameandmove. - Operators
## game,%% game, andgame ^ movefor display, stable text identity, and applying a move. - Functions
new_game(),score(game),gain(game, game),valid_moves(game), andparse_move(text, game). - The single-argument display operator
# game, used by the terminal UI.
The upstream example uses pgchess to supply this contract. Create the game-specific extension first:
Core Objects
- Persistent search state:
gamesstores positions and parent moves;gainscaches evaluations. - Working state: unlogged
choicesandstatustables, plus choice-ordering/display views. - Search:
research_games,compute_gains,evaluate_choices, andapply_best_choice. - User interface:
ui_cpu_moves,ui_human_moves,ui_loop,status_display_vt100, anddisplay_game_end.
research_games expands positions to a minimum depth and, after the first level, an optional time target. evaluate_choices scores the explored cone; apply_best_choice advances the current position.
Data and Upgrade Caveats
The extension inserts an initial position into games when installed. games and gains are persistent extension-owned tables; dropping the extension removes their contents. The upstream 0.1.3 README says upgrades require dropping, reinstalling, and recreating the extension and do not preserve those tables, so export any valuable state first.
This code targets PostgreSQL 9.1-era interfaces and its game contract is only implicit in the SQL source. Validate a candidate game implementation and its operators/functions before installation, and use bounded time/depth values because the game tree can grow rapidly. No preload or restart is required.