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.
- Host: GitHub
- URL: https://github.com/rabestro/dicechess-engine-scala
- Owner: rabestro
- License: other
- Created: 2026-05-06T20:40:56.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2026-05-30T15:37:32.000Z (13 days ago)
- Last Synced: 2026-05-30T16:09:59.246Z (13 days ago)
- Topics: artificial-intelligence, bitboard, chess-engine, dice-chess, expectimax, functional-programming, game-engine, scala, scala3, virtual-threads
- Language: Scala
- Homepage: https://jc.id.lv/dicechess-engine-scala/
- Size: 896 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Agents: AGENTS.md
Awesome Lists containing this project
README
# Dice Chess Engine (Scala) π²βοΈ
[](https://sonarcloud.io/summary/new_code?id=rabestro_dicechess-engine-scala)
[](https://github.com/rabestro/dicechess-engine-scala/actions/workflows/ci.yaml)
[](https://dc.jc.id.lv/)
[](https://jc.id.lv/dicechess-engine-scala/)
[](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)**.