Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (754)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
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 2154 times)
0 Members and 1 Guest are viewing this topic.
Offline Gibbo3771

JGO Kernel

Medals: 128
Projects: 5
Exp: 1 year

Currently inactive on forums :(

« Posted 2014-04-15 10:09:12 »


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:


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  

DesertCoockie (22 views)
2018-05-13 18:23:11

nelsongames (73 views)
2018-04-24 18:15:36

nelsongames (68 views)
2018-04-24 18:14:32

ivj94 (751 views)
2018-03-24 14:47:39

ivj94 (81 views)
2018-03-24 14:46:31

ivj94 (605 views)
2018-03-24 14:43:53

Solater (97 views)
2018-03-17 05:04:08

nelsongames (170 views)
2018-03-05 17:56:34

Gornova (388 views)
2018-03-02 22:15:33

buddyBro (1048 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!