// addWall on both sides func (m *Maze) addWall(c common.Coordinate, dir int) { nb := c.Neighbor(dir) if m.contains(nb) { r, _ := m.GetRoom(c.X, c.Y) r.AddWall(dir) r, _ = m.GetRoom(nb.X, nb.Y) r.AddWall(common.ReverseDirection[dir]) } }
// pickNeighbor selects a neighboring unexplored coordinate func pickNeighbor(coordinate common.Coordinate, explored map[common.Coordinate]Survey) (common.Coordinate, int, bool) { survey := explored[coordinate] idxs := rand.Perm(len(allDirections)) for _, idx := range idxs { dir := allDirections[idx] if !survey.HasWall(dir) { neighbor := coordinate.Neighbor(dir) if _, ok := explored[neighbor]; !ok { return neighbor, dir, true } } } return coordinate, 0, false }