Back to Projects

Checkers Game

A desktop Checkers game built in C with a GTK+ graphical interface, featuring single-player AI, two-player, and AI vs AI modes.

2023

Duration

Mar 2023 – May 2023

Contributors

2 contributors

Technologies

4+ tech

CG

Checkers Game

A desktop Checkers game written in C with a GTK+ graphical interface. It enforces the full rule set and offers three ways to play: against an AI opponent, against a friend on the same machine, or as a spectator watching two AIs play each other.

Built as a systems programming project.

What it does#

  • Full rules — captures, multi-jumps, promotion to king, and forced captures are all enforced
  • Single-player — play against an AI opponent
  • Two-player — local play on the same machine
  • AI vs AI — watch two computer players compete
  • Difficulty levels — the AI's strength scales with how far ahead it searches
  • Graphical board — a GTK+ interface with board rendering and piece animations

The rule engine#

Checkers looks simple and has more edge cases than expected. A piece can capture several times in one turn, a capture is mandatory when one is available, and a piece that reaches the far row becomes a king that moves in both directions.

The board is a 2D array, and each square stores its piece state as bitfield flags — empty or occupied, which player, king or not. That makes checking a square a single bitwise test, which matters once the AI starts examining thousands of positions.

Move generation follows the rules in order: first look for captures; if any exist, only captures are legal. A capture that lands where another capture is possible continues the same turn. Only when no capture exists are simple moves considered.

The AI: minimax with alpha-beta pruning#

The computer player uses minimax, the classic algorithm for two-player games. It looks ahead several moves, assuming the AI picks the move that is best for it and the opponent picks the move that is worst for the AI, and chooses the move that leads to the best guaranteed outcome. In simplified form:

c
int minimax(Board *b, int depth, int alpha, int beta, bool maximizing) {
    if (depth == 0 || game_over(b))
        return evaluate(b);

    MoveList moves = generate_moves(b, maximizing ? AI : HUMAN);
    for (int i = 0; i < moves.count; i++) {
        Board next = apply_move(b, moves.items[i]);
        int score = minimax(&next, depth - 1, alpha, beta, !maximizing);

        if (maximizing) alpha = max(alpha, score);
        else            beta  = min(beta, score);

        if (beta <= alpha) break;   /* prune: this branch can't matter */
    }
    return maximizing ? alpha : beta;
}

Alpha-beta pruning is what keeps the AI responsive. It stops exploring a branch as soon as it is clear the opponent would never allow it, which removes a large share of the search tree without changing the result. That makes deeper searches affordable — and search depth is exactly what the difficulty setting controls: a shallow search plays plausibly but misses traps, a deep one sees them coming.

At the bottom of the search, evaluate() turns a position into a single score from the AI's point of view.

Architecture#

main
 └── GTK+ application
      ├── drawing area        renders the board, handles mouse clicks
      ├── game state struct   board, current turn, scores
      ├── rules module        legal moves, captures, promotion
      └── AI module           minimax + alpha-beta, returns best move

GTK+ event callbacks drive everything: a click selects or moves a piece, the move updates the game state, and the drawing area is asked to redraw. When it is the AI's turn, the AI module receives the current state and returns its chosen move — it never touches the interface directly. The same separation is what makes AI-vs-AI mode possible: two AI turns in a row, with the interface just watching.

Stack#

AreaTools
LanguageC
InterfaceGTK+
BuildGCC, Make

Results#

  • A fully playable Checkers game with every standard rule enforced
  • An AI that is a genuine challenge at higher difficulty settings
  • A native desktop experience on Linux

Team#

Built with Yasser TRIDOU.

Share:Share on Twitter / XShare on LinkedInShare on Facebook

More Projects

Dr Maroc
2024Current
A healthcare SaaS live at drmaroc.com, grown from a single app into a platform: four Angular portals in one Nx monorepo, a modular Spring Boot backend, self-hosted Keycloak, shared contracts, and a delivery pipeline where GitHub is the source of truth.
AngularNxNext.js+8
ngx-auth-client
2026Current
A published npm package that exposes Angular authentication as signals instead of getters, ships Keycloak and HTTP adapters behind a provider-agnostic port, and keeps tokens out of localStorage entirely.
AngularTypeScriptKeycloak+7