Corrected direction priority to break ties

When two equal directions are picked, ghosts prefer north > west > south
> east.
Switched to range-based loop as cleaner and allows required iteration
order.