Troll Farm - Spring Challenge 2026 - Puzzle discussion

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

We slightly changed the early end condition: when the last tree gets chopped, the players have enough time to return the wood to the shack, when taking the shortest path back home.
The limit of 300 turns per game is unaffected by this.

1 Like

Before I rant, huge thankyous for creating this particular puzzle for us. I enjoyed it.

My issue is with time in game. I wrote the input parser in Python, but since I would like to write some kind of heavier AI I decided to rewrite it in C#. To my surprise, both need at min 15 ms each turn (just to parse inputs) and very very often they go over 50 ms allotted. I was going to end my rant with a question but I forgot what it was… (any reply is welcome).

This boils down to one question: how do you measure time? The order should be:

read input (or first line of input at least)
start timer
do computations
stop timer
print stderr
print output

If you start the timer before reading the input, you also measure all kind of other things that are out of your control: the time used by your opponent and the referee (the program that plays the game and executes the players).

2 Likes

Just for reference, this is my C# code. Both ReadParse() methods are reading from stdin and parse the data.

public class MainClass
{
    public static void Main()
    {
        var wm = WorldMap.ReadParse();
        var sw = Stopwatch.StartNew();
        while (true)
        {
            sw.Restart();
            var gs = GameState.ReadParse();
            var elapsed = sw.ElapsedMilliseconds;
            Console.WriteLine($"MSG {elapsed}");
        }
    }
}

The first ReadParse only happens before the loop, not for every turn. For every turn thereafter you measure the opponent as well. If your gamestate parsing doesn’t do any heavy lifting, just start the timer after it.

Will there be some embedded replays on the details page of this game?

Would you mind sharing your ideas/strategies? How did you approach this challenge?

You may refer to this topic.

1 Like

Hi, eulerscheZahl !

I think there is still an issue on that, as we can see at the end of the game Coding Games and Programming Challenges to Code Better : two of my trolls are loaded with wood but don’t have enough time to bring it back to the shack.

Regards

Nothing wrong with this: there are no more fruits remaining, thus no planting possible. And you already won before dropping all the wood, nothing you can do (except crashing) would change the outcome.

I agree it wouldn’t change the game result. It was just about the statement “when the last tree gets chopped, the players have enough time to return the wood to the shack“ that was not true. Didn’t thought the referee would do such a computation.

I was a bit lazy and just described the change. The early end when either play can enforce a win by doing nothing already existed in the contest and remained unchanged.