Connors, I think 4450 is higher than any score I ever got. Pretty embarrassing considering how much I played the game for testing purposes.
That bug might have happened once to me while testing, and I couldn't figure out why it happened, since I call a function that resets all the variables after you lose. I might look at it again.
Gan, there is no algorithm. I just randomly place one of six possible tunnels (vertical, horizontal, and four bent tunnels) on the board. I've never run into a grid where there's no way to get to the end. I suppose that if all the pieces on the leftmost column were straight, then there would be no way to get to the end since you would be stuck in that column until you bumped into the start square.