Linux Format

How to solve mazes using Go and maths

This month, we’re going delve into solving maze and dungeon puzzles with the help of graph theory (well, we are all in isolation–Ed). The purpose of such puzzles is to determine whether there’s a path that connects two places and find that path, keeping in mind that not all maze puzzles are solvable!

A maze is a path or a collection of paths. When we say that we want to solve a maze, we mean that we should find a way of going from the start cell (entrance), which is predefined, to the end cell (goal), which is also predefined. A similar way of thinking about solving a maze is routing through obstacles of various types from your current place to a given location. A maze might have multiple solutions, too.

To solve a maze, you just have to find a trail between the start and end points of the maze. Note that mazes can be implemented using undirected graphs and that if a maze contains isolated nodes or too many wall cells then it might not be solvable.

The way you represent a maze has nothing to do with the maze itself – it’s just a practical way of

You’re reading a preview, subscribe to read more.

More from Linux Format

Linux Format12 min read
Let’s Code Some Demos Like It’s 1990!
Ferenc Deák never throws anything away, which is why he still has all his demoscene files. Sadly, it also means his fridge is a no-go zone. It all started when this author’s beloved retro PC, used to host nostalgic gaming sessions, I suddenly suffer
Linux Format1 min read
Nvk Is Go!
"NVK, the open source Vulkan driver for Nvidia hardware in Mesa, is ready for prime time. The merge request has landed, getting rid of the nonconformant implementation warnings and signalling to distros that it’s now time to start shipping NVK to use
Linux Format3 min read
Kernel Watch
Linus Torvalds announced the fourth RC (Release Candidate) for what will become Linux 6.9 in another few weeks. In his announcement, he noted that there was “Nothing particularly unusual going on this week – some new hardware mitigations may stand o

Related Books & Audiobooks