Skip to content

code-geek/baghchal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Baghchal

A desktop implementation of Baghchal (बाघचाल), a traditional Nepali strategic board game, featuring a strong AI opponent with 5 difficulty levels.

Baghchal is a game of asymmetric strategy played on a 5x5 grid. One player controls 4 tigers, the other controls 20 goats. Tigers hunt goats by jumping over them; goats try to trap all tigers so they cannot move. The asymmetry makes every game a unique tactical puzzle.

Table of Contents

Features

  • Three game modes: Play as Goat vs AI, Play as Tiger vs AI, or Human vs Human
  • 5 AI difficulty levels: From beginner-friendly to very challenging
  • Timed Human vs Human mode: 5-minute chess clock per side
  • Sound effects and a polished main menu
  • Keyboard and mouse support
  • Self-contained: All assets (images, fonts, sounds) are embedded in the binary — no external files needed at runtime

Game Rules

Tigers (Bagh) Goats (Bakhra)
Pieces 4 (start on corners) 20 (placed one per turn)
Objective Capture 5 goats Trap all tigers so they cannot move
Movement Move to an adjacent point, or jump over a goat to capture it Place a goat on any empty point, then move to adjacent points
  • Tigers and goats move along the lines of the board (horizontal, vertical, and diagonal where lines exist).
  • A tiger captures a goat by jumping over it to an empty point directly beyond, along a line.
  • Goats cannot jump or capture.
  • The goat player must place all 20 goats before moving any of them.

Prerequisites

  • C++17 compatible compiler (clang++ or g++)
  • SFML 2 — Simple and Fast Multimedia Library

macOS (Homebrew)

brew install sfml@2

Ubuntu / Debian

sudo apt install libsfml-dev

Note: On Linux, you may need to adjust the include and library paths in the Makefile (currently configured for Homebrew on macOS).

Building

git clone https://github.com/code-geek/baghchal.git
cd baghchal
make

This produces the baghchal_game executable in the project root.

To clean build artifacts:

make clean

Running

./baghchal_game

Controls

Action Keyboard Mouse
Move selector Arrow keys Hover over a point
Select / Place / Move Enter Click
Return to main menu Z

How the AI Works

The AI uses a negamax search (a variant of minimax) with several modern enhancements:

  • Bitboard representation — The 5x5 board (25 points) is encoded in a 32-bit integer for fast move generation and evaluation
  • Iterative deepening with aspiration windows — searches progressively deeper within a 2-second time limit
  • Alpha-beta pruning with Principal Variation Search (PVS)
  • Transposition table — 4M-entry Zobrist hash table avoids re-evaluating positions
  • Move ordering — killer moves, history heuristic, and countermove heuristic
  • Pruning — null move pruning, futility pruning, and razoring to cut the search tree
  • Quiescence search — extends the search for capture sequences to avoid horizon effects
  • Symmetry canonicalization — exploits the board's 8-fold symmetry to reduce the search space

The evaluation function considers tiger mobility, goat clustering, possible captures, trapped tigers, center control, and dead goats.

Project Structure

baghchal/
├── main.cpp          # Entry point
├── Game.cpp/.h       # Game loop, initialization, rendering
├── AI.cpp/.h         # AI engine (search, evaluation, bitboards)
├── Board.cpp/.h      # Board representation and point coordinates
├── Tiger.cpp/.h      # Tiger player logic and move validation
├── Goat.cpp/.h       # Goat player logic and move validation
├── Input.cpp/.h      # Keyboard and mouse input handling
├── Sprites.cpp/.h    # Sprite rendering and image management
├── MainMenu.cpp/.h   # Main menu UI and navigation
├── GameState.cpp/.h  # Position history for repetition detection
├── GameTimer.cpp/.h  # Chess clock for Human vs Human mode
├── Sound.cpp/.h      # Sound effects
├── Text.cpp/.h       # On-screen text rendering
├── Headers.h         # Shared constants and enums
├── Flags.h           # Game state flags
├── AIState.h         # AI configuration (depth, time limit)
├── SelectionState.h  # Selector/cursor state
├── DrawState.h       # Rendering flags
├── ImgManager.h      # Texture and image loader
├── images/           # Embedded image data (as header files)
├── fonts/            # Embedded font data
└── sounds/           # Embedded sound data

Roadmap

  • Non-repetition rule enforcement
  • Stronger evaluation function and deeper search
  • Faster AI move times
  • More sounds and animations
  • Cross-platform build support (CMake)

Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/my-feature)
  3. Commit your changes
  4. Push to the branch and open a pull request

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Desktop Baghchal application

Resources

License

Stars

3 stars

Watchers

2 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors