wala-fr / CodingameFramework

Java tips for codingame multiplayers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CodingameFramework

This project contains some Java utilities/tips for Codingame.

When i started on Codingame, i tried to reach legend in a lot of multis. It seems like an opportunity to practice Java 8. My bots were mostly heuristic with no use of a timer. But then, after pushing back as much as possible, i had to do UTTT. It changed my vision of Codingame and now i'm redoing all my previous bots.

Here are some Java tips that i've learned so far :

  • Use a Merger that allows you to code in multiple files. I coded the CodinGame Sponsored Challenge in one file. I had to stop when it wasn't readable anymore (still got to redo it).

  • Use a personal Logger printing time elapsed and class name.

  • Go back to the source. Forget about Java 8 (Stream, Optional...). I even removed foreach loops in UTTT.

  • I use mostly primitives and arrays rather than objects. In this project to store a position, i used a byte rather than an object with x and y fields (see PointUtils).

  • I almost don’t use List, Set, Map... anymore. I have small utilities to use arrays instead of collections (basically the first element of the array is the number of elements in the "list"). It avoids boxing/unboxing, the creation of "useless" objects (Integer, Byte...), to clear a "list" you only set the first element to 0... Look at PlaceUtils to see a use case.

  • I use assertions rather than Unit Tests to make sure that there's no bugs/regressions.
    For example in Spring Challenge 2021 : i kept the state of the game at the beginning of my last turn, then i "guessed" the opponent actions, used my simulation to play my action and his, and compare (with assertions) the result and the game inputs.

  • Create caches (around positions, distances...)

  • One of the main problems using Java in CodingGame (besides its slowness) is garbage collector timeouts. One way to reduce them is to implement the trick in GarbageCollectorUtils (see also JVM memory issues). But mostly you must avoid creating garbage collectable objects. For an example, you can look at the Beam Search implementation.

I'm also starting to use bitboards (but no specific tips for Java).

There's an associated post in the Codingame forum.
Hope it will be helpful.

About

Java tips for codingame multiplayers


Languages

Language:Java 100.0%