The Arena as a Game State
At the start of a game, a server creates a game state, which in essence is a structured representation of everything that is happening in an arena. Game states can be refereed as a screenshot that your device sends to the server that is constantly updated per game tick. These "screenshots" change every time a player modifies the state, for instance by placing a spell or a troop or even by not doing anything.
The Game Tick System
Several games including Minecraft, Clash Royal, run on a tick-based simulation. Calculating everything continuously can not only be resource heavy, but also lead to desync of game play between 2 or more players. To combat this, Clash Royale use a common trick that involves "Ticks". Think of a tick like a games definition of times. Every set period of time, a tick is incremented. During each tick, your device updates the server about each units movements, target selection, attacks/health lost, elixir generation, etc. By doing so, Clash Royale is not only able to maintain proper logs but also ensure gameplay remains in synchrony
Troop AI and Targeting
Every troop in the game has a very simple algorithm hard codded into it that determines its movement and attacks. Each troop has a certain rule like its detection range, what it can hit (ground troops, air troops or buildings), its priority targets (Hero mega minion ability), movement types. When a troop is placed/spawned, its algortithm searches for the nearest target that are valid for its set rules. If the target dies or another enemy becomes closer, the troop recalculates its target on the next tick.
Each troup has its own slightly different path finding movement, for example, the movement of Wizard will be different to that of a prince as prince can jump over the river thus take a shorter route. These algorithms allow troops to avoid obstacles like the river and not get stuck.
Why Everything Feels So Smooth
Even though dozens of units may be moving, attacking, and casting spells at once, the simulation remains smooth because, the game processes only essential calculations each tick, troops path finding and behavior is intentionally simple and movement and combat rules are predictable.




