A Self-Avoiding Walker in SwiftUI

Creating a snake that’s scared of itself

Mark Lucking
Better Programming
Published in
2 min readOct 12, 2022

--

Walker trying to avoid itself. Backtracking if needed

Having built a snake game the other day, it occurred to me that I might use the source to build something similar and yet different: a self-avoiding walker. Turns out, this task is harder than you may think.

The goal is to modify the snake source so that it creates an ever-growing snake that never runs into…

--

--

Coding for 35+ years, enjoying using and learning Swift/iOS development. Writer @ Better Programming, @The StartUp, @Mac O’Clock, Level Up Coding & More