Code Royale - Puzzle Discussion

Hi, can anyone help with my python 3 code, here is a sample:

minimo = []
for i in range(num_sites):
minimo = sorted(minimo)

for x in sites:
    if x.dist_site == minimo[0] and x.owner != 0:
        msg = "BUILD " +  str(x.site_id) + " BARRACKS-KNIGHT"

I created a class Sites for storing sites info and status. I calculate the nearest site and send the queen to build but she keeps rebuilding it instead of going for the next nearest site. It looks like the sites info arent updated every turn, but since the updates are inside the game loop, I dont understand why not.

usually, when this kind of thing happens to me, it’s because I forgot to clear my list. Difficult to say though with your snippet.

This happend because i keep the minimum distance site a site that i already have, i just changed the condition to add the minimum distance always to a site that is not mine. Thanks for the help!

1 Like

Hello, sometimes when I run my code this error comes:
Code failed: nothing should be sent to the output before reaching the main entry point for your language.
Read: [Error occurred during initialization of VM]
But I don’t send anything to the output before the first round.
My Bot is written in Java. Does anybody else have this problem?

sorry about this. The issue has been fixed:

The number of turns keep changing randomly. now it is less than 10 turns all the time, it is even 3-4 turn!!!
in the code of the game I can see “theGameManager.maxTurns = 200”
But it is not valid.
Any idea how to handle this?

Are you sure your games are not ending because of a timeout ?
This causes an immediate loss whenever it happens.

Never mind made very silly mistake.

I have just started Code Royale. This is very basic, but I was just wondering what the command to build a barrack at the queen’s closest building site is. Many thanks.

All needed information can be found in the statement below the viewer:

Yeah, I found it. Thanks

Hi, I’m not sure if I’m missing something, but in the description it says that the response time for the first move is 1s. I’d like this second to calculate the best route between structures, but I don’t know on where my queen is until the first turn… is there any way to know on which side I start before the game loop?

it seems there isn’t, although, if you look at the referee, you could get an idea:

but, the first iteration of the while loop is the first turn, so you can use the time there, can’t you?


Ah obviously, that makes sense.

I know this is an old puzzle, but if anyone can help that’d be great.

I’ve got everything working (at least, I think it does) for the first level in ruby… but the code is taking longer than the allowed time. I’m still pretty new to this stuff in general, and don’t know much about optimizing.

Can anyone give some advice on ways to get this moving fast enough?