Ants will select the square that is best for them based on a algorithm that will take into account food, pheromone, other ants and obstacles.
If all surrounding grid squares are empty then the ant should continue in the same direction. If the only objects within the grid squares are obstacles then these shouldn't affect the ant, unless there is an obstacle in the square in front of it. So if the ant encounters an obstacle in the direction of its next move it should turn around and move the other way (the same goes for another ant - which should be treated as an obstacle).

Figure 1 - 8 Possible directions.
Examples

Figure 2 - The grid squares contain different strengths of pheromone with 5 being the strongest. The ant should choose square 5.

Figure 3 - The grid squares 3, 4 and 5 again contain pheromone, but squares 6 and 7 contain food. The ant should choose either of these.

Figure 3 - The grid squares 1, 8 and 7 contain an obstacle. The ant should choose grid square 4 to move away from it.
