cd /news/artificial-intelligence/show-hn-watch-a-neural-net-learn-cla… · home › topics › artificial-intelligence › article
[ARTICLE · art-143161] src=itzik123.github.io ↗ pub= topic=artificial-intelligence verified=true sentiment=↑ positive

Show HN: Watch a neural net learn Clash Royale defense in the browser

An open-source project called ClashRoyaleAi published a browser demo in which a neural network with a few thousand weights, trained with the REINFORCE policy-gradient method, learns to place a single defending card against five scripted Clash Royale attacks. The demo runs the project's C++ battle simulator, which models more than a hundred cards tick by tick, compiled to WebAssembly so every try is scored locally in the browser; the network picks a legal cell and a delay of 0 to 5 seconds, and its reward is the share of no-defence tower damage prevented. The full agent, which uses a convolutional and recurrent network trained with PPO on one laptop CPU with no GPU, plays complete three-minute matches with a four-card hand and an elixir economy and takes days to train.

read3 min views1 publishedOct 1, 2026

A neural net learns to defend, live in your browser

Matchup

Attacker

Your defender

No defence

Random drop

Best possible

Measured by trying every cell and every delay on the five attacks below.

Drag onto the board

1Your turn

2AI's turn

3Results

Defend it yourself

Five attacks. Drag your card onto the board to drop it, where and when you like. Each round scores the share of tower damage you prevented.

Watch it learn

It starts knowing nothing. Each try, the engine drops the attacker somewhere new, the network picks a cell and a moment, and the engine reports the damage.

Tries0

Per second0

Time0.0s

Drag the red attacker on the board: the heatmap shows where the network would drop your defender.

Same five attacks

Damage prevented on the five attacks

An interactive demo

Can you out-think a neural network that has never seen the game?

1

Pick a matchup. An enemy attack heads for your tower. You get one defending card.

2

Defend it yourself. Drag the card onto the board. Where you drop it and when both count. Optional.

3

Watch a network learn it. It starts from zero. A real Clash Royale simulator, written in C++ and compiled to WebAssembly, scores every try right here in your browser.

Takes about two minutes, with a ten-second how-to-play demo first if you want one. Works with a mouse or a finger.

How it works

The engine. The arena, the troops, the towers and every hit are simulated by the project's C++ engine, the same code the full agent trains against, compiled to WebAssembly. It is deterministic: the same drop always gives the same result.

The problem. The attacker is dropped at a random spot on the enemy side (a Goblin Barrel is thrown at a random spot around one of your towers). The network chooses a legal cell for your defender, then a delay from 0 to 5 seconds. The reward is the share of the no-defence tower damage it prevented. Your defender's health counts only as a tie-breaker: of two drops that save exactly as much of the tower, it prefers the one that keeps its card alive, and it never gives up a single tower hit point to do so. The score on the page is the damage prevented alone, for you and for it.

The network.A few thousand weights in plain JavaScript, no ML library: the attacker's position goes in, a map of cell preferences and a delay choice come out. It learns with REINFORCE, the simplest policy-gradient method: tries that beat the usual result for that spawn become more likely.

The honest part. This is a miniature. The real agent picks from a hand of four cards with an elixir economy, every second of a three-minute match, and needs days of training.

Game over

Game over

What you just played is a small corner of ClashRoyaleAi, an open-source project to teach a neural network to play Clash Royale.

The engine. A Clash Royale battle simulator written in C++, with more than a hundred cards, played out tick by tick. The same code scored every try on this page, compiled to WebAssembly.

The agent. A network with a convolutional eye and a recurrent memory, trained with PPO, that plays whole three-minute matches: a hand of four cards, an elixir bar, every second a decision. It learns against scripted teachers first, then against past versions of itself.

The hardware. One laptop CPU, no GPU. A training run takes days.

── more in #artificial-intelligence 4 stories · sorted by recency
── more on @clashroyaleai 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/show-hn-watch-a-neur…] indexed:0 read:3min 2026-10-01 · —