Unit path algorithm