An open API service indexing awesome lists of open source software.

https://github.com/rabestro/dicechess-engine-scala

High-performance parallelized Expectimax game engine and probability calculator for Dice Chess, written in Scala 3.
https://github.com/rabestro/dicechess-engine-scala

artificial-intelligence bitboard chess-engine dice-chess expectimax functional-programming game-engine scala scala3 virtual-threads

Last synced: 13 days ago
JSON representation

High-performance parallelized Expectimax game engine and probability calculator for Dice Chess, written in Scala 3.

Awesome Lists containing this project

README

          

# Dice Chess Engine (Scala) πŸŽ²β™ŸοΈ

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=rabestro_dicechess-engine-scala&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=rabestro_dicechess-engine-scala)
[![CI Pipeline](https://github.com/rabestro/dicechess-engine-scala/actions/workflows/ci.yaml/badge.svg)](https://github.com/rabestro/dicechess-engine-scala/actions/workflows/ci.yaml)
[![Play Live](https://img.shields.io/badge/Play-Live-success)](https://dc.jc.id.lv/)
[![Architecture Docs](https://img.shields.io/badge/Docs-Architecture-orange)](https://jc.id.lv/dicechess-engine-scala/)
[![Scaladoc API](https://img.shields.io/badge/Scaladoc-API-blue)](https://jc.id.lv/dicechess-engine-scala/api/)

An open-source, high-performance game engine and probability calculator for **Dice Chess**, built with **Scala 3**.

This engine is designed to calculate win probabilities, evaluate board positions, and suggest the best sequences of micro-moves based on stochastic search algorithms (Expectiminimax or Monte Carlo Tree Search).

---

## πŸ“– Dice Chess Rules & Turn Structure

Dice Chess is a stochastic variant of chess where players must roll a 6-sided die before making their moves.

### Core Concepts:
1. **The Turn Structure**:
* A player's turn consists of **1 Dice Roll** and **up to 3 micro-moves**.
* The active color in the FEN **does not change** within the turn (i.e., during the 1st, 2nd, or 3rd micro-moves). It only changes when the turn ends (after 3 micro-moves, or when no legal moves are available / the player decides to pass).

2. **The Dice Roll**:
* The die determines which pieces are allowed to move:
* `1` = Pawn (β™™)
* `2` = Knight (β™˜)
* `3` = Bishop (β™—)
* `4` = Rook (β™–)
* `5` = Queen (β™•)
* `6` = King (β™”)

3. **Micro-moves**:
* You can move **different pieces** or the **same piece** multiple times during your turn, as long as each piece's type matches the rolled die.
* If you roll a `3` (Bishop), you can make up to 3 separate bishop moves.
* **Victory Condition**: The game is won by **capturing the opponent's king** directly (there is no traditional check/mate, as the king can be captured on the next micro-move).
* **Maximum Micro-moves**: Players must play moves that maximize the total number of micro-moves played in their turn. See our detailed [Maximum Micro-moves Rule Algorithm](docs/src/content/docs/architecture/move-generation/05-maximum-micromoves.md) guide for the mathematical formulation and pseudocode.

---

## πŸ› οΈ Tech Stack

* **Language**: Scala 3 (leveraging modern enums, case classes, and type safety)
* **Concurrency**: Cats Effect 3 / ZIO (for high-performance parallel tree search)
* **API Framework**: Tapir / Http4s (exposing lightweight REST endpoints)
* **Build Tool**: sbt (Simple Build Tool)

---

## πŸ—ΊοΈ Pre-Hackathon & Hackathon Roadmap

```
[Phase 0: Pre-Hackathon - 2 Months Prep]
β”œβ”€β”€ Setup repository structure & Domain Models (Scala 3)
β”œβ”€β”€ Write a FEN Parser for Dice Chess
└── Define & implement basic API endpoints (mock responses)

[Phase 1: Hackathon Day 1 - Morning]
β”œβ”€β”€ Core Move Generator (handling the 3 micro-moves sequence)
└── Basic Greedy/Random evaluation

[Phase 2: Hackathon Day 1 - Afternoon & Night]
β”œβ”€β”€ Search Engine implementation (Expectimax or MCTS)
└── Position Evaluation Function (Material, Position, Mobilty)

[Phase 3: Hackathon Day 2 - Morning]
β”œβ”€β”€ Integration of HTTP API with the main PWA Client
└── Performance profiling and bug fixing

[Phase 4: Hackathon Day 2 - Afternoon]
└── Demo preparation, benchmarks, and final presentation!
```

---

## πŸ”Œ API Contract (JSON)

### 1. Suggest Best Move
`POST /api/v1/engine/suggest`

#### Request
```json
{
"dfen": "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 P",
"depth": 3
}
```

#### Response
```json
{
"suggested_turn": {
"dfen_after_turn": "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - 0 1 P",
"micro_moves": [
{ "from": "e2", "to": "e4" },
{ "from": "d2", "to": "d4" }
]
},
"evaluation": {
"win_probability": 0.545,
"score_cp": 45
},
"nodes_searched": 1420500,
"time_ms": 120
}
```

---

## πŸ“š Documentation & API Reference

* **[Live Web App](https://dc.jc.id.lv/)**: Play Dice Chess against our engine's active search algorithms in a premium Svelte PWA environment.
* **[Architecture & Developer Guide](https://jc.id.lv/dicechess-engine-scala/)**: Read about our Zero-Cost Abstractions, Hybrid Mailbox, and Milestone roadmap.
* **[Scaladoc API Reference](https://jc.id.lv/dicechess-engine-scala/api/)**: Comprehensive technical API documentation automatically generated from our codebase.

---

## πŸš€ Getting Started

Ensure you have [mise](https://mise.jdx.dev/) installed for orchestrating the developer environment.

```bash
# Clone the repository
git clone https://github.com/rabestro/dicechess-engine-scala.git
cd dicechess-engine-scala

# Installs all required tooling (JDK, Scala CLI, SBT, Formatting tools)
mise install

# Run the test suite and formatter checks
mise run check

# Open the interactive Scala 3 REPL loaded with the project
mise run console
```

---

## βš–οΈ License

This project is licensed under the **GNU Affero General Public License v3.0 (AGPL-3.0)**.