This document provides a detailed explanation of the bot's logic, focusing on the main controllers and their functionalities. The bot is designed to manage resources, units, and missions efficiently to maximize resource collection and city development.
The agent
function is the core of the bot. It processes the game state, updates clusters, assigns missions, and issues actions for units and city tiles.
- Initialization: Initializes the game state and clusters at the start of the game.
- Resource Collection: Identifies and collects resources on the map.
- Cluster Updates: Updates clusters and assigns missions to units.
- Action Issuance: Issues actions for units and city tiles based on the current game state.
-
Initialization:
- At the start of the game (
observation["step"] == 0
), the game state and clusters are initialized. - The
ClusterController
is initialized, and clusters are identified using a Depth-First Search (DFS) approach.
- At the start of the game (
-
Resource Collection:
- The bot retrieves all resource cells on the map using
get_resources
. - It filters minable resources based on the player's research level using
get_minable_resource_cells
.
- The bot retrieves all resource cells on the map using
-
Cluster Updates:
- Clusters are updated based on the current game state using
cluster_controller.update_clusters
. - Units without clusters are identified and assigned to clusters using
cluster_controller.assign_worker
.
- Clusters are updated based on the current game state using
-
Mission Assignment:
- Missions are assigned to units based on the cluster's needs (e.g., building, guarding, exploring).
- Target positions are assigned to missions using
cluster.assign_targets_to_missions
.
-
Action Issuance:
- Build actions are issued for units using
cluster.get_build_actions
. - Required moves for units are calculated using
cluster.get_required_moves
. - Actions for city tiles (e.g., building workers, researching) are issued using
get_city_actions
.
- Build actions are issued for units using
The ClusterController
class manages resource clusters, which are groups of connected resource cells. It uses a Disjoint Set Union (DSU) data structure to efficiently manage clusters.
- Cluster Initialization: Identifies clusters using DFS and initializes them.
- Cluster Updates: Updates clusters based on the current game state.
- Worker Assignment: Assigns workers to clusters based on a scoring system.
- Unit Management: Tracks units assigned to clusters.
-
getClustersRolling
:- Uses DFS to identify clusters of connected resource cells.
- Initializes clusters and stores them in
clusterDict
.
-
update_clusters
:- Updates resource cells, units, and perimeters for each cluster.
- Removes consumed resources and dead units.
-
assign_worker
:- Assigns workers to clusters based on a scoring system that considers distance, resource cells, perimeter, and opponent presence.
-
get_units_without_clusters
:- Identifies units that are not assigned to any cluster.
clusterDict
: Dictionary mapping cluster IDs toCluster
objects.woodClusters
,coalClusters
,uraniumClusters
: Lists of clusters for each resource type.
The Mission
class represents a task assigned to a unit, such as building, guarding, or exploring. The Cluster
class manages missions for each cluster.
- Mission Assignment: Assigns missions to units based on cluster needs.
- Target Assignment: Assigns target positions to missions.
- Mission Execution: Issues actions for missions (e.g., building, moving).
-
assign_targets_to_missions
:- Assigns target positions to missions based on mission type (e.g., building, guarding, exploring).
-
get_build_actions
:- Issues build actions for units that are at their target positions and have enough resources.
-
get_required_moves
:- Calculates required moves for units to reach their target positions.
-
handle_explore_missions
:- Manages explore missions, ensuring units have enough fuel to survive the night.
missions
: List of missions for the cluster.target_pos
: Target position for the mission.responsible_unit
: Unit responsible for the mission.
The resourceService
module provides functions to manage resources on the map.
- Resource Identification: Retrieves all resource cells on the map.
- Resource Filtering: Filters minable resources based on the player's research level.
-
get_resources
:- Retrieves all resource cells on the map.
-
get_minable_resource_cells
:- Filters resource cells that can be mined by the player based on their research level.
-
get_resources_from_cells
:- Retrieves resource cells from a list of positions.
resource_cells
: List of resource cells on the map.
The unitsService
module provides functions to manage units.
- Unit Retrieval: Retrieves units by their ID.
- Cargo Management: Calculates the remaining cargo space for a unit.
- Action Validation: Checks if a unit can perform an action.
-
get_unit_by_id
:- Retrieves a unit by its ID.
-
get_cargo_space_left
:- Calculates the remaining cargo space for a unit.
-
can_act
:- Checks if a unit can perform an action.
units
: List of units controlled by the player.
The helperFunctions
module provides functions to manage city tiles and their actions.
- City Tile Actions: Issues actions for city tiles, such as building workers and researching.
- City Tile Scoring: Calculates a score for city tiles to determine the best action.
-
get_city_actions
:- Issues actions for city tiles, such as building workers and researching.
-
get_citytile_score
:- Calculates a score for city tiles based on resource availability, perimeter, and opponent presence.
citytiles
: List of city tiles controlled by the player.