Code Royale - Puzzle Discussion


#43

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

minimo = []
for i in range(num_sites):
    minimo.append(sites[i].dist_site)
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.


#44

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.


#45

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!