Map scanning keeps crashing

I wrote into the game_state:
def contains_unit_of_type(self, type, location):
x, y = map(int, location)
if self.game_map[x,y] == None: return False
for unit in self.game_map[x,y]:
if unit.unit_type == type:
return unit
return False
and into the algo strategy:
if(game_state.contains_unit_of_type(DESTRUCTOR,[14,14])):
but its keeps crashing.Any idea how can i fix it?

Try using the Playground, as that’ll print a traceback of the crash. If it crashes every turn, just reupload the algo and have it play something in the playground before it gets disabled for crashing.

def contains_unit_Location(self,location):
    x,y=map(int,location)
for unit in self.game_map[x,y]:
        if unit.location == game_map[x,y]:
            return unit.location
return False

for unit in self.game_map[x,y]:
^
TabError: inconsistent use of tabs and spaces in indentation

its still doesnt work and i dont understand what it means on taberror.
anywho know where is the coding error?

The python langage relies on indentation (the white space at the beginning of a line) to decide the block of code each instruction belongs to.
So in the code you uploaded, if I use curly brackets to delimit each block of instruction, it would be like that:

def contains_unit_Location(self,location):
{
    x,y=map(int,location)
}
for unit in self.game_map[x,y]:
{
        if unit.location == game_map[x,y]:
        {
            return unit.location
        }
}
return False

I believe you meant something like this:

def contains_unit_Location(self,location):
    x,y=map(int,location)
    for unit in self.game_map[x,y]:
        if unit.location == game_map[x,y]:
            return unit.location
    return False

I would advise you to use a true IDE instead of a normal text editor, that would highlight most of those mistakes. Particularly you could have some problems if you mix tabs and spaces in a normal text editor.

2 Likes

thanks it works better :slight_smile: