declare all paths
This commit is contained in:
parent
596a77db59
commit
65576c9331
|
@ -192,18 +192,17 @@ func (maze *Maze) Solve() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (maze *Maze) explorePaths(currentRoom Room, endRoom string, currentPath []string, paths *[]string) {
|
func (maze *Maze) explorePaths(currentRoom Room, endRoom string, currentPath []string, paths *[]string) {
|
||||||
currentPath = append(currentPath, currentRoom.name) // is the end room
|
currentPath = append(currentPath, currentRoom.name)
|
||||||
|
|
||||||
if currentRoom.name == endRoom { // is the end room
|
if currentRoom.name == endRoom { // is the end room
|
||||||
*paths = append(*paths, strings.Join(currentPath, " -> "))
|
*paths = append(*paths, strings.Join(currentPath, " -> "))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Explore all possible paths from current room
|
// explore all possible paths from current room
|
||||||
for _, nextRoomName := range currentRoom.paths {
|
for _, nextRoomName := range currentRoom.paths {
|
||||||
for _, room := range maze.rooms {
|
for _, room := range maze.rooms {
|
||||||
if room.name == nextRoomName {
|
if room.name == nextRoomName {
|
||||||
// Explore next room if it's not already visited
|
|
||||||
if !contains(currentPath, room.name) {
|
if !contains(currentPath, room.name) {
|
||||||
maze.explorePaths(room, endRoom, currentPath, paths)
|
maze.explorePaths(room, endRoom, currentPath, paths)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue