Gomoku (as implemented within Tourk) is a game for two players played on a 20x20 grid. It is an ancient Japanese board game. Literally translated, it means "five things."
Each player takes turns to place a counter in a vacant square. The first to get five in a row, horizontally or vertically, wins the game.
Simple, eh?
There are generally two modes of playing, building and blocking. Where your opponent is not about to win, you may as well build up your own 5 in a row. But if they are on the verge of winning, you need to step in and block, preventing them from completing that row of five.
There are heuristics which can be worked out on a piece of graph paper. Here are a few, where you are O and X is your opponent.
| ...X... | Build. No immediate risk. |
| ..OX... | Build. |
| ..XX... | Build. |
| ..OXX.. | Build. |
| ..XXX.. | Block. X may make 5 unless you step in now. |
| .OXXX.. | Build. You can block next turn if X makes 4. |
| .XXXX.. | Too late. Block incase X errs. |
| .OXXXX. | Block. X is on the verge of winning. |
If only things were so simple. Remember that gomoku is played in two dimensions. The table above shows a game in one dimension.
Gomoku is distributed as C code. Download it as..
This includes the base Tourk code, the Gomoku game specific code and the viewdbg utility.
Extract the archive into a directory. Instructions follow for Unix systems and for other (including MS Windows) systems.
If you have Gnu-Make, you may use the supplied Makefile. (Other make systems might work, but this has not been tested.)
You will need to modify the value of PLAYERS in the makefile to list all the players in the current directory, without the ".c". (Make sure you include random and vthuman.)
If you are not using GCC, but instead using the supplied "cc" compiler, you may also need to modify the CFLAGS variable to read "-Ae -g". (Certainly, this is the case with HPUX.)
Running make (or gmake) will generate the game executable. It will be called "gomoku" or "gomoku.exe". It will also attempt to make the viewdbg utility.
So far, Tourk has been developed on unix based systems, but work is in progress to make it more portable. I hope to supply sample "project files" for both MSVC and Borland C in future.
First of all, compile genbi.c into genbi.exe. This little utility looks at all the C file for player code, and generates "builtins.h", which lists all the player code in an array.
If you are having trouble compiling genbi.c, you should read this FAQ entry.
Now you have the generated builtins.h header file, you can compile everything else. Open a project file Compile and link together all the C files from the supplied archive (except genbi.c and viewdbg.c) into an executable.
Tourk is presently a command line only application. To run a
gomoku game, give the command;
gomoku players options
players are the names of the two players you want to play against each other.
The following options are available...
For example; (here, "groupie" is a player)
Debug text with will be filed into Gomoku-playername.txt for later review.
The vthuman player is supplied to allow you to test your player code. Compile "vthuman.c" and link it in as if it were just another player.
Note that vthuman uses some vt100 codes (underline and bold) to generate the display. If you can't use this, throw "-DNO_VT100" into the CFLAGS variable. (Or whichever is your compiler's equivilent mechanism.)
A separate utility, viewdbg, will give you a visual step by step account of a game in progress.
To use this, run a game with debug level 3 (or 4-9, as these include level 3) and the generated debug file will include codes which viewdbg can recognise.
For example;
gomoku groupie random -d3
viewdbg Gomoku-groupie.txt
And the game just completed will be played out on screen.
Viewdbg will only display the first game it finds in the file.
Using an extra seed parameter;
viewdbg Gomoko-groupie.txt 123456
and viewdbg will look for the game with the starting seed of
123456.
viewdbg uses a lot of VT100. (Screen positioning, text effects, etc). If you can't use vt100, sorry.
Your player should exist as a single .c file. It must have the following structure;
| #define PLAYER_NAME playername | Give your player a name. (No quotes.) |
| #include <.....> | Any standard C header files your code requires. (Except stdio.h or time.h) |
| #include "gomoku-play.h" | The common code that all players need. |
| /* Your code */ | Your code, in standard C. |
| static unsigned short phase1(int you, int round,
int newgame, unsigned short last_move)
{ /* Your main code */ } | The main function by which your code is called by the player code. |
The function phase1 takes the following parameters;
The return value of this function should be your move in XY() form. XY is a macro supplied by the header file. To move in (say) space (6,10), return XY(6,10).
To reverse an XY() value (of particular use when using the last_move value) into the x and y that created it, use XPOS() and YPOS().
The grid system in Gomoku is in two dimensions, 1..20 in each direction. To read the state of play, use the grid array.
grid is declared within the header file, and is of type
int grid[21][21];
The [x][0] and [0][y] items of this array are unused, only 1..20 in each direction is used. (Blame Andy.)
Each (used) item of the grid array contains either a zero, representing a vacant square, or a one or two, representing a mark for that player.
It is a foul to move on a filled square, or make a move outside the grid.
You do not have to detect a win. The controller code will do that for you.
To send text to the debug file, use the debugmsg() function, which works in a similar way to printf.
To best illustrate it, here is an example;
debugmsg(4,"Considering %d/%d\n",xpos,ypos);
The 4 refers to the debug level. This message will appear in the debug file when the -d4 option (or -d5 to -d9) is used. This function is otherwise identical in operation to printf. Same % formats, etc.
If you are having trouble, mail me.