8-puzzle - Functions not working correctly

Which loop is that?