AI path finder using a recursive function