Skip to content

kavehs87/PasoorEngine

Repository files navigation

♠️ Pasoor++

Pasoor++ is a high-performance C++ engine for simulating and evaluating the Persian card game Pasoor (a.k.a. the Game of 11). It supports full rule enforcement, Soor detection, AI simulation, undo, JSON serialization, and Redis-based evaluation pipelines — making it suitable for strategy analysis, AI training, and game automation.


📦 Features

  • 🎲 Full Pasoor gameplay engine
  • 🧠 Monte Carlo–based move evaluation
  • 🕵️ Opponent hand guesstimation engine
  • 🧵 Multithreaded simulation
  • 🧪 JSON-based game state I/O
  • 📡 Redis interface for external evaluation clients
  • 🔄 Undo system with game state rollback
  • 🐳 Docker-ready environment
  • ⚙️ GCC 6 & GCC 11 compatible builds

🗂️ Project Structure

File/Dir Description
main.cpp Entry point. Listens on Redis channels and dispatches evaluations or guesses.
Game.cpp Core game logic: turn progression, scoring, Soor rules, state updates, etc.
Player.cpp Manages player hand, pile, moves, scoring, and serialization.
Deck.cpp Manages deck creation, shuffling, drawing, and weighted draws.
Card.cpp Encodes cards as integers (0–51), provides card logic and naming.
Table.cpp Tracks cards on the table and provides utilities to manipulate them.
Eval.cpp Simulates full games from every legal move to produce win-rate and Soor evaluations.
Guesstimate.cpp Estimates unknown cards in opponent’s hand based on last move.
Cache.cpp Routes Redis input to evaluation engines and publishes results.
makefile Supports GCC 6/11, debug/release builds, and modular compilation.
Dockerfile Full build environment including Redis and dependencies.
include/rapidjson Included JSON parsing library used throughout the project.

⚙️ Build Instructions

🧰 Prerequisites

  • Redis server (locally or via Docker)
  • GCC 6 or GCC 11
  • libhiredis.a, libredis++.a (included statically)
  • CMake optional (not required)

🧱 Build with Makefile

# Optimized build using GCC 6
make linux

# Debug build
make gdbc

# GCC 11 builds
make gcc11
make gcc11o3

# Build just the object files
make libs
make libs11

# Clean build artifacts
make clean

Object files are stored in lib/, and output binary is p++.


🐳 Docker Usage

A Dockerfile is provided to create a reproducible Pasoor++ environment.

docker build -t pasoor++ .
docker run --rm -p 6379:6379 pasoor++
  • Ubuntu 16.04 base
  • GCC 6 and all dependencies
  • Compiles and sets up hiredis and redis-plus-plus
  • Starts Redis and sets /var/p++/entry.sh as entrypoint

🔁 Redis Simulation Interface

Pasoor++ listens for evaluation tasks via Redis.

🔌 Incoming Channels

  • games_1 to games_10

📩 Commands

Command Description
eval Evaluate all possible moves for current player via simulation
guess Estimate the likely card(s) held by the opponent

📤 Response

  • Serialized JSON (3D vector of move evaluations or guessed cards)

🧠 Evaluation Engine

Eval (Eval.cpp)

  • Reconstructs game from JSON
  • For each legal move:
    • Simulates N games (Monte Carlo)
    • Reports average score, Soors, win rate, etc.

Guesstimate (Guesstimate.cpp)

  • Reverts the last play
  • Runs simulation to deduce what card the opponent most likely held
  • Filters out Soor-creating plays
  • Returns high-probability guesses

📄 JSON Format

[
  [deck],
  [[p1 hand], [p1 pile], ...],
  [table cards],
  [[p2 hand], [p2 pile], ...],
  current_turn,
  current_round,
  last_winner_index,
  [last played cards]
]

Use Game::dump() and Game::read() to serialize and restore this format.


🔧 Utilities & Debug

  • Game::explain() — Prints readable game state
  • Player::dumpPlay() — Logs player move
  • Deck::explain() — Prints remaining cards
  • Game::isIntact() — Validates total card count = 52

🔮 Future Enhancements

  • Multiplayer protocol over WebSocket
  • Reinforcement learning interface
  • Web-based strategy visualizer
  • Persian localization
  • Benchmarking + performance tuning options

📝 License

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

You're welcome to use, modify, and contribute to this project freely. Contributions are highly encouraged!


👤 Author

Kaveh Sarkhanlou
Pasoor++ Developer | C++ Engineer | Backend Strategist

About

C++ strategy engine for Pasoor — with AI move evaluation, Soor detection, and Redis-based analysis tools.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages