This repository contains the implementation of an intelligent agent for the Hypersonic game. The project demonstrates the use of advanced search algorithms and heuristics to create an agent capable of competing effectively in the game.
The project is implemented entirely in C++ to ensure high performance and efficient computation, crucial for real-time decision-making in a competitive environment. This competition is part of CodinGame's Hypersonic Bot Programming Challenge.
Hypersonic is a strategic multiplayer game where 2 to 4 players compete on a grid. The game involves placing bombs to destroy boxes, collect items, and eliminate opponents. Players are ranked based on survival and the number of boxes destroyed.
- The grid consists of floors, walls, and boxes.
- Players can move or place bombs, which explode after 8 turns.
- Items dropped from boxes can enhance players' abilities.
- Players have full visibility of the game state and opponents' moves.
- The winner is the last player standing or the one who destroys the most boxes in case of a tie.
The game state is a critical component of the agent's decision-making process. It provides a snapshot of all relevant elements in the game at a given moment.
- Map: A representation of the grid, including walls, boxes, and empty spaces.
- Players: Details of each player:
- Current position
- Number of bombs available
- Explosion range of bombs
- Bombs: List of all bombs in the game, including:
- Position on the grid
- Timer before explosion
- Explosion range
- The player who placed the bomb
- Items: List of collectible items on the map, including:
- Item type (e.g., bomb range, additional bomb)
- Position on the grid
- Parent and Child States:
- Parent State: The state from which the current state was derived.
- Child States: States generated from the current state based on possible actions.
The agent uses a Search Tree to explore possible game states and determine optimal moves.
- Initial State: Represents the starting configuration of the game.
- Nodes: Each node corresponds to a game state.
- Edges: Represent the legal moves made by players.
- Levels: Each level simulates a single round of the game.
- The agent employs Beam Search:
- Expands a fixed number of top states (e.g., 150) at each level based on evaluation metrics.
- Simulates 8 levels, representing 8 rounds of the game.
- Backtracks from the best state at the deepest level to determine the optimal move.
The Transition Model describes how the game state evolves as a result of player actions.
- Bomb Explosion:
- Decrements the timer for all bombs.
- Triggers explosions for bombs with a timer of 0, affecting:
- Players within the explosion radius.
- Boxes (destroyed and potentially revealing items).
- Adjacent bombs (chain reaction).
- Player Position:
- Updates the player’s position based on the selected move.
- Item Collection:
- If a player moves to a cell containing an item, it is collected.
- Effects depend on the item type (e.g., increased bomb range).
- Bomb Placement:
- If a bomb is placed, it is added to the list of bombs.
To evaluate the quality of a game state, the agent uses several heuristic metrics:
-
Player Position:
- Proximity to boxes (with or without items).
- Proximity to available items.
- Distance from other players.
- Distance from the center of the map.
-
Bomb Position:
- Strategic placement for maximum impact.
- Avoiding blast zones for survival.
-
Survival:
- Ensures the agent prioritizes moves that maximize survival chances.
- The evaluation of a child state combines:
- The parent state’s score (to preserve long-term strategy).
- Scores based on the metrics described above.
The agent demonstrates intelligent behavior by selecting moves that maximize survival and box destruction. It has achieved top positions in the gold league standings.