game files: https://drive.google.com/file/d/1MrrGC5PBFbjgwXO0IRgbYSHRQ-CFGYbd/view?usp=sharing
This project implements an AI agent for a 2D fighting game environment.
The goal of the project was to design an intelligent decision-making agent capable of defeating a random opponent using heuristic evaluation and adversarial search techniques.
The strongest and final version of the AI agent is implemented in:
agent3.py
Other files such as GAMECODE-python.py and fighter.py belong to the game engine and are not part of the AI logic.
The game asset files (graphics, sounds, etc.) are provided as a ZIP file in the repository.
- Download the repository.
- Extract the ZIP file containing the game assets.
- Place the extracted folders next to the Python source files.
- Run the following file:
GAMECODE-python.py
The AI vs AI mode will automatically execute using agent3.py as the main intelligent agent.
- Each fighter starts with 100 HP.
- The game ends when one fighter’s HP reaches 0.
- Movement speed: 5 units per frame.
- Dash:
- Moves the fighter 300 units over 10 frames.
- Has a cooldown.
- Light Attack:
- Damage: 10
- Short cooldown
- Heavy Attack:
- Damage: 20
- Long cooldown
- Attacks only hit if the opponent is inside the attack hitbox.
Each frame, the agent must output a dictionary with:
- move (left / right / None)
- attack (1 = light, 2 = heavy, None)
- jump (True / False)
- dash (left / right / None)
- debug
- saved_data
The agent must respond within 0.4 seconds per frame.
The final agent uses a combination of:
- Heuristic evaluation function
- Minimax algorithm with Alpha-Beta pruning
- Situation-based overrides (corner logic, anti-air, post-dash safety)
The AI balances aggression, positioning, and defensive reactions.
The evaluation function estimates the quality of a game state using weighted factors:
-
Health Difference
- Primary objective.
- Higher HP advantage increases score.
-
Distance to Opponent
- Encourages staying within effective attack range.
- Penalizes excessive distance.
-
Attack Cooldowns
- Rewards having attacks ready.
- Penalizes long cooldown states.
-
Opponent Attacking State
- Reduces score when staying inside opponent attack range during enemy attack.
-
Airborne Detection
- Adjusts behavior when opponent is jumping.
- Prevents unnecessary ground attacks.
The heuristic enables the agent to reason about positional advantage, risk, and offensive opportunity.
The agent uses:
minimax_alpha_beta(state, depth, alpha, beta)
- Depth-limited search (depth = 2)
- Alternating maximizing (self) and minimizing (opponent)
- Alpha-Beta pruning to reduce unnecessary branches
- Small, controlled action space to maintain performance under 0.4s limit
The opponent is modeled using the same action generator for adversarial reasoning.
Beyond pure Minimax, the agent includes practical game intelligence:
Safely closes distance at the beginning when far from opponent.
If near wall and opponent jumps, performs forward dash to reposition and avoid getting trapped.
After dashing forward, temporarily avoids attacking to prevent immediate punishment.
Heavy attacks are only used when:
- Distance is appropriate
- Opponent is not airborne
- Risk is acceptable
Avoids ineffective ground attacks when opponent is airborne.
Compared to previous iterations, this version:
- Uses realistic hitbox simulation
- Avoids unsafe dash situations
- Handles wall positioning
- Reduces unnecessary whiff attacks
- Balances aggression and safety dynamically
- Performs consistently well against random agents
This project demonstrates:
- Practical application of adversarial search (Minimax)
- Heuristic state evaluation design
- Real-time decision constraints
- Strategy refinement through iterative improvement
The final agent achieves strong and stable performance against a random opponent and represents the most optimized version developed during the project.
Author: Mahan Baneshi AI Project – Final Submission - winter 2025