A* NodeMap

Hi,

I have a NodeMap class for my A* algorithm that holds all my nodes in an array with some methods to do things.

I am struggling to make a decision about 2 fields in specific within this NodeMap:



	/** The nodes that are passable */
	private boolean[][] nodesPassable;

	/** The value of the nodes */
	private int[][] nodeValues;


These 2 fields, hopefully are self explanatory. Basically when I create my NodeMap I pass in 2 arrays that holds information about what is passable and the values of the nodes.

The array of nodes is just a 2D array like the above.

I also have a PathFinder class that has a one of these maps, well in this case they all have the same map.

Which is bad, because after I have finished moving to a path, the map needs reset. To my knowledge that means if I do this:



		/* Create our map and give it the array of passable nodes */
		Map map = new NodeMap(8, 8, nodesPassable, nodeValues);
		
		/* Create our apth finder and give it the map */
		PathFinder pathFinder = new PathFinder(map, new Heuristic());
		PathFinder pathFinder2 = new PathFinder(map, new Heuristic());


I pass the exact same map to both path finders, ideally every single NPC in my game will have their own path finder. No idea if that is wise or now, or if they should all use the same one.

Well now say one NPC just finished its path, I then call:



pathFinder.map.reset();


I feel stupid for asking this, but is that not going to reset the map for both pathfinders since I passed them the same map? Objects are pass by reference right?

So back to the problem with those 2 fields, if I was to go into my NPC class and create a new NPC, say I don’t have access to the array of passable nodes and node values, or say they have changed (The map can change), now what?

Well I was thinking I would make those 2 fields static and set them at run time, then I can adjust them for all maps with NodeMap.updateNodes() or something.

Would this be a viable work around? Or anyone got a better idea?

I would rather not have to fire those arrays around in a ton of constructors or even make them static, it seems to make more sense to make the actual fields inside the array static themself.

Means if the map changes I can simply get the position of the node within the array and change all the values from within any class.

EDIT: Might want to tell you reset actually does, it basically goes through all the nodes in the map and resets their previous node to null. As the path is built by setting the next node to check as the current node we just checked.

So the path gets build from destination to start.