Halite Home

List index out of range


I've recently submitted a new version of my bot and am getting regular errors in my games. The stack is:

Response received (if any):
Traceback (most recent call last):
--- Bot was killed. Below is the rest of its output (if any): ---
File "MyBot.py", line 40, in
if not movedPiece and gameMap.getSite(Location(y, x)).strength < 10:
File "/home/ubuntu/Halite/worker/workingPath/1810/hlt.py", line 96, in getSite
return self.contents[l.y][l.x]
IndexError: list index out of range

But the line before the problem code has 'if gameMap.getSite(Location(x, y)).owner == myID:' and that's working fine, how can the index be out of range for the .strength call but not for the .owner?

Thanks in advance




I think I might have a similar problem. I've looked it up a bit, and it seems that the calls to obtain the dimensions of the map give wrong values. For some seeds, when I simply do:

n = gameMap.height
m = gameMap.width
and print these values in a log file, m and n appear to be different from the actual dimensions of the board.

For instance, launching halite with 4 bots and the following specs:

halite -s 599140843 -d "35 35" "python RandomBot.py" "python RandomBot.py" "python RandomBot.py" "python MyBot.py"

gives me n = 34 and m =32 saved in a log file by the last bot.
Might be a silly mistake of mine as well :slight_smile:

Edit: to replicate the error, you can use the following "bot" which will crash instantly but saves the dimensions:


from hlt import *
from networking import *
import numpy as np

myID, gameMap = getInit()
gameMap = getFrame()
n = gameMap.height
m = gameMap.width
np.save("dim.npy", (m,n))

And then using halite:

halite -s 599140843 -d "35 35" "python Bot.py" "python Bot.py"

Finally, retrieving the dimensions in an IDE:

Outputs (34, 34), not (35, 35).


Those are the actual dimensions of the board.

From the game rules:

Tries to match the given width and height as closely as it can while still creating a symmetric map. Maps are guaranteed to be the given size or smaller in each dimension; never larger.

So you request a 35 by 35 and we give you something like a 32 by 34 to make it symmetric.


Ok that explains it ! Thank you a lot then and sorry for the waist of time.


Thanks for the update, that doesn't answer my issue though, right? The getSite() call should not give index errors the second time it's called.


Isn't it because the second time you pass (y, x) in the Location function rather than (x, y)?


blush, how did I miss that?!