Stop 2 gameObjects from occupying same tile

In the scene I am creating, everytime the player moves one tile, all AI objects on the map also move one tile in a random direction (UP, DOWN, LEFT or RIGHT).

The problem I ran into is how do I stop two AI objects from moving into the same tile. Because they all move simultaneously when an event is dispatched by the player having finished its movement, I can’t quite figure out a solution to this.

I don’t need the code, just an idea on how it could be achieved.

Many thanks in advance.

As it turns out it was actually quite simple. Because all methods run in a thread, altough it seems simultaneously, it is not. So in the NextRandomTile() method which decides which tile the enemy goes next, I’ve added a new line to change the next tile’s status to willHaveEnemy=true. The status will be changed to false on next turn when enemy lands on it. So now all enemies check the next tile for it’s status and only pick that if willHaveEnemy is false.