Self Avoiding Walk
Coding Challenge #162
It’s finally time to attempt a Self-Avoiding Walk! In this video, I quickly visualize a simple JavaScript p5.js implementation of a self-avoiding walk. I then tackle the more complex problem of backtracking to find a solution to a space-filling self-avoiding walk.
Topics
- 0:00 - Choo choo! Welcome!
- 1:05 - Explain! How can we go about this?
- 2:29 - Code! Let's add a visited grid.
- 6:25 - Code! What are the options for movement now?
- 10:34 - Code! Let's check the edges.
- 12:34 - I could stop here but wait.
- 13:30 - Explain! How can we think about backtracking?
- 15:15 - Code! Let's make a spot class and a path variable.
- 24:23 - Code! Now backtracking!
- 29:38 - Whoops! Copying allOptions was a mistake.
- 31:19 - Code! Maybe we need an end condition.
- 32:09 - Yay! It worked.
- 32:22 - This could take awhile. Could it be improved?
Community Contributions
You can also add your own version! (See how)
Links discussed in this coding challenge
Videos discussed in this coding challenge
- Random Walker - Coding Challenge 52 by The Coding Train
- Minesweeper - Coding Challenge 71 by The Coding Train
- filter() - Array Functions by The Coding Train
- Maze Generator - Coding Challenge 10 by The Coding Train
- Recursion - Coding Train 77 by The Coding Train
- A* Pathfinding Algorithm - Coding Challenge 51 by The Coding Train
- 3D Self Avoiding Walk - Coding Train Live (May 27, 2021) by The Coding Train