Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (491)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  A* NodeMap  (Read 415 times)
0 Members and 1 Guest are viewing this topic.
Offline Gibbo3771
« Posted 2014-04-15 10:09:12 »

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:

1  
2  
3  
4  
5  
   /** 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:

1  
2  
3  
4  
5  
6  
      /* 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:

1  
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.

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (15 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (29 views)
2014-08-22 19:31:30

atombrot (41 views)
2014-08-19 09:29:53

Tekkerue (38 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (25 views)
2014-08-16 06:20:21

Tekkerue (34 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (48 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!