From 11ce2203475f128500233a3bc06682e07214849a Mon Sep 17 00:00:00 2001 From: hhlal Date: Sun, 12 May 2024 21:00:20 +0300 Subject: [PATCH] try to get paths --- examplr00.txt | 10 ++++++++++ maze/maze.go | 32 ++++++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 examplr00.txt diff --git a/examplr00.txt b/examplr00.txt new file mode 100644 index 0000000..b1f8a48 --- /dev/null +++ b/examplr00.txt @@ -0,0 +1,10 @@ +4 +##start +1 2 3 +##end +3 5 2 +2 5 6 +1-3 +1-2 +2-3 +3-2 diff --git a/maze/maze.go b/maze/maze.go index 4d031d5..672cd97 100644 --- a/maze/maze.go +++ b/maze/maze.go @@ -15,12 +15,15 @@ type Maze struct { } type Room struct { - connections []Room distance int name string occupancies int + paths []string } + var collection [][]string + + // Load method to load the maze from input func Load(inputStream *bufio.Reader) *Maze { maze := &Maze{} @@ -148,7 +151,7 @@ func (maze *Maze) mapFarm(line string) bool { log.Printf("Mapping connection between rooms: %s and %s\n", room1Name, room2Name) // Find room objects by name - var room1, room2 *Room + var room1,room2 *Room for i := range maze.rooms { if maze.rooms[i].name == room1Name { room1 = &maze.rooms[i] @@ -165,11 +168,32 @@ func (maze *Maze) mapFarm(line string) bool { } // Establish connection between rooms - room1.connections = append(room1.connections, *room2) - room2.connections = append(room2.connections, *room1) + // room1. = append(room1.connections, *room2) + // room2.connections = append(room2.connections, *room1) + collection = append(collection, []string{room1Name, room2Name}) return true } func (maze *Maze) Solve() { log.Println("Solving the maze...") + //l want to declare all paths + var path string; + var currentcol = collection[0][0] + var flage bool + + for !strings.HasPrefix(currentcol, maze.endRoom){ + + if strings.HasPrefix(currentcol, maze.startRoom) { + path = currentcol + flage = true + break + } + + if flage { + + } + } + + log.Println(collection) + }