Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/crispinprojects/gtk-checkers
GTK Checkers is a demo of the classic human-vs-computer checkers game for GTK Linux desktops such as GNOME.
https://github.com/crispinprojects/gtk-checkers
board board-game checkers draughts gnome gtk gtk4 player-vs-computer
Last synced: 1 day ago
JSON representation
GTK Checkers is a demo of the classic human-vs-computer checkers game for GTK Linux desktops such as GNOME.
- Host: GitHub
- URL: https://github.com/crispinprojects/gtk-checkers
- Owner: crispinprojects
- License: lgpl-2.1
- Created: 2024-03-07T20:23:56.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-12-03T10:20:59.000Z (about 2 months ago)
- Last Synced: 2024-12-03T11:26:31.107Z (about 2 months ago)
- Topics: board, board-game, checkers, draughts, gnome, gtk, gtk4, player-vs-computer
- Language: C
- Homepage:
- Size: 371 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GTK Checkers
GTK Checkers is a demo of the classic human-vs-computer checkers game for Linux. It has been developed using C and the latest version of the GTK toolkit [GTK4](https://docs.gtk.org/gtk4/) for desktops such as GNOME.
Checkers is a two-player strategy game played on an 8×8 checkerboard which involve diagonal moves of circular game pieces and mandatory captures by jumping over opponent pieces. In Britain, American checkers is known as Draughts.
A screenshot of GTK Checkers running on Fedora 41 is shown below.
![](gtk4-checkers.png)
## Checkers Rules
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.
### Prebuilt Binary
A 64 bit prebuilt binary is available and can be downloaded from the binary folder. This has been built using Fedora and tested using the GNOME desktop. 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
```## Desktop File
To add the GTK Checkers to the system menu modify the desktop file provided in the download. A desktop file has a .desktop extension and provides metadata about an application such as its name, icon, command to execute and other properties. For user-specific applications desktop files can be located locally in the ***~/.local/share/applications/*** directory. Local user entries take precedence over system entries. For the GNOME desktop, the desktop file should be named using the [application ID](https://developer.gnome.org/documentation/tutorials/application-id.html), that is .desktop, which in this case is "org.gtk.checkers.desktop"
The "org.gtk.checkers.desktop" file is shown below. You need to modify this using your own user name and directory locations. For example, if your user name is "tiki" and you install local applications in a folder called "Software" and you create a folder called "checkers" to store the checkers binary executable then the executable path would be "Exec=/home/tiki/Software/checkers/checkers". The Exec variable defines the command to execute when launching an application, in this case, the checkers binary executable.
```
Desktop Entry]
Version=0.3
Type=Application
Name=GTK Checkers
Comment=GTK Checkers
Icon=/home/user/Software/checkers/checkers.png
Exec=/home/user/Software/checkers/checkers
Path=/home/user/Software/checkers
X-GNOME-UsesNotifications=true
Actions=
Categories=Game;BoardGame;
```This way of locally installing Checkers should be universal across different Linux distributions.
## Usage
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 can also make multiple jumps. 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 "Reset White Click" and then on the piece you need to move.
When a piece reaches the other end of the board it becomes a king and its colour changes as shown below.
![](gtk4-checkers-king.png)
## AI
The AI uses a minimax algorithm and move recursion for multiple jumps.
![](gtk4-checkers-ai.png)
## Build From Source
The C source code for GTK checkers is provided in the src directory.
### Building on Fedora 40 and Fedora 41
With Fedora you need to install the following packages to compile GTK Checkers.
```
sudo dnf install gcc make
sudo dnf install gtk4-devel
sudo dnf install gtk4-devel-docs
```### Building on Ubuntu 24.04 LTS
With Ubuntu and you need to install the following packages to compile GTK Checkers.
```
sudo apt install build-essential
sudo apt install libgtk-4-dev
```The package:
```
apt install libglib2.0-dev
```is needed but should be installed by default.
## Make
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.
## GTK4 Code Notes
The code for GTK Checkers version 0.3 has been updated to use GTK4.16 which is current version used by [Fedora 41](https://fedoraproject.org/). To check the GTK version use
```
dnf list gtk4-devel
```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.
Previously, when using [Debian 12 Bookworm](https://www.debian.org/) and GTK4.8 you load data into a CSS provider using
```
gtk_css_provider_load_from_data (provider, css, -1);
```This approach has been deprecated and with GTK4.16 you use
```
gtk_css_provider_load_from_string(provider,css);
```According to the [Debian GTK4 tracker](https://tracker.debian.org/pkg/gtk4) Trixie currently has GTK4.16 in its repositories. Debian experimental is using GTK4.16. The GTK Checkers code will most likely compile using Debian testing (Trixie) and experimental but I have not tried this. With Debian stable (Bookworm) the code will have to be modified to use "gtk_css_provider_load_from_data".
When using Fedora 41 and GTK4.16 the following warning occured.
```
MESA-INTEL: warning: ../src/intel/vulkan/anv_formats.c:763: FINISHME: support YUV colorspace with DRM format modifiers
```This was fixed by opening the /etc/environment file
```
sudo nano /etc/environment
```and adding
```
GSK_RENDERER=ngl
```## Versioning
[SemVer](http://semver.org/) is used for versioning. The version number has the form 0.0.0 representing major, minor and bug fix changes.
## Author
* **Alan Crispin** [Github](https://github.com/crispinprojects)
## License
GTK Checkers is licensed under LGPL v2.1.
## Project Status
Active.
## Acknowledgements
* [GTK](https://www.gtk.org/)
* 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](https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html).
* [GTK4 API](https://docs.gtk.org/gtk4/index.html)
* [GObject API](https://docs.gtk.org/gobject/index.html)
* [Glib API](https://docs.gtk.org/glib/index.html)
* [Gio API](https://docs.gtk.org/gio/index.html)
* [Geany](https://www.geany.org/) is a lightweight source-code editor (version 2 now uses GTK3). [GPL v2 license](https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt)
* [Debian](https://www.debian.org/)
* [Fedora](https://fedoraproject.org/)