Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (604) Games in Android Showcase (171) games submitted by our members Games in WIP (654) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Help implementing path finding.  (Read 1348 times) 0 Members and 1 Guest are viewing this topic.
syrinth

Senior Newbie

 « Posted 2011-06-29 00:36:30 »

Hello all, I've looked at the sample pages listed in the pathfinding for beginners thread, and yet I'm still having problems implementing my pathfinding. The following code returns a path, and I'm sure the total value is the shortest path.

Unfortunately, what it does is it uses all the horizontal distance first, and then travels diagonally. This creates a very unnatural form of movement. I was hoping someone could help me?

I am using the Chebyshev distance equation listed at http://theory.stanford.edu/~amitp/GameProgramming/Heuristics.html#S7 to calculate the heuristic, I've checked to ensure that the G values are all being added properly and both forms of movement cost the same... What am I doing wrong?

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48 `public void pathFind(Node target){      this.target = target;      open.add(node);      target.setG(0);      Node current = node;      Node min = null;      while(!open.isEmpty()){         for(int i=0; i
 « Reply #1 - Posted 2011-06-29 04:04:49 »

can't understand question without drawing
Jono
 « Reply #2 - Posted 2011-06-29 06:56:11 »

Because the horizontal and diagonal moves both reduce the Chebyshev distance by the same amount (1), it just comes down to the ordering of the neighbours. I'd guess that your getNeighbours() method returns the horizontal move first and in case of ties your open list returns the earlier node.

One work-around is to add a penalty value in addition to f and g. Say, for each consecutive horizontal move add a 0.001 penalty. Just make sure that the penalty values for an entire path never add up to more than the cost of one move.
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 bilznatch (18 views) 2015-08-04 11:03:17 SHC (38 views) 2015-08-01 03:58:20 Jesse (24 views) 2015-07-29 04:35:27 Riven (44 views) 2015-07-27 16:38:00 Riven (25 views) 2015-07-27 15:35:20 Riven (27 views) 2015-07-27 12:26:13 Riven (18 views) 2015-07-27 12:23:39 BurntPizza (40 views) 2015-07-25 00:14:37 BurntPizza (48 views) 2015-07-24 22:06:39 BurntPizza (33 views) 2015-07-24 06:06:53
 theagentd 50x wessles 49x basil_ 33x KaiHH 26x orangepascal 25x Riven 21x ags1 17x mooman219 17x bornander 16x KudoDEV 13x CelestialCreator 11x klaus 11x princec 11x pquiring 11x Jesse 9x philfrei 8x
 List of Learning Resourcesby gouessej2015-07-09 11:29:36How Do I Expand My Game?by bashfrog2015-06-14 11:34:43List of Learning Resources2015-05-31 05:37:30Intersection Methodsby Roquen2015-05-29 08:19:33List of Learning Resources2015-05-05 10:20:32How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21
 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