Final Rank: 32
source code: https://github.com/Manwe56/Manwe56-ai-c ... lanet-wars
Executable Jar : attached (just rename .zip in .jar since jar files are not accepted)
Most of the code basis has been written in Test Driven Development. You will find a test package in the sources containing all the tests I have written. Those tests are all checking under a given trivial situation of the world, that my bot is sending the expecting fleets during one turn. I did not write lower level tests because I did not want to loose time maintaining tests on a code that might evolve a lot.
After a certain stage, I faced difficulties to write tests : it is quite perfect to ensure your bot will manage a certain situation, and you are not breaking the previous features, but when you want to tests if you get "stronger" by changing an evaluation function for example, I did not find any way to go further.
So fine tuning has been done like the others contestants i guess : running a new version against my previous versions, running the bot on the tcp server etc...
There is packages in the sources, and for the submissions I had a little script that copied everything in a new folder, and removed package definition/imports.
I also modified the game visualizer in order to display more information. I was trying to understand how I could re-balance my ships between the planets to avoid putting one planet in danger.
For each planets, the visualizer computes the planets states until maximum distance between planets. Then on each planets, for each turn, it calculate how many ships could reach the planet for both player.
Then on each planet:
The planet is neutral : the text displayed has the color of the player with the maximum of ships that could reach the planet. The number displayed after the # represent the difference of ships between the player with max ships and the other player at the turn of the maximum
The planet is owned by a player : we find the minimum of the difference of ships of the owner and the other player. If this difference is negative (so it exists a turn where the planet could be lost) the color of the text will be the other player. Then the absolute value of this difference is displayed
It is quite amazing how you can "see" who will win in a early stage of the game with this visualizer. I tried to use this information (trying to maximize the "influence" map), but I did not succeed to stabilize something enough efficient.
Now on the code of the bot:
There is no magic, and it is very similar to other top players
maximum simulated turn is the maximum distance between two planets on the map
1) compute all the states of the planets, for each turn. Based on this, compute for each turn how many ships could reach a planet for each player.
2) Compute the "front" planet and "future front" planets. the future front is the front with the planet owner of the maximum simulated turn
3) Try to cover planets that might fall to the enemy if we are not sending reinforcement
4) This is the attack step:
Determine eligible targets. Eligible targets are all the neutral planets, enemy front planets, and my planets that I will lost
For each eligible target try to find a possibility of attack with my planets, starting from the nearest. I determine on each planet the available ships without any risk to loose the planet. I add my planets contribution until I find a combination that allow to conquer the planet with the following conditions:
The number of ships to send depends on the target : if it is enemy, I just want to be sure to capture it when all the fleet arrives, ie no defensive move is possible on impact. If it is neutral, I will need to ensure I will be able to keep this planet until the max simulated turn. If the neutral is closer than an enemy, ships that are required due to potential enemy reactions are included in the ships to send. Else those ships are reserved in the planet. On each step, The order are executed and refreshes the simulation to avoid side effects. The possibility rating is the number of turn until I begin to gain ships compare to my enemy.
Execute the best possibility, and remove the target from the eligible targets. Return to beginning of 4 until there is no other possibility to execute
5) recompute front to take into account our attacks
6) if a planet is not a front planet, send ships that are not required to keep the planet to the nearest front planet
7) with the ships of definitively lost planet, try to plan suicide attacks on enemy planet expecting a defensive move that will allow to have time to counter
Note that there is two phase : one phase of expansion where I try to conquer neutrals quickly. In this case, neutral planets are considered as enemy on the front calculation. It allows to keep ships behind for faster conquest. Then there is the offensive phase, where only enemy are considered to calculate front planets, and step 3 is simply not executed because I do not need to re-balance my ships considering enemy moves. I did not took the time to find a good criteria for the phase transition, so I hard coded 5 turns...It was more to avoid on a few maps to send almost all my ships in a direction when in one or two turn I would have been able to capture a neutral planet next to my starting position
I also have some special things in the step 4) : I try to find a solution in the future, allowing to wait to take a more interesting planet (else I remarked the planets are taken in order of their ships number, and not really interest). If this solution is the best, the ships are reserved for the entire turn.
The major weakness of my bot is that it never place in the other player point of view. basically, if it could take a 70/+1 neutral, but by doing this allow the enemy to capture a middle neutral 11/+3 planet, it does not cancel the move...The other major weakness is that my bot does not store anything between two turns. So it is not able to really make the same assumptions on the attacks it previously launched, and the attacks it is planning. It usually allow the other player to take control of a neutral at the beginning it was able to maintain
I really enjoyed this contest! Thanks you all for this great challenge!!