Skip to content

voonhous/crforge

crforge

License Build Java 17

A headless Clash Royale battle simulator built in Java, designed for reinforcement learning and AI research. Deterministic tick-based engine with data-driven cards, a LibGDX debug visualizer, and a Python Gymnasium integration via ZMQ bridge.

Debug visualizer showing a simulated battle

Features

  • Full combat: melee, ranged, AOE, chain lightning, scatter projectiles, charge, dash, hook, reflect, shields, death spawn, burst attacks
  • Status effects: stun, slow, rage, freeze with multiplier-based stacking
  • Level scaling: rarity-based iterative growth matching the original game's formulas
  • Component-Entity-System: entities hold data, systems hold logic
  • Community card data: >100 troops, spells, and buildings loaded from JSON with automatic reference resolution

Quick Start

Requirements: Java 17

# Build
export JAVA_HOME=$(/usr/libexec/java_home -v 17)
./gradlew build

# Run tests
./gradlew :core:test :data:test

# Run debug visualizer
./gradlew :desktop:run

# Run gym bridge server (default port 9876)
./gradlew :gym-bridge:run

macOS: The visualizer needs -XstartOnFirstThread. The Gradle task handles this; add it to VM options if running from an IDE.

Python / RL Training

Requirements: Python 3.10+, Java bridge server running

pip install -e python/
python python/examples/run_episodes.py
from crforge_gym import CRForgeEnv

env = CRForgeEnv()
obs, info = env.reset(seed=42)

while True:
    action = env.action_space.sample()
    obs, reward, terminated, truncated, info = env.step(action)
    if terminated or truncated:
        break

env.close()

Modules

Module Description
core Headless simulation engine -- entities, systems, match logic
data Card/unit/projectile config loading from JSON into typed objects
desktop LibGDX debug visualizer for watching and interacting with matches
gym-bridge ZMQ server + Python Gymnasium environment for RL training

core has no GUI dependencies. data depends on core. desktop and gym-bridge depend on both.

Docs

Document Description
Simulation & Entities Tick loop, entity lifecycle, entity types
Arena, Match & Economy Arena layout, placement, win conditions, elixir, hand
Targeting, Combat & Abilities Target locking, attack pipeline, 10 ability types
Card Data Schema JSON schema, loading pipeline, reference resolution
Python Gymnasium Bridge ZMQ transport, observation/action spaces, rewards

See docs/architecture.md for the full documentation index.

Tools

Tool Description
Formation Visualizer Tkinter app for viewing and editing multi-unit spawn formation offsets

Code Style

This project uses Google Java Format enforced via Spotless. Formatting is checked on build:

./gradlew spotlessApply

Acknowledgements

This project was inspired by scholarlygaming's Clash Royale engine, the first somewhat complete open-source Clash Royale simulation engine.

Disclaimer

This is an independent fan project created for educational and research purposes. It is not affiliated with, endorsed by, or associated with Supercell. "Clash Royale", "Supercell", and related names and imagery are trademarks of Supercell Oy. See NOTICE for full attribution.

License

Licensed under the Apache License 2.0.

About

Headless Clash Royale battle simulator in Java for RL/AI training, with LibGDX debug visualizer

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors