0

I'm trying to make a map using "Graphnodes" and coordinates where it would form a grid. I'm doing this first filling every coordinate in with a graphnode, and then going back through and connecting them all up. When I'm going through it tells me that key {2,1} is not in the dictionary but when I check the dictionary, the key and graphnode ARE there.

For i = 1 To MapSize
    For j = 1 To MapSize
        If i = 1 And j = 1 Then
            temp = {i, j}
            nodes.Add(temp, rootNode)
        Else
            roomKeyVal += 1
            temp = {i, j}
            nodes.Add(temp, New graphNode With {.Key = roomKeyVal})
        End If
    Next
Next

For i = 1 To MapSize
    For j = 1 To MapSize
        If i = MapSize Then
            If j <> MapSize Then
                nodes({i, j}).South = nodes({i, j + 1})
                nodes({i, j + 1}).North = nodes({i, j})
            End If
        Else
            If j = MapSize Then
                nodes({i, j}).East = nodes({i + 1, j})
                nodes({i + 1, j}).West = nodes({i, j})
            Else
                nodes({i, j}).East = nodes({i + 1, j})
                nodes({i + 1, j}).West = nodes({i, j})
                nodes({i, j}).South = nodes({i, j + 1})
                nodes({i, j + 1}).North = nodes({i, j})
            End If
        End If
    Next
Next

I need to have an interconnected grid of graphnodes that I can "travel" through but it can't get past connecting the third graphnode.

P.S. if you need help understanding the code, let me know what.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Kijilas
  • 33
  • 6
  • Will need to make you coordinates their own class instead of an integer array. So you can implement an equatable implementation (overloading the inherited equal function). Right now it is just comparing if the two coordinate array objects are the same object not their respective values. – Ryan Roos Feb 04 '19 at 16:35
  • Alright thank you very much! – Kijilas Feb 04 '19 at 17:54

1 Answers1

0

Answered in comments. I changed the key in the dictionary from an array to one string. :)

Kijilas
  • 33
  • 6