Can someone tell me what mistake I'm making in this usage of game_map._get_target_direction()?


#1

I’m making some sort of a mistake that’s bound to be ridiculously obvious in hindsight, I’d wager.

In the following code snippet’s first statement, I’m able to verify that current_assignments[ship.id].destination is, indeed, a tuple that appears to be a standard position. Obviously, in the second, ship.position is also a standard position.

        glo.Misc.loggit('core', 'debug', " -* destination: " +
                        str(glo.Variables.current_assignments[ship.id].destination))
        glo.Misc.loggit('core', 'debug', " -* target's direction: " +
                        game_map._get_target_direction(ship.position,
                                                       glo.Variables.current_assignments[ship.id].destination))

Why, then, do I have the interpreter telling me that (as far as I can deduce) I’m not using the right kind of arguments to this method, with the following error message?

[error] [3] [P1] File “/home/sprite/src/py/haliteIII/nightMiner/custom_routines/seek_n_nav.py”, line 140, in scoot
[error] [3] [P1] current_assignments[ship.id].
[error] [3] [P1] File “/home/sprite/src/py/haliteIII/nightMiner/hlt/positionals.py”, line 75, in directional_offset
[error] [3] [P1] return self + Position(*direction)
[error] [3] [P1] File “/home/sprite/src/py/haliteIII/nightMiner/hlt/positionals.py”, line 84, in add
[error] [3] [P1] return Position(self.x + other.x, self.y + other.y)
[error] [3] [P1] TypeError: unsupported operand type(s) for +: ‘int’ and ‘tuple’

If it makes any difference, I’ve also run into the error, previously, that I was trying to add an ‘int’ with ‘NoneType’, as well. I don’t recall the exact code changes from that point, though, so it’s almost certainly moot right now.

Thank you very much for any pointers in the right direction; I will make certain to slam my forehead into the desk when it becomes apparent how obvious my mistake should have been.

TIA


#2

Oh, and for what it’s worth, I did, indeed, notice that the 2nd logging statement in the code snippet above was missing the str() wrapping around the erroneous statement. That’s since been corrected. Of course it has nothing to do with the matter really at hand, though.


#3

I believe this is occurring when your target direction is None.

If you are determining your target with naive_navigate(), or something similar, and no safe moves are available, it would return Direction.Still.

get_target_direction() would then return a tuple containing None, instead of an int (enum of Direction).

directional_offset() is then unable to ‘return Position(self.x + other.x, self.y + other.y)’, since it’s trying to add an int and tuple (Position(self.x + {None}, self.y + {None}).

Hope this helps.


#4

Sso I think that I’ve located the reason that things are happening like this. It seems that it only occurs when the entity or position that I’m trying to navigate to is on the same row or column as my start coordinates. Thus it appears that a tuple is being generated for n/s and one for e/w, possibly…?

Either way, I’m now utilizing a cheap hack which I still have not checked for accuracy. I’m just stripping the outside tule of the None value, if it exists, and use the remaining one. I’ll go back after work and study the Direction object a little better to try to see if this is I’ll be somewhat accurate or not after work. :slight_smile: guess I can can’t at h a game play now to see how it goes, too.

More later!