Sunday, December 4, 2016

Fantastic Bot for Fantastic Bits

The winter 2016 CodinGame contest, Fantastic Bits, just wrapped up and I am incredibly excited by how well I was able to do.  This was my fifth contest since joining the site in spring this year, but it was the first time that the contest has fallen on a week where I've been relatively free to focus without distractions since my initial participation in the Smash the Code contest.  The results definitely reflect this, as I finished 4th in the country and 42nd overall out of 2400 entries from top programmers around the world.  In fact, in the final few minutes I climbed as high as 1st in the country and 18th overall, before some last minute changes and optimizations by other players caught me off guard.



Needless to say, I am extremely proud of how well my bot programming turned out.  I used C# for my language this time (and finished as the 6th best C# entry), which meant that I had no problems with performance and was able to do simulations and calculations plenty fast.  The contest this time was a video game version of Quidditch, where you control 2 wizards trying to score goals against your opponent while avoiding bludgers and using flying, throwing, and magic.

The big challenge in this contest was the number of different choices to be made each round.  With 2 wizards, up to 7 balls, 2 bludgers, 2 enemies, and 4 potential spells to use, the options quickly compound.  Early on, I struggled with how to best handle this, until I came up with a generic command and ranking architecture.  This allowed me to iterate through the breadth of options, generate ranked values for each possibility, and then execute whichever ones gave me the best possible score.

Other factors that strongly contributed to performance were how to calculate which wizard pursued which balls, optimizing the trajectory and thrust trigonometry for best intercept, and finally simulating trajectory of shots on goal to avoid getting blocked and maximize scoring potential.  By having a generic system that assigned value ranks to each action, I was also able to adjust weighting and scoring ratios to optimize my wizards' AI behaviors.  This made a big difference once I broke into the top 100, because I needed a way to genetically adjust to wins and losses in order to slowly climb up the ranks.

This was another great, engaging contest and I'm sad that it's over.  I can't say enough good things about CodinGame.  I look forward to seeing reading the breakdown of the contest once all the data is analyzed, and I hope I can learn enough to improve on my performance even more for next time and maybe threaten for a top spot.