The night is dark and full of terrors. Two teams must fight off the darkness, collect resources, and advance through the ages. Daytime finds a desperate rush to gather and build the resources that can carry you through the impending night. Plan and expand carefully -- any city that fails to produce enough light will be consumed by darkness.
Lux AI Challenge in Season 1 is a game competition, where two players are tasked with resource-collecting and building the bigger city. Each player is given a starting city and a unit. They have to navigate the unit to collect resources and use these resources to build new cities or fuel existing ones, and they can use the cities to create new units. Every couple of turns a night occurs and cities and units need to start burning gathered fuel to keep lights on and survive the night - if they run out of resources, they are removed from the game. At the end of the last turn, the winner is the player with the bigger city.
This game is quite straightforward and not complicated. However, nothing is so cut-and-dry for automatic algorithms and AI, and there is a lot of possible strategy in this game when one dives into the plethora of possibile moves and strategies. The detailed instructions are posted on the Lux AI 2021 competition website.
The competition was held from 16th August till 6th December in the year of 2021. I learned about this game from an extensive Coding Adventure video by sentdex. But I learned about its existance quite late, with only a few days to the deadline. I never stood a chance to win the competition, but that does not mean I cannot make a decent bot anyway.
Main platform
Competition platform
Game code
Visualizer
First thing, I decided on the scope of this small project. I decided to invest just 2 days into it, so a lot of important parts needed to be cut off. I ended up spending 3 days, or about 25 working hours on this project (mainly because of some problems with initial game code-base). The things, I cut out right off the bat are the following:
By cuting these two big pillars of the game out, the scope seems much more managable to acomplish in such limited time.
I decided to base my bot on the focus of self-preservation. This type of play is very conservative and can be seen as quite slow. It also somewhat limits possibility for rapid expansion, but on the positive note, it makes sure that the cities (almost) never run out of fuel. MY cities (almost) always survive the night and I do not lose the progrss made up to that point in the game.
I chose to implement my bot in Java, based on my existing knowledge and the fact that I already had the environment prepared. Additional drive in my decision was that Java is simply much faster than other supported languages. In the later stages of implementation, this decision turned out to be a bad one. The submission platform is more supportive of Python and the community has also better focus on Python bots. In retrospective, I should have spent a bit more time deciding on the language for the bot.
The plan was simple:
This plan was completely proof. Cities were surviving all nights without any problems. Unfortunatelly, it become obvious that I did not pay enough attention to units, as they kept dying through the nights. So, I added the following restrictions:
This is a solid plan. The play is not agressive at all and if the opponent is breaver with its expansion, my bot cannot keep up. On the other hand, it easily outlasts the bots that expand too rapidly and end up losing their cities through the night.
As it was obvious from the very beginning, my bot does not perform very well. But thanks to its safe pace and reliability, it managed to end up in the golden middle on the leaderboards, at ~ 600 from ~ 1200 bots (the leaderboards are constantly shifting, so the actual result is not yet determined at the time of writing).
I spent some time researching plays from the bots at the very top leaderboards. One of the most interesting concepts was how protective they were of their resources. Those bots set up multiple cities, each around its own resource and in this way they prevented the opponent from using that resource altogether. Additionally, they had strong supply lines to each city, so the bots did not need to spend precious turns traveling back and forth between a city and a resource. Those are quite advanced tactics and I wonder if they were designed and programmed into the bots by developers, or were they a result of AI learning how to best play the game.
The game is a lot of fun and I would recommend it very much, if only there was more time available. Lucky for us, this was just the Season 1 of the Lux AI Competition and I am looking to the next seasons, filled with exciting anticipation. Next season, I will take my time and develop a winning bot.
Disclaimer: all images belong to lux-ai.org.