Overview
The Lux AI Challenge is a competitive AI programming competition where players develop autonomous agents to manage resources, build cities, and outmaneuver opponents in a turn-based environment.
As part of a team project, we designed and implemented our own AI strategy to compete against other teams in our class. By refining our approach and optimizing decision-making, we ended up winning every match!
Key Strategy Elements
Strategic Movement of Units
In our AI, one of the key components was optimizing unit movements. To achieve this, we utilized a custom Position class that allowed us to easily calculate the Manhattan distance between units and targets, and find the optimal direction to move toward resources or cities.
1 | float Position::distanceTo(const Position &pos) const |
1 | auto dir = unit.pos.directionTo(closestCityTile->pos); |
Unit Management and Resource Gathering
One core aspect of our strategy was to manage the workers effectively by directing them to gather resources in the most efficient way. We dynamically selected the closest resource tile and prioritized filling the workers’ cargo spaces before moving them back to the cities.
1 | if (unit.getCargoSpaceLeft() > 0) |
City Building and Worker Creation
Another critical part of our strategy was deciding when to build new workers or cities. This decision was based on the current state of the game, such as the number of available units and the resources researched by the player. For example, when coal or uranium were researched, the AI would prioritize building workers to increase production.
1 | if (it->second.citytiles.size() <= player.units.size()) |
Day, Dawn, and Night Phases
Our strategy was also influenced by the game’s cycle, where different actions were taken depending on whether it was day, dawn, or night. During the day, we focused on unit actions and city building, while during dawn and night, we prioritized resource gathering and preparation for the next cycle.
1 | if (gameState.turn % 40 <= 20) |