Improving AI through patterns and simple prediction #9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Thinking about PR #8, I tried to solve a strange problem and improve the overall behavior of the AI.
I wouldn't say I achieved everything I wanted, but the bots started shooting better and no longer circle around the player if he flies in circles all the time.
In addition, it's now really interesting to watch two bots play.
This doesn't solve the issue of the strange "low-speed-to-back" tactic of the plane, but I didn't try to solve it.
I tried to describe what I did in more detail. But I suspect that there is a more elegant way to do it, as this is my first time doing this :D
Description of changes
Core Components
1. Pattern Recognition System
Detects when opponents are stuck in predictable patterns and responds appropriately.
Key Features:
include/ai_patterns.hpp(lines 37-47) -AiPatternTrackerstructureHow Circular Pattern Detection Works:
2. Pattern Breaking Strategy
Prevents infinite circular pursuit loops by forcing AI to change course.
Breaking Conditions:
src/ai_patterns.cpp(lines 130-174) -shouldBreakCircularPattern()methodBreaking Mechanism:
src/ai_stuff.cpp(lines 940-1041) - Pattern breaking implementation3. Enhanced Combat with Movement Prediction
AI uses enhanced shooting logic with movement prediction for better accuracy in all combat situations.
Key Behaviors:
src/ai_stuff.cpp(lines 98-161) -shouldShootWithPrediction()function4. Personality System
Gives each bot unique behavioral characteristics and tactical preferences.
Core Parameters:
Personality Types:
src/ai_patterns.cpp(lines 177-227) -updateBasedOnDifficulty()method5. Tactical Strategy System
Adapts AI behavior based on personality and tactical situation.
Strategy Selection Logic:
Defensive Strategy (when to use):
Defensive Behavior:
src/ai_patterns.cpp(lines 248-266) -shouldUseDefensiveStrategy()methodAggressive Strategy (when to use):
Aggressive Behavior:
src/ai_patterns.cpp(lines 229-266) -shouldUseAggressiveStrategy()methodsrc/ai_stuff.cpp(lines 1087-1100) - Aggressive behavior implementation6. Enhanced Aiming System
Improves shooting accuracy based on personality.
src/ai_patterns.cpp(lines 268-272)How it works:
src/ai_patterns.cpp(lines 268-275) -getModifiedAimCone()methodDifficulty Levels and Behavior
EASY
MEDIUM
HARD
DEVELOPER
New Behavior Patterns
The system introduces five distinct behavior patterns that make the AI feel more intelligent and unpredictable:
1. Adaptive Pursuit
2. Tactical Positioning
3. Dynamic Avoidance
4. Targeted Pursuit
5. Intelligent Pattern Breaking
Technical Implementation
Data Structures
include/ai_patterns.hpp(lines 37-57) -AiPatternTrackerstructureinclude/ai_patterns.hpp(lines 60-79) -AiPersonalitystructureNew Constants
What
circularPatternThresholdregulates:circularPatternThreshold * 2.0f= maximum allowed varianceWhat
stalePursuitThresholdregulates:mPursuitTimerstalePursuitThreshold→ pattern is considered staleisStalePursuit(): Detects stale pursuit stateshouldBreakCircularPattern(): UsesstalePursuitThreshold * 0.5ffor breaking decisionsWhat
movementPredictionTimeregulates:movementPredictionTimeseconds ahead