r/ProgrammerHumor • • Jun 10 '23

[deleted by user]

[removed]

12k Upvotes

615 comments sorted by

View all comments

Show parent comment

19

u/other_usernames_gone Jun 10 '23

Pledge algorithm also works.

Pick a direction (helps if it's the rough direction of the exit) and "pledge" to always go in that direction when possible.

When you hit a wall hug it and follow it round but disconnect when you're facing in your pledged direction(and the sum of angles turned is a multiple of 360).

It stops you getting trapped in a disconnected segment in the middle of the maze.

A Wikipedia article full of maze solving algorithms

7

u/Hubcat_ Jun 10 '23

This kind of reminds me of how greedy path finding algorithms search