nkg114mc / c-gomoku-cli

Command Line Interface tool for Gomocup gomoku/renju engines
GNU General Public License v3.0
7 stars 3 forks source link

c-gomoku-cli

c-gomoku-cli is a command line interface for gomoku/renju engines that support Gomocup protocol. It is a derived project from c-chess-cli, originally authored by Lucas Braesch (lucasart).

Different from computer chess community where a lot of interface tools have been developed in the passed 20 years, computer gomoku/renju is still lack of tools for engine-vs-engine matches. Most of the existing tools are GUI based, which is not suitable for distributed systems like high performance clusters. The motivation of c-gomoku-cli is to provide an open-source command line tool that can run large scale engine-vs-engine matches on multi-core workstations or cluster systems in parallel. The large-scale engine-vs-engine testing is common approach for quantifying the strength improvements of computer game engines, like chess. With this tool, engine designers can concisely measure the new engine ELO gain by letting it play with the old version for enough number of games.

Instead of sticking on the C language to avoid the dependency hell in c-chess-cli, C++ is chosen to be the primary programming language in this project, because my target is to build a usable tool and C++ contains some features that can bring more convenience to achieving this target. Similar to c-chess-cli, c-gomoku-cli is primarily developed for Unix/Linux, it should work on all POSIX operating systems, including MacOS and Android. Windows support is added by Haobin (dhbloo).

Compiling from the Source

Under the root directory of project, run cd src, then run make.

Usage

c-gomoku-cli [-each [eng_options]] -engine [eng_options] -engine [eng_options] ... [options]

Example

c-gomoku-cli -each tc=180/30 \
    -engine name=Wine cmd=./example-engine/pbrain-wine \
    -engine name=Rapfi cmd=./example-engine/pbrain-rapfi1 \
    -rule 0 -boardsize 20 -rounds 2 -games 4000 -debug -repeat \
    -concurrency 8 -drawafter 200 \
    -pgn my_games.pgn -sgf my_games.sgf -msg my_games.txt \
    -openings file=opening_examples/offset_freestyle_20x20.txt order=random

Options

Engine Options

Openings File Format

So far c-gomoku-cli only accept openings in plaintext format (*.txt). In a plaintext opening file, each line is an opening position. Currently there are two notation types for a position: offset and pos.

"Offset" opening notation (Gomocup opening format)

Offset opening notation is denoted by the move sequence: <black_move>, <white_move>, <black_move>... . Each move is separated with a comma "," and a space "". The last move will not be followed by any comma or space. Each move is in format <x-offset>,<y-offset>, no space in between. Note that here each coordinate is the offset from the center of the board, which is different from the move coordinate of Gomocup protocol where (0,0) is up-left corner of the board. Offset value can be negative. Assuming that a board is in size SIZE, the conversion between plaintext offsets <x-offset>,<y-offset> and Gomocup move <x>,<y> is:

HALF_SIZE = floor(SIZE / 2)
<x> = <x-offset> + HALF_SIZE
<y> = <y-offset> + HALF_SIZE

The following is an example position in "offset" notation:

8,-3, 6,-4, 5,-4, 4,-3, 2,-8, -1,-5

You can see more examples from Gomocup 2020 result page (download the results+openings from the link at the very bottom of that page).

"Pos" opening notation

Pos opening notation is denoted by a sequence of move position, with no space or any forms of delimiter in between: <black_move><white_move><block_move>... . Each move is in format <x-coord><y-coord>, while <x-coord> is a letter starting from "a", <y-coord> is a number starting from "1". Coordinate is the offset from the upper-left corner of the board. This notation is only suitable for board size less than 27.

The following is an example position in "pos" notation:

b7d6e6f7h2k5

This notation is common among many Gomoku/Renju applications. (For example, you can acquire a pos notation text by using "getpos" command in Yixin-Board).

Sampling (advanced)

Sampling is used to record various position and engine outputs in a game, as well as the final game result. These can be used as training data, which can be used to fit the parameters of a gomoku engine evaluation, otherwise known as supervised learning. Sample record is usually in binary format easy for engine to process, meanwhile a human readable and easily parsable CSV file can also be generated. Note that only game which result is not "win by time forfeit" or "win by opponent illegal move" will be recorded.

Syntax is -sample [freq=%f] [format=csv|bin|bin_lz4] [file=%s]. Example -sample freq=0.25 format=csv file=out.csv.

Binary format

Binary format uses variable length encoding show below, which is easy to parse for engines. Each entry has a length of 4+ply bytes. Position is represented by a move sequence that black plays first. Move sequence is guaranteed to have the same order as the actual game record.

struct Entry {
    uint16_t result : 2;    // game outcome: 0=loss, 1=draw, 2=win (side to move pov)
    uint16_t ply : 9;       // current number of stones on board
    uint16_t boardsize : 5; // board size in [5-22]
    uint16_t rule : 3;      // game rule: 0=freestyle, 1=standard, 4=renju
    uint16_t move : 13;     // move output by the engine
    uint16_t position[ply]; // move sequence that representing a position
};

Each move is represented by a 16bit unsigned integer. It's lower 10 bits are constructed with two index x and y using uint16_t move = (x << 5) | y;. Below is a code snippet that does transform between the packed move and two coordinates.

uint16_t Move(int x, int y)    { return (x << 5) | y; }
int      CoordX(uint16_t move) { return (move >> 5) & 0x1f; }
int      CoordY(uint16_t move) { return move & 0x1f; }

Acknowledgement

Thanks to lucasart for developing the c-chess-cli project. His prior work provides a perfect starting point for the development of c-gomoku-cli. Thanks to Haobin for contributing the support on Windows. It makes c-gomoku-cli avaliable to all Windows based engines.

External library used:

Contributors

Lucas Braesch (lucasart) Chao Ma (nkg114mc) Haobin Duan (dhbloo)