# Codingame

banner

Learnings

Algorithm Description
MCTS (Monte Carlo Tree Search) Designed for turn-based games. It builds a search tree using random simulations (playouts) to evaluate moves, balancing exploration and exploitation to find strong decisions over time.
Smitsimax An adaptation of MCTS for simultaneous-move games. Instead of assuming alternating turns, it accounts for both players acting at the same time, often modeling uncertainty about the opponent’s choice.
Beam Search A heuristic search algorithm that explores a limited set (beam width) of the most promising nodes at each depth. It focuses on deep exploration of likely good paths, with less emphasis on modeling or anticipating opponent strategies.

see also

HW Limits

Your program is compiled and run in a Linux environment on a 64bit multi-core architecture. - Environment/lang

  • 1 cpu
  • Memory limits is 768MB - forum
  • source code is 100k characters

C++ flags ⮺ (2024-09-25)

SIGSEGV will often been seen as Timeout by the Codingame engine (without any clue given).
see Stacktrace - for a quick Signal handler that could help diagnosing this situation.

compiler: g++ 11.2.0 mode C++20
flags: -std=gnu++17 -Werror=return-type -g -pthread
libraries: -lm -lpthread -ldl -lcrypt

Optimization trick

#pragma GCC
// trigger optimisation from source file
#pragma GCC optimize("O3")
#pragma GCC optimize("inline")
#pragma GCC optimize("omit-frame-pointer")
#pragma GCC optimize("unroll-loops") //Optimization flags

#pragma GCC optimize("Ofast")

#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx")  //Enable AVX
#pragma GCC target "bmi2"
#include <x86intrin.h> //AVX/SSE Extensions

Ruby 3.1.2 (2024-09-25)

Arena

  • psyleague - cmd-line league system for bot contests.
    • recommended by smits

Referee

For Legacy games:

  • codinGame - These are the actual codingame referees, written by CG staff.
  • eulerscheZah - unofficial collection of referee

CSB / Mad Pod

External Playground

  • Cg-brutaltester / github
  • The Game Runner - The Game Runner lets you run your game locally during developement. It comes with a handy HTML package to watch each game’s replay. The parameters you set to the Game Runner will not affect the final contribution.

Using Codingame playground

  • CG Benchmark - A benchmark tool for CodinGame:
    • don’t need to have your browser open
    • you can queue several codes to run big fat batches of games and compare results easily.
  • CG Spunk / Github

Last Battle history

  • CG stats
  • Using match history - We will explore the CodinGame API to understand how to download replays. Then we will parse them to extract the data we are looking for. We will then feed it into our bot to debug a specific action.

Codingame API

Firefox Extension

  • CG Enhancer / github - enhance Codingame IDE

  • CG Local - basically a copy of CG Sync that works with both Chrome and Firefox, and instead of a Chrome App it uses a Java application to watch the selected file for changes. Besides that, it also makes it easier to work in different files for different puzzles and is completely open-source. / github

Chrome Extension

Merger Tools ⮺

Use my own.

Cheating

  • CG-Send-Binary - Flagged as a cheat during contests since Wondev Woman

Technical details

CodinGame SDK ⮺

The CodinGame SDK is a Java project that allows you to write programming games for CodinGame.

Maybe old

Rest API

liste des agents des participants au concours: curl -H "Content-Type: application/json" https://www.codingame.com/services/LeaderboardsRemoteService/getChallengeLeaderboard --data '["hypersonic",null,"global"]'

Ca renvoie une liste JSON de tous les participants, et chaque participant a un champ “agentId”.

Pour chaque “agentId”, on peut récupérer toutes ses batailles, par exemple pour l’agent 707853:

curl -H "Content-Type: application/json" https://www.codingame.com/services/gamesPlayersRankingRemoteService/findLastBattlesAndProgressByAgentId --data '[707853,null]'

Ca renvoie encore une autre liste JSON avec toutes les parties jouées, et le résultat. (Y’a aussi la partie à jouer dans le replay de la page mais on s’en fout). Chaque partie a un champ “gameId”.

Pour chaque “gameId”, on peut enfin récupérer le déroulement complet, avec stdin et stdout de tous les joueurs. C’est ce qui est envoyé au player web, donc le format est peut être pas 100% équivalent au format d’entrée / sortie de l’agent, mais toutes les infos sont là à ce que j’ai pu voir sur les challenges précédents. Par exemple pour la partie 136874087:

curl -H "Content-Type: application/json" https://www.codingame.com/services/gameResultRemoteService/findByGameId --data '[136874087,null]'

Pour la dernière vu que le format des données change pour chaque challenge, il faut faire un parser spécifique à chaque fois, et je n’en ai pas fait.

Written on January 28, 2018, Last update on August 31, 2025
codingame AI puzzle c++