FAQ¶
The questions everyone asks. No question is too basic: if yours isn't here, ask on Discord. If you're looking at an error message, go to It Doesn't Work instead.
The Basics¶
What is this?¶
A way to make a Clash Royale bot on your own computer. Your bot can copy real players, from thousands of real games. It can also learn by trial and error in practice battles, rewarded for what you choose, like winning or taking towers. For a bot that plays like a person, start by copying players: see Cloning a Bot.
Do I need the game or a phone?¶
No. The battles run in a copy of the game's battle engine, on your computer. You don't need the game, any game files or an account.
Can my bot play real matches?¶
Yes, on Nulls Royale, a fan-run Clash Royale server. RoyaleBot plays a bot you made with RoyaleGym there, card by card. Playing on Nulls Royale shows how to train for it and set it up.
We show our own bots' ladder results as a benchmark of what a bot can do. You can play against them yourself: ask in the Discord for a 1v1.
Will this get me banned?¶
RoyaleGym never touches the game, your account or Supercell's servers, so there's nothing to ban.
What computer do I need?¶
- Windows 10 or 11, Linux, or a Mac with Apple silicon (M1 or newer), with Python 3.12.
- About 5 GB of free disk space, most of it for PyTorch.
- 16 GB of memory (RAM) or more. Training with the quickstart's settings can use around 10 GB.
- To train at a useful speed, an NVIDIA graphics card: a GTX 16-series, an RTX 20-series, or anything newer. GTX 10-series and older cards don't work with the PyTorch it uses.
- A fast processor helps too, because the battles run on it.
Intel Macs can't install the PyTorch RoyaleGym needs, so RoyaleGym doesn't run on them.
If you have a PC with an NVIDIA card and a Mac, use the PC.
Can I use it without an NVIDIA graphics card, or on a Mac?¶
Yes, but training runs on the processor instead, which is far slower. RoyaleGym doesn't use Apple's graphics chip, so a Mac always trains on its processor. Everything else (running battles, writing rewards, the viewer) works the same.
Can I use Google Colab or a rented GPU?¶
We haven't tested Colab. A rented Linux machine with an NVIDIA card works like any Linux
computer: follow Install in its terminal. It has no screen, so watch your bot by
saving battles with watch.py and opening them on your own computer (see
No window appears at all).
Do I need to know Python or machine learning?¶
You need to be able to run a Python file and change a line in it. You don't need to know any machine learning. The Quick Start shows you everything step by step, and the terms page explains the words in plain language.
Is it free?¶
Yes. It's open source, under the MIT license.
Training¶
I ran the quickstart. What am I looking at?¶
One line each time the bot learns from a batch of battles. The number to watch is crowns:
crowns taken minus crowns lost, per battle. If it goes up over time, your bot is learning. It
jumps up and down from line to line, so look at the trend over 20 lines or more. It starts above
zero because the random bot waits 9 moves out of 10, and near +3 your bot beats it 3-0 almost
every time. Every column is explained in What You'll See.
How long until my bot is any good?¶
It depends on how it learns. The Quick Start's bot starts from nothing and learns only by trial and error. It learns to beat a bot that plays at random, and on one computer it seldom gets much further, even after days. To see a bot that plays like a person, start by cloning human players: your bot copies the moves people made in real games.
You can then train the clone further by trial and error. That's harder than it sounds, and it can make the bot worse as well as better. So test the new bot against the scripted bots the same way you tested the clone, and compare the two (see How do I know how good my bot is?).
Should I clone a bot or train one from nothing?¶
Do the Quick Start first: training from nothing is the best way to learn how RoyaleGym works. Then, for a bot that plays like a person, start it from a clone, not from nothing. A bot that learns only by trial and error, from nothing, doesn't get far. A clone starts out playing like the players it copied.
How do I watch it play?¶
While it trains, open a second terminal, turn on the virtual environment and run royaleviser.
A window shows one of its battles live. See Watch It Play.
How do I stop training and carry on later?¶
Press Ctrl+C once in the training terminal (Control+C on a Mac too), and wait. It finishes the update it's on, saves, and stops. Run the same command again to carry on where it stopped. See Stop and Carry On.
How do I start over?¶
Delete the runs\quickstart folder (Remove-Item -Recurse runs\quickstart in PowerShell,
rm -r runs/quickstart on a Mac or Linux), or change save_dir in quickstart.py to a new
name.
Is it OK to leave it running overnight, or for days?¶
Yes. It's like running a demanding game for that long: the fans get loud, and that's normal. Keep a laptop plugged in with the lid open, and turn off sleep while it trains. If the computer restarts, run the script again and it carries on from its last save. There's a checklist in How Long Should I Leave It?
How much disk space does a bot take?¶
Not much. Each save is a few megabytes, and it keeps only the newest three. Training against
itself (opponent="self") also keeps a few older versions of your bot to play against.
Can I train two bots at once?¶
Yes, if your computer can keep up: give each its own save_dir. Only one of them can stream to
the viewer at a time, so set viser=False in the other.
Why does my bot do nothing?¶
A brand new bot picks its moves almost at random, and waiting is one of its choices. So at first it often waits a lot, or plays cards in odd places. That's normal, and it changes as it learns.
If it still mostly waits after hours of training, look at your reward. If it only gets paid for winning, it hardly ever sees a reward at all, so it has nothing to learn from. Rewards for crowns and tower damage, like the quickstart's, pay out much more often.
Why does my bot spam one card?¶
It found something your reward pays for, and it's doing it as often as it can. Look at what the
reward pays: a reward for playing cards, for example, teaches it to play cards, any cards,
anywhere. Change the reward, or train a new bot against copies of itself (opponent="self", with
a new save_dir), so a trick that beats a weak opponent stops working.
Why does crowns stay near zero?¶
If it plays against itself (opponent="self"), both sides get better together, so neither wins
more. That's expected. Watch it play to see whether it's improving. After a few million steps,
the file metrics.jsonl in your save_dir also records a rating, ladder/rating_above_v0: how
much stronger it is than its first saved version, in Elo points. +100 means it wins about 64% of
its games against that first version.
How do I make it use my deck?¶
Change the deck = [...] line in quickstart.py to your eight cards, and use a new save_dir
there and in watch.py. See Use Your Own Deck. Card names
have no spaces, except Elixir Collector; the full list is in
Game Values.
Can it use evolutions, heroes and champions?¶
Most of them: 42 evolutions, 16 heroes and every champion. The lists are in Game Values, and Evolutions and heroes shows how to add them to your deck.
What level are the cards? Can I pick a tower troop?¶
Every card and tower is level 11, the tournament standard. The towers are the normal Princess Towers; tower troops aren't in RoyaleGym.
Can the opponent use a different deck?¶
Yes: DefaultStateMutator(decks=[my_deck, other_deck]). Your bot then plays both sides at
random, so it learns both decks. In the quickstart, both sides use your deck.
What's a reward, and how do I change it?¶
The reward is a score your bot gets after every move. It learns to do whatever makes that score
high, so the reward is how you tell it what you want. In quickstart.py it's the reward_fn
lines. See Change What It Learns, and
Reward Functions to write your own.
What do all the settings in Learner(...) mean?¶
Each line in quickstart.py has a short comment. The RoyaleLearn
page lists every setting and its default, and the terms page explains
the words. You can leave most of them at their defaults.
How do I make training faster?¶
First make sure PyTorch can see your graphics card (see It Doesn't Work).
The battles take turns on one processor core, so the processor won't show near 100%, and a
faster core helps more than more cores. Playing more battles at once (n_envs) lets the
graphics card work on many of them together, which is why the quickstart plays 32. n_envs is
fixed for a run: to try another number, start a new bot with a new save_dir.
Can I see graphs of how it's doing?¶
Yes, with Weights & Biases, a free website for charts. Make an account at
wandb.ai, run pip install wandb and then wandb login once (with the
virtual environment on), and set log_to_wandb=True in quickstart.py.
Playing¶
What can I do with my bot once it's trained?¶
- Watch it play: live while it trains, or a whole battle later.
- Test it against the simple bots that come with RoyaleGym (see below).
- Keep training it with a new reward. Training it against itself starts a new bot in a new
save_dir. - Keep a copy of its folder in
runs: that's your bot, with everything it has learned.
How do I share my bot, or a battle?¶
Send your bot's folder from runs. Your friend loads it with Learner.load_policy("that folder")
and plays it with the same deck, as in watch.py. They can't carry on training it on their
computer. To share a battle, send the .msgpack file that watch.py saves; they open it with
royaleviser FILE. To make a video of it, see
No window appears at all.
Sharing a bot's files publicly (its folder, or its battle files) is fine for bots weaker than what
it takes to reach Ranked. A bot strong enough for Ranked (15,000 trophies and up) that anyone can
download becomes a cheating tool on Supercell's ladder, so those bots stay private. Their results,
videos and clips are fine to share. Before you share a bot's files, check it in the
Discord: type /checkbot in #bot-talk and attach its saved folder as
a zip. It reads the deck your bot trained with from the folder. It plays against a fixed reference,
and you get "pass" or "too strong" by DM, usually within an hour.
Can I play against my bot?¶
Not yet. You can watch it play against other bots, or against itself.
How do I know how good my bot is?¶
Watch it play, and test it against the simple bots that come with RoyaleGym. Save this as
how_good.py next to quickstart.py and run python how_good.py. It takes a few minutes:
from royalegym import CallableOpponent, evaluate, ladder
from royalelearn import Learner
from quickstart import build_env
bot = Learner.load_policy("runs/quickstart")
me = CallableOpponent(lambda obs, mask: bot(obs))
for name, opponent in ladder():
print(evaluate(me, opponent, build_env, games=50, names=("my bot", name)).summary())
Each line says how many battles it won and whether it's clearly better or "too close to call". A good bot clearly beats every bot on the list, not just the random one. More about this on Opponents.
The Game¶
Is it exactly like the real game?¶
Close, but not exact. The engine is checked against recordings of real battles, and most cards behave the same. Some details are still being matched, and the engine keeps improving.
Which cards are in it?¶
Most cards you can use in ladder battles. The list is in Game Values.
How do I remove everything?¶
First, with the virtual environment on, run pip cache purge: pip keeps its own copy of
everything it downloaded, PyTorch included, outside your folder. Then delete your royale
folder. That removes RoyaleGym, PyTorch and your bots. If you cloned human players, also delete
the .cache\huggingface folder in your user folder (~/.cache/huggingface on a Mac or Linux):
the downloaded games are there. If you don't need Python any more,
uninstall it too (on Windows: Settings > Apps > Installed apps > Python > Uninstall).
What happens when Clash Royale updates?¶
New cards and balance changes reach RoyaleGym in a new version of the engine. To update, run
this. Updating from v0.1.1 or earlier? Run pip uninstall -y pygame first: the viewer now uses
pygame-ce in its place.
It updates RoyaleGym, brings the other four packages up to at least the versions that release needs, and leaves your PyTorch alone. The engine can update between RoyaleGym releases. This gets the newest one:
Your code keeps working, but a bot can't carry on training across an update: start a new one with
a new save_dir. If RoyaleGym then refuses the new engine, it's too old for it: run the first line
too.