Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: A* algorithm help

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default A* algorithm help

    I have tried to use the piece of code to test out the A* algorithm and when I run it the values I get are wrong, can someone try and tell me if their are any gaping errors which i missed, If anyone doesn't know what the A* algorithm is, It is the algorithm used for path finding. Thanks in advanced

    public int[] pathfind(int currentX, int currentY, int finalX , int finalY)
        {
            int[][] grid = new int[3][3];
            int[] lowVals = new int[3];
            lowVals[2] = 2000000;
            for (int i = 0; i < 3; ++i)
            {
                for (int s = 0; s < 3; ++s)
                {
                    grid[i][s] = (finalX - currentX + (i-1) + finalY - currentY + (s-1));
                    if (grid[i][s] < lowVals[2])
                    {
                        lowVals[0] = i;
                        lowVals[1] = s;
                        lowVals[2] = grid[i][s];
                    }
                }
            }
            currentX += lowVals[0] - 1;
            currentY += lowVals[1] - 1;
            System.out.println(currentX + " " + currentY);
            return lowVals;
        }


  2. #2
    Junior Member
    Join Date
    Jul 2013
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: A* algorithm help

    Could you give us the output or the error messages ?

Similar Threads

  1. [SOLVED] Dijkstra's algorithm
    By dezett in forum What's Wrong With My Code?
    Replies: 7
    Last Post: October 22nd, 2012, 03:53 PM
  2. [SOLVED] What Algorithm Would Work Best for me?
    By userct in forum Algorithms & Recursion
    Replies: 4
    Last Post: February 20th, 2012, 05:38 PM
  3. all i need is algorithm
    By coder.freak in forum Paid Java Projects
    Replies: 3
    Last Post: April 6th, 2011, 11:11 AM
  4. [SOLVED] Algorithm Help
    By aussiemcgr in forum Java Theory & Questions
    Replies: 2
    Last Post: September 10th, 2010, 04:12 PM
  5. algorithm
    By AmmrO in forum Algorithms & Recursion
    Replies: 13
    Last Post: September 24th, 2009, 09:18 PM

Tags for this Thread