Helper method for the self-avoiding walk.  Details in-file.  The code is so long (.... and hideous) that it is in its own file...