GTK4 Checkers is a demo of the classic human-vs-computer checkers game. It has been developed using C and GTK4.
A screenshot is shown below.
Checkers is played by two opponents on opposite sides of the game board. One player is white and the other is black (computer AI in this case). White moves first, then players take alternate turns. Obviously, the white player cannot move the black player's pieces and vice versa.
A move consists of moving a piece forward to a diagonal adjacent unoccupied square. If the adjacent square contains an opponent's piece, and the square immediately beyond it is unoccupied, then the opponent piece must be captured and is removed from the game by jumping over it. This is called a jump move. A piece can only move forward into an unoccupied square. When jumping an opponent's piece is possible then this must be done and can involve multiple jumps.
When a piece reaches the other end of the board it becomes a king and can move and capture diagonally in all directions.
A 64 bit prebuilt binary is available and can be downloaded from the binary folder. This has been built using Debian 12 Bookworm. Download and extract. The checkers executable can be run from a terminal as shown below.
./checkers
The checkers binary must have executable permissions. Use the command below if necessary.
chmod +x checkers
To add Checkers to the system menu modify the "checkers.desktop" file provided in the download using your user name and application location and copy it to the .local/share/applications/ directory.
This way of locally installing Checkers should be universal across different Linux distributions.
This is a player-vs-computer game. You (the player) move a white piece on the board by first mouse clicking on the piece start position and then clicking on the piece end position. The build-in AI responds with a black move.
If the white (human) player can make a multiple jump then you jump the first piece and then jump the second piece and so on. The AI prioritises multiple jumps over single jumps when both are available. If you get a "white illegal move" it usually means that you have to jump elsewhere or you have tried to move to a position which is not allowed. Click on another white piece to restart move.
When a piece reaches the other end of the board it becomes a king and its colour changes as shown below.
The AI uses a simple rule-based move algorithm and recursion for multiple jumps.
The C source code for GTK4 checkers is provided in the src directory.
With both Debian Bookworm and Ubuntu and you need to install the following packages to build GTK Checkers.
apt install build-essential
apt install libgtk-4-dev
The package:
apt install libglib2.0-dev
is needed but should be installed by default.
Use the MAKEFILE to compile.
make
To run Checkers from the terminal use
./checkers
I have used Geany for developing the code which is a lightweight source-code editor with an integrated terminal.
GTK uses CSS for styling. CSS is an abbreviation of Cascading Style Sheet and is widely used with HTML. CSS can be applied to GTK widgets, images etc. To apply CSS to an image (e.g. a checker piece) you create a GtkCssProvider which is an object that parses CSS. Currently I am using Debian 12 Bookworm for developing this application which uses GTK4.8. With GTK4.8 you load data into a CSS provider using
gtk_css_provider_load_from_data (provider, css, -1);
This clears any previously loaded CSS data. However, this is being depreciated in GTK4.12 and it is suggested that gtk_css_provider_load_from_string can be used instead. The Checkers code base will have to updated when Debian moves to GTK4.12 and above.
When time permits, I will update the Checkers code base and compile using Fedora which is currently using GTK4.14.
SemVer is used for versioning. The version number has the form 0.0.0 representing major, minor and bug fix changes.
- Alan Crispin Github
GTK4 Checkers is licensed under LGPL v2.1.
Active.
-
GTK is a free and open-source project maintained by GNOME and an active community of contributors. GTK is released under the terms of the GNU Lesser General Public License version 2.1.
-
Geany is a lightweight source-code editor (version 2 now uses GTK3). GPL v2 license