DEV Community

Augusts Bautra
Augusts Bautra

Posted on

Thoughs on Codingame 2024 Winter challenge

Image description

Despite being ill for the majority of Dec 19th to Jan 6th runtime, I had fun participating in this code challenge, and even got a decent place (very low gold). Overall is seemed that significantly more people were participating, and the competition was tough.

My strategy was simple - be aggressive in sporing towards opponents and tentacling them to death. I figured worst case, with symmetric play, this is always a draw. Besides these easy cases of immediate aggression, I was focusing on harvesting A protein to out-grow my opponents. Naturally, this led to an edge-case weakeness where if no As were close, my Organism was struggling to get off the ground.

For this challenge I wanted to focus on implementing a Domain Query Interface, were instead of operating on raw hashes and arrays, I could do Rails-like Entity.organs and the like, and this worked very well. Unfortunately, I'm not quite sure how to achive chainability, for example Entity.organs.my.

Some take-aways:

  • Study game rules, especially the time and input limits. This can give you ideas for optimizations like instead of Point class for coordinates, can use Integers etc.
  • Do not jump on fixing every little failure. Click through at least 10 losses to get a feel for how you lose generally, not just that one time.
  • Useful to think about change direction of game state. For example, arena walls can be added (actually undocumented feature, both players trying to grow to the same cell results in that cell becoming a wall instead), whereas protein sources can only ever disappear. Knowing events around these can help expire data cache related to arena state (for example, use current turn as new state cache key whenever arena layout changes)
  • Important to output concise debugging information that you can copy+paste in your specs and reproduce failing state ASAP. Omit everything you can infer, for example all WALL data is the same, so no need to output that, just coordinates suffice.
  • Also important for reproduction are any variables provided by the game, like the seed etc, save it all.

Up next

For the next challenge or even before that, I'd like to focus on practicing deep Ruby optimization magic, one avenue is Leetcode, but there may be others.

Top comments (0)