Preprint
Article

This version is not peer-reviewed.

Modeling and Experimental Analysis of Troop Pathfinding and Target Selection Algorithms in Clash of Clans–Style War Scenarios

Submitted:

30 January 2026

Posted:

30 January 2026

You are already at the latest version

Abstract
Pathfinding and target selection algorithms play a critical role in real-time strategy and mobile games, directly influencing gameplay balance, fairness, and player skill expression. Unlike traditional shortest-path algorithms such as A*, many commercial games intentionally employ simplified or constrained pathfinding to preserve strategic depth. This paper presents a modeling and experimental analysis of troop pathfinding and target selection behavior inspired by Clash of Clans, with a focus on Clan War attack scenarios involving troop movement toward Town Halls and defensive structures. Since the internal implementation of Clash of Clans is proprietary, this study proposes a behavioral approximation model based on observable in-game mechanics. A hybrid algorithm combining greedy nearest-target selection, local obstacle-aware movement, and priority-based cost functions is designed and evaluated. Multiple simulated base layouts with varying densities and wall configurations are tested. Results show that intentionally non-optimal pathfinding enhances game balance, prevents deterministic outcomes, and promotes strategic base design. The study follows the IMRAD structure and applies standard experimental game AI research methodologies.
Keywords: 
;  ;  ;  

1. Introduction

Artificial intelligence (AI) algorithms are essential components of modern digital games, governing non-player character (NPC) behavior such as movement, combat decisions, and interaction with dynamic environments. In many contemporary games, especially those within the strategy genre, AI systems are responsible for automating complex actions that would otherwise require constant player input. Among these actions, troop movement and navigation are particularly critical, as they directly affect player experience, perceived fairness, and competitive balance [1]. Poorly designed movement algorithms can lead to frustrating gameplay, while overly efficient algorithms may remove strategic depth and reduce player agency.
In academic research, pathfinding is often studied through optimal algorithms such as A*, Dijkstra’s algorithm, and their variants. These algorithms are designed to compute the shortest or least-cost path between two points in a graph-based environment. While such approaches are mathematically sound and widely used in theoretical studies, their direct application in commercial games is not always desirable. Perfect pathfinding can produce predictable and deterministic outcomes, making gameplay less engaging and limiting the impact of player strategy. As a result, many commercial games deliberately constrain or simplify pathfinding behavior to support balanced and enjoyable gameplay.
Clash of Clans is a globally popular mobile strategy game that combines base-building, resource management, and real-time combat. A defining feature of the game is its automated combat system, particularly during Clan Wars, where players deploy troops that independently navigate enemy bases. Once deployed, players have no direct control over troop movement; instead, all navigation and targeting decisions are handled by the game’s AI system. Troops move through bases, interact with walls and defenses, and attack buildings such as defensive structures and the Town Hall based entirely on internal decision-making logic [2].
Unlike traditional player-controlled movement systems, troop behavior in Clash of Clans relies on a combination of pathfinding and target selection rules. Troops do not simply move toward the Town Hall along the shortest possible route. Instead, they prioritize nearby buildings according to troop-specific targeting rules, environmental constraints, and obstacle placement. This design choice allows players to influence troop behavior indirectly through base layout, wall configuration, and building placement, rather than through real-time control.
A key design philosophy underlying Clash of Clans is the prioritization of game balance over algorithmic optimality. By avoiding globally optimal pathfinding, the game encourages strategic base design and meaningful decision-making on both offense and defense. Walls, funnels, and layered defenses become critical tools for shaping troop movement, creating opportunities for skilled players to outplay opponents through intelligent layout design rather than relying solely on troop strength or numerical superiority.
The objective of this research is to model and experimentally analyze Clash of Clans–style troop pathfinding and target selection behavior using a formal algorithmic framework. Since the internal implementation of the game’s AI is proprietary, this study focuses on behavioral approximation based on observable in-game mechanics. By designing controlled experiments and evaluating different base layouts and cost-function parameters, this paper demonstrates how intentionally non-optimal AI behavior contributes to balanced and engaging gameplay. Ultimately, the study aims to bridge the gap between academic pathfinding research and practical game AI design, highlighting the importance of balance-driven algorithms in commercial strategy games.

3. Algorithm Design and Formal Model

3.1. Behavioral Approximation and Hybrid Decision Model

The internal artificial intelligence implementation of Clash of Clans is proprietary and not publicly accessible. Consequently, this study does not attempt to reverse-engineer or replicate the game’s source code. Instead, a behavioral approximation model is proposed, derived from observable in-game troop behavior, official documentation, and publicly available developer discussions. This approach is consistent with established academic practice when analyzing commercial games with closed-source implementations.
The proposed model represents troop behavior as a hybrid decision-making process that separates what a troop chooses to attack from how it moves toward that target. Rather than computing a global path to a fixed objective, troop behavior is modeled as a sequence of local decisions that evolve dynamically during an attack. Specifically, the model consists of three tightly coupled components: target selection, local movement, and dynamic retargeting.
In the target selection stage, troops evaluate nearby buildings according to predefined rules based on troop type and building category. Once a target is selected, the troop performs local, obstacle-aware movement toward that target. After the destruction of a building, the decision process repeats, allowing the troop to dynamically retarget based on the updated environment. This hybrid structure avoids global path planning while maintaining responsive and predictable behavior, aligning with design principles commonly observed in mobile strategy games. The proposed model uses a hybrid target selection and pathfinding approach. Each target t is evaluated using the cost function:

3.2. Target Cost Function and Local Movement Strategy

To formalize the target selection process, each potential target t is evaluated using a weighted cost function:
C ( t ) = α D ( t ) + β W ( t ) + γ P ( t )
where:
  • D ( t ) represents the Euclidean distance between the troop and the target
  • W ( t ) denotes wall resistance or obstacle cost encountered along the path
  • P ( t ) is a priority value assigned to the target (e.g., defensive structure, resource building, or Town Hall)
  • α , β , γ are tunable weights that control the influence of each factor.
Targets with the lowest cost value are selected for engagement. This formulation captures the observed behavior in Clash of Clans, where troops do not simply attack the most important objective, such as the Town Hall, but instead prioritize nearby and accessible structures depending on troop-specific rules. By adjusting the weighting parameters, the model can represent different troop behaviors while maintaining deterministic and interpretable decision-making.
Once a target has been selected, troop movement is governed by a local obstacle-aware navigation strategy rather than full-map pathfinding. Troops advance toward the target while responding to immediate obstacles such as walls. If a wall blocks the direct path, the troop attacks the wall instead of searching for an alternative global route. After each building or obstacle is destroyed, movement direction is recalculated locally. This strategy significantly reduces computational complexity and ensures real-time responsiveness, which is critical for mobile platforms and large-scale attacks involving many units.
where D ( t ) is distance, W ( t ) represents wall resistance, and P ( t ) denotes target priority.

4. Research Methodology

This section describes the experimental design used to evaluate the proposed Clash of Clans–style troop pathfinding and target selection model. The methodology focuses on creating a controlled simulation environment, defining experimental variables, and applying systematic testing procedures to ensure fairness, repeatability, and meaningful comparison across scenarios [7].

4.1. Please Add Title

A custom grid-based simulation environment was created to represent Clash of Clans–style war bases. The environment abstracts key gameplay elements while preserving the structural features that influence troop behavior. This approach allows controlled experimentation without relying on proprietary game code [8].
The simulated environment includes the following components:
Walls Walls are modeled as blocking structures that increase traversal cost and may require direct destruction before troops can proceed. Wall placement is a critical factor in shaping troop movement, as it determines whether troops attack obstacles or reach interior buildings directly.
Defensive Buildings Defensive structures represent high-priority targets that influence troop targeting behavior. These buildings are strategically placed to simulate realistic war base layouts and to observe how troops respond to nearby threats and defensive density.
Resource Buildings Resource buildings act as low- to medium-priority targets. Their inclusion allows the simulation to capture diversion effects, where troops are drawn away from the Town Hall due to proximity-based target selection.
Town Hall Core The Town Hall is positioned at the core of the base and represents the primary strategic objective. Its placement allows analysis of how base design and wall complexity delay or prevent direct access by attacking troops.

4.2. Experimental Variables and Testing Procedures

The experiments were designed by systematically varying base characteristics while keeping troop properties constant. This controlled approach enables clear observation of how environmental complexity influences troop behavior and algorithm performance.
The following experimental variables were tested:
Base Density Base density describes the overall compactness of buildings within the layout and was categorized as sparse, medium, or compact. Sparse bases provide more open paths, while compact bases increase the likelihood of wall interactions and target diversion.
Wall Complexity Wall complexity refers to how walls are arranged within the base. Low-complexity layouts use minimal walls, maze-like layouts create indirect paths, and layered layouts introduce multiple defensive rings. This variable directly affects wall resistance and local movement decisions.
Troop Type A generic melee troop was used in all experiments. This troop type prioritizes nearby buildings and directly attacks blocking walls, making it well suited for studying the interaction between target selection and obstacle-aware movement.
To evaluate algorithm behavior under these conditions, the study applied the following testing methods:
Black-box Testing The algorithm was evaluated based solely on observable inputs and outputs, without inspecting internal decision states. This mirrors real-world analysis of commercial games with proprietary AI implementations.
Scenario-based Testing Each base configuration represents a distinct scenario designed to test specific behaviors, such as funneling effectiveness or wall-induced path diversion.
Stress Testing Compact bases with layered walls were used to examine algorithm performance under high-complexity conditions, where local decision-making is repeatedly triggered.
Repeatability Testing Each scenario was executed five times to ensure consistent outcomes and to reduce the impact of incidental variation. Results were averaged to improve reliability.
This combination of controlled variables and systematic testing methods ensures that observed outcomes can be attributed to algorithmic behavior rather than random variation or uncontrolled factors.

5. Experiments and Results

This section presents the results of the experimental evaluation of the proposed Clash of Clans–style troop pathfinding and target selection model. Each experiment focuses on a specific factor that influences troop behavior, including base layout density, target priority weighting, and the trade-off between balance and optimality. The results are presented in a simple and interpretable manner to highlight their impact on gameplay balance.

5.1. Experiment 1: Base Density Impact

This experiment examined how base density affects troop movement and attack outcomes. Three base layouts were tested: sparse, medium, and compact. In sparse bases, buildings were spread out with fewer walls. In compact bases, buildings were tightly packed and surrounded by multiple wall layers.
Table 2. Base Density vs Attack Outcome.
Table 2. Base Density vs Attack Outcome.
Base Type Time to Town Hall Walls Destroyed Success
Sparse Short Low Yes
Medium Medium Medium Yes
Compact Long High Sometimes
Observation:
Compact bases significantly delay troop progress and increase wall interactions. As base density increases, troops spend more time attacking walls and nearby buildings before reaching the Town Hall. This demonstrates how base layout design can strongly influence troop behavior without changing troop.

5.2. Experiment 2: Priority Weight Variation

This experiment analyzed the effect of changing the priority weight ( γ ) in the target selection cost function. The priority weight controls how strongly troops prefer high-value targets such as defensive buildings or the Town Hall [9].
When the priority weight was increased, troops were more likely to ignore nearby buildings and instead move toward high-priority targets. While this behavior sometimes allowed faster access to important structures, it also caused troops to take longer paths and engage more defenses along the way.
Figure 2. Priority-based target selection in Clash of Clans, where the troops wall breaker and the wall met the required to break it.
Figure 2. Priority-based target selection in Clash of Clans, where the troops wall breaker and the wall met the required to break it.
Preprints 196769 g002
Result:
Higher priority weights increased attack time and troop losses, indicating that overly aggressive target selection can reduce overall attack efficiency. So if we played ground troop we need to use wall breaker to break the wall to let the other troop go to attack the defense without blocking from the wall so it will save the time and lead to get three stars [10].

5.3. Experiment 3: Balance vs Optimality

The final experiment compared balanced AI behavior with a purely optimal pathfinding approach. In this scenario, wall resistance ( β ) was set to zero, allowing troops to effectively follow the shortest possible path to the Town Hall.
Under this configuration, troops reached the Town Hall very quickly and with minimal interaction with walls or defensive structures [9].
Observation:
Although optimal pathfinding improved attack efficiency, it resulted in unbalanced gameplay. Defensive base design became less effective, and strategic wall placement lost its importance. This result explains why Clash of Clans intentionally avoids pure shortest-path algorithms in favor of constrained, balance-oriented AI behavior.

6. Conclusion

This study analyzed troop pathfinding and target selection algorithms inspired by Clash of Clans–style war scenarios, focusing on balance-oriented AI design rather than optimal pathfinding. By modeling observable troop behavior and conducting controlled experiments, the research showed that base layout, wall complexity, and target priority significantly influence attack outcomes.
The results demonstrate that intentionally constrained AI behavior enhances strategic gameplay by allowing players to influence troop movement through base design. Comparisons with pure shortest-path navigation further revealed that optimal pathfinding can lead to unbalanced gameplay and reduce defensive relevance. Overall, this work supports the view that effective game AI prioritizes player experience and balance over mathematical optimality and provides a practical framework for analyzing AI behavior in commercial strategy games.

References

  1. Millington, I.; Funge, J. Artificial Intelligence for Games, 2 ed.; CRC Press: Boca Raton, FL, USA, 2009.
  2. Clash of Clans Wiki: Game Mechanics Overview. https://clashofclans.fandom.com. Accessed: 2026-01-18.
  3. Yannakakis, G.N.; Togelius, J. Artificial Intelligence and Games; Springer: Cham, Switzerland, 2018.
  4. Hart, P.E.; Nilsson, N.J.; Raphael, B. A Formal Basis for the Heuristic Determination of Minimum Cost Paths. IEEE Transactions on Systems Science and Cybernetics 1968, SSC-4, 100–107. [CrossRef]
  5. Holmgård, C.; Togelius, J.; Yannakakis, G.N. Game Balance and Player Experience. In Proceedings of the Proceedings of the IEEE Conference on Computational Intelligence and Games (CIG), 2014, pp. 1–8.
  6. Supercell Developers. Clash of Clans AI Design. YouTube. Accessed: 2026-01-18.
  7. Designing AI for Strategy Games. https://www.gdcvault.com. Accessed: 2026-01-18.
  8. Laird, J.E.; van Lent, M. Human-Level AI’s Killer Application. AI Magazine 2001, 22, 15–26.
  9. Russell, S.; Norvig, P. Artificial Intelligence: A Modern Approach, 3 ed.; Pearson: Upper Saddle River, NJ, USA, 2016.
  10. Game Maker’s Toolkit. Why Game AI Cheats. YouTube. Accessed: 2026-01-18.
Figure 1. Clash of Clans troop behavior illustrating target selection before local movement [6].
Figure 1. Clash of Clans troop behavior illustrating target selection before local movement [6].
Preprints 196769 g001
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.
Copyright: This open access article is published under a Creative Commons CC BY 4.0 license, which permit the free download, distribution, and reuse, provided that the author and preprint are cited in any reuse.