Coders of the Caribbean - Feedback & Strategies

4th - Legend

Thank you CodinGame for this great contest again!
Probably one of the contests where I invested the most time, and ended up with the biggest code :slight_smile:

Basically I used the same approach as Ghost in the Cell.

The first step was to convert the Java referee to C++.
In order to make things more convenient, I had one big source code, that would compile as my AI, a referee or a testing mode, with some #ifdefs.

In referee mode, the program takes 2 bots as parameters and outputs the winner. I usually ran about 1000 games with a 2ms timeout, to quickly see if my new bot improved over the previous one.

In testing mode, I ran the referee with 2 deterministic dummy bots on a specific map (using a static seed) and compared the game states with the same match I ran before on CodinGame.
This allowed me to check that some optimizations I made to updateGame() did not break the simulation model.

My bot was a Genetic Algorithm doing 3 consecutive moves for each ship in 3v3, 4 moves in 2v2, 5 moves in 1v1.

In order to choose moves for the opponent, I ran the GA for the opponent against myself assuming I would WAIT, for 1/3 of the time limit.
Then I ran the GA for myself against the bests moves found for the opponent for 2/3 of the time limit.
Of course this meant I was very good at predicting my own moves, and I was afraid this would cause too much “inbreeding” but it turned out to be okay, and at least better than assuming my opponent would just WAIT.

I optimized a bit the simulations by using lookup tables for mines, barrels and ships collisions to avoid iterations on the full list at each turn.

The moves (for myself and opponent) were choosen based on the genes, with some preference for FASTER, PORT, STARBOARD and FIRE.
I would never WAIT (but I could FIRE/MINE during my cooldowns resulting in the same behavior).
For the FIRE command the target was chosen based on the genes, with some preference for ship positions (including mine).

After each turn of the simulation, a big evaluation function was called to see if the new state was better (with a decay factor of ~0.8 for each turn in the future).
Some parameters I was checking were:

  • my ships health, speed, cooldowns and distance to the center of the map
  • opponent ships health
  • a additional malus for ships on the border of the map
  • ships distance to barrels * rum
  • distance to future cannonballs
  • bows distance to opponent ships sterns
  • when there were no barrels left: distance to ship with highest health (being offensive if I am behind, or running away if I am ahead)

I also tried many things that did not work (or that I did wrong):

  • try to guess were opponent would be in the future in order to shoot at these coordinates
  • instead of the distance, use the “time to reach” by precomputing all the paths before the GA
  • have a malus for all the potential coordinates on the map where the opponent could FIRE or MINE
  • and many others that I forgot :slight_smile:

During the last day I did not manage to improve the core functionalities, so I spent some time tuning my evalution function weights.

Overall this was a great contest, it was so fun fighting against pb4 and Agade all week long and improving my bot!

24 Likes