The dancing ant problem occurs when an ant's best choice for a next move is a square that it has just moved from. This can occur when it hits an obstacle, because it hits the obstacle turns around and moves back again because it is the 'best' choice.
In Figure 1 the ant's (red square) best choice is to move into position 8 because of the pheromone deposited there.

Figure 1
In Figure 2 the ant has moved into the square with the pheromone but has hit an obstacle (black squares). My algorithm now tells the ant to turn in the opposite direction. The leads it to the same state as in Figure 1, and the ant therefore continues the process until the pheromone evaporates.
Figure 2