Game_map[ship.position.directional_offset(move)].is_empty returns True wille only one ship on a map


#1

Hi everybody,
Im using Pyton 3. I want to teach bots don’t stay in traffic jams. There is one pice of code:

move = game_map.naive_navigate(ship, target)

if (not game_map[ship.position.directional_offset(move)].is_empty):

On the second turn code in if block performs. Target is not equel to ship.position
What can be wrong?

Some extra info:
if block:

if (not game_map[ship.position.directional_offset(move)].is_empty):
logging.info(“because {}”.format(not game_map[ship.position.directional_offset(move)].is_empty))
logging.info(“ship want to go {}”.format(move))
move = ((move[0] + 1) % 2, (move[1] + 1) % 2)
logging.info(“but go {} because {}”.format(move, not game_map[ship.position.directional_offset(move)].is_empty))

logs:
INFO:root:because True
INFO:root:ship want to go (1, 0)
INFO:root:but go (0, 1) because False

It’s Turn 2, so there are only 1 ship standing on the shipyard.


#2

You are testing “move” then changing changing move and logging that. Try _move = ((move[0] + 1) % 2, (move[1] + 1) % 2)
Then log _move instead.


#3

Thanks, you are right.


#4

Maybe you can help me with new problem?


#5

What’s the other problem?


#6

I changed original post


#8

Looks like I figured out what is wrong. Instance MapCell has parameter ship, and it can be ship wich moving to this location too, not only i=one standing there.