Uh oh! Your current browser is not supported by CodinGame.
You may encounter navigation difficulties. Update your browser with the latest versions of Firefox or Chrome for optimal use.


Basic simulation and evaluation

Previous: Full turn simulation

Random search

This is the brain of our pods. It makes our pods "think" and "come up" with trajectory plans for the near future. To make it work, we need to try a lot of different trajectories and evaluate the outcomes they provide to pick the trajectory with the best score. Trajectory is defined with a list of game moves for the next N turns. We can easily generate trajectories randomly and then simulate the game with them:

Solution sol = new Solution(); float score = sol->RandomizeAndEvaluate(pods);

then just repeat this 10 000 times more and print the best solution found:

static public void DoRandomSearch(Pod[] pods)
    Solution best = new Solution();
    float scoreBest = best->RandomizeAndEvaluate(pods);

    for(int i = 0; i < 10000; i++)
        Solution sol = new Solution();
        float score = sol->RandomizeAndEvaluate(pods);

        if (score > scoreBest)
            scoreBest = score;
            best = sol;

Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
Online Participants