Algorithm in RPG Games
Adaptive Generative Difficulty

Overview
This project introduces an adaptive generative difficulty algorithm that adjusts a game's difficulty based on player behavior and performance, using player modeling, playstyle inference, and adaptive adjustments. The system monitors stats such as hit rate, damage taken, resource usage, and exploration habits to fine-tune enemy behavior and abilities. This helps keep the challenge at an optimal level and make sure players stay engaged without feeling frustrated or bored. The scalability, flexibility, and capacity of the algorithm to tailor gaming experiences are also underscored.
View Full DocumentMy Role
- Programmer and Developer
Language
- Python
Tool
- Pygame
Context and Background
Video games aim to balance challenge and enjoyment, aligning with Csikszentmihalyi’s flow theory (1990). Traditional difficulty systems use static presets or manual tweaks, often missing the mark for diverse player skills and styles. Dynamic Difficulty Adjustment (DDA), seen in games like Left 4 Dead (Valve, 2008) and Resident Evil 4 (Capcom, 2005), adjusts parameters in real-time but typically lacks depth, relying on basic metrics like health or time. This Python Adaptive Generative Difficulty Algorithm (AGDA) improves DDA by considering hit accuracy, damage taken, resource usage, and discovery, inferring playstyles (defensive or aggressive). It adjusts monster stats and player skills dynamically, using momentum and trend analysis for smooth, cohesive gameplay transitions.
Research Problem & Thesis
Most DDA techniques narrowly focus on either performance (e.g., hits or damage) or behavior (e.g., aggression) without integrating both into one adaptive system. Most also cannot effectively manage gradual difficulty changes, disrupting immersion. This research tries to overcome this limitation by developing an algorithm that integrates performance metrics and inferred actions to adjust multiple game elements continuously so that the overall experience is engaging and natural and adapted to the player. The question is: How can game difficulty smoothly and finely adapt to keep pace with a player's shifting skills and habits? The goal is to illustrate this method enhances satisfaction and personalizes gaming.
Methodology & Performance Tracking
The environment setup tested the Adaptive Generative Difficulty Algorithm (AGDA) against a player and monsters with varying stats (e.g., hit points, speed, attack rate, recognize range) under a simulated game environment. The player tracker monitored hit points, hit rate, damage taken, use of resources, and exploration. Player action was simulated probabilistically according to different aggressive, defensive, or balanced playstyles, with weights like 70% attack for aggressive and 50% dodge for defensive. Each test run was 150 steps long, with AGDA dynamically adjusting difficulty step by step based on trends in performance.
AGDA continuously kept track of statistics such as the player's attack success rate (hit percentage), the damage they took (percentage of maximum health), resource use (e.g., healing items used), and depth of exploration (percentage of world discovered). These figures tracked fight and strategic moves, scribbled down each move into a 30-step history buffer. This buffer let trend analysis, such as hit accuracy or damage frequency adjustment, catch if the player was getting better or struggling.

Decision tree for AGDA's difficulty adjustment logic.
Performance Analysis

Graph showing AGDA's adaptation over 150 steps with an aggressive playstyle.
The graph provides a view of how AGDA successfully adjusts the game experience over 150 simulation steps with an aggressive playstyle, tracking Hits (green), Misses (red), Recent Damage Taken (black), and Hit Accuracy (blue).
- Early Game (Steps 0–40): The player struggles, with Recent Damage Taken peaking at 600–700 and Hit Accuracy falling from 0.6 to 0.4. The algorithm lowers difficulty, reducing damage taken to 200–300 by step 40.
- Mid Game (Steps 40–80): Hit Accuracy improves to 0.6, and Recent Damage Taken remains low at 200–300. The algorithm maintains a balanced challenge, supporting player growth.
- Late Game (Steps 80–150): Hit Accuracy rises to 0.8–0.9, and Recent Damage Taken increases to 300–500 as difficulty ramps up. The player maintains high accuracy, showing effective scaling.
Next Steps
- Multi-Player Adaptation: Adjust the algorithm to support multiple players in co-op or competitive scenarios for more dynamic gameplay.
- Granular Difficulty Scaling: Expand difficulty adjustments to include environmental threats or narrative-induced challenges.
- User Customization: Allow players to control difficulty adjustment levels to attract a broader audience.
- Real-World Testing: Integrate AGDA into a commercial game engine to validate scalability and user acceptance.
References
- Hunicke, R., & Chapman, V. (2004). "AI for Dynamic Difficulty Adjustment in Games." Proceedings of the AAAI Workshop on Challenges in Game AI.
- Adams, E. (2010). Fundamentals of Game Design (2nd ed.). New Riders.
- Abramowitz, M., & Stegun, I. A. (Eds.). (1972). Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables. Dover Publications.
- Astrom, K. J., & Wittenmark, B. (1995). Adaptive Control (2nd ed.). Addison-Wesley.
- Sutton, R. S., & Barto, A. G. (2018). Reinforcement Learning: An Introduction (2nd ed.). MIT Press.
- Yannakakis, G. N., & Togelius, J. (2018). Artificial Intelligence and Games. Springer.
- Drachen, A., Canossa, A., & Yannakakis, G. N. (2009). "Player Modeling using Self-Organization in Games."
- Gardiner, C. W. (2009). Stochastic Methods: A Handbook for the Natural and Social Sciences (4th ed.). Springer.