I was trying to implement a shortest path algorithm in python. I ran into some trouble when I attempted to connect my points on the path.
I have a class called NODE I made an array of these nodes and then created new nodes in them like this:
nodes = []
for r in range ( 0, 3 ):
for c in range ( 0, 3 ):
nodes.append( NODE( c*WIDTH/20 + 30, r*HEIGHT/20 + 30, 10 ) )
This created nodes, which is fine, I can draw them just fine.
At first I attempted connecting them by adding a list of node objects into the the NODE class. I ran into some issues, I thought the problem is with the recursive classes, so to test I did this.
Where connections is a blank array within the NODE class.
nodes[0].connections.append( 0 )
print nodes[0].connections
nodes[1].connections.append( 1 )
print nodes[1].connections
print nodes[0].connections
This is where I found the problem, Maybe I'm just being stupid, or It's a language thing ? Dunno, but I thought I'd ask.
The output is this:
[ 0 ]
[ 0, 1 ]
[ 0, 1 ]
As you can see, I only added 1 object to the connections list in the index 1. However when I print the contents, I see two.... And this confuses me.