A* algorithm implementation in java
<p>I am having problems figuring out how to implement parts of the A* algorithm in java. I have a decent amount of the code completed and have filled out the rest with psuedocode, which I am having trouble implementing.</p>

<p>The trouble for me comes with calculating the g cost of the cells and deciding if there is a shorter path to the neighbor cell.</p>

<p>Main A* class:</p>

<pre><code>import acm.util.*;
import java.awt.*;
import java.util.*;

/**
 * Write a description of class AStarMain here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */

public class AStarMain
{
    // instance variables
    private ArrayList&lt;AStarCell&gt; open = new ArrayList&lt;AStarCell&gt;(); //list of open cells
    private ArrayList&lt;AStarCell&gt; closed = new ArrayList&lt;AStarCell&gt;();//list of closed cells
    private ArrayList path = new ArrayList(); //will hold the path once found
    public static AStarCell[][] grid = new AStarCell[25][25]; //grid of cells
    private int startRow, startCol; //staring point for the search
    private int endRow, endCol; //destination
    private boolean pathFound = false;
    private AStarCell current; //current cell

    public AStarMain(int startRow, int startCol, int endRow, int endCol){

        open.add(grid[startRow][startCol]); //add the starting cell to the open list
        current = open.get(0); //set the current cell to the starting cell

        while(!pathFound &amp;&amp; open.size()&gt;0){
            //loop through the open array list, find the cell with the lowest cost
            for(int i = 0; i &lt; open.size(); i++){
                if(open.get(i).getFinalCost() &lt; current.getFinalCost()){
                    current = open.get(i);
                }
            }
            //remove the found cell from the open list
            open.remove(current);
            //add the cell to the closed list
            closed.add(current);

            //check if a path has been found
            if(current.getRow() == endRow &amp;&amp; current.getCol() == endCol){
                pathFound = true;
                constructPath();
            }

            //consider each vertical and horizontal neighbor of the current cell
            consider(grid[current.getRow()-1][current.getCol()]);
            consider(grid[current.getRow()+1][current.getCol()]);
            consider(grid[current.getRow()][current.getCol()-1]);
            consider(grid[current.getRow()][current.getCol()+1]);
        }
    }

    private void consider(AStarCell passedCell){
        //if the neighbor cell is not passable or is already on the closed list, skip it
        if(!passedCell.getIsPassable() || closed.contains(passedCell)){
            return;
        }


        //calculate the path cost of reaching the neighbor
        //if the cost is less than the cost known for this location then remove it from 
        //the open or closed lists (since you've found a better route)
        //if the location isn't in either the open or closed list then record the costs for the
        //location and add it to the open list
        //record the parent for this cell

    }

    private void constructPath(){
        //once a path has been found, trace it backwards adding each step to the path ArrayList
    }
}
</code></pre>

<p>Cell class:</p>

<pre><code>/**
 * Write a description of class AStarCell here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class AStarCell
{
    public static final int VHCost = 10;

    // instance variables
    private int hCost = 0;
    private int gCost = 0;
    private int finalCost = 0; //G+H
    private int row, col; //location in grid of cells
    private AStarCell parent; //parent cell
    private boolean isPassable = true;


    AStarCell(int row, int col){
        this.row = row;
        this.col = col;
    }

    public int getFinalCost(){
        return finalCost;
    }

    public boolean getIsPassable(){
        return isPassable;
    }

    public int getCol(){
        return col;
    }

    public int getRow(){
        return row;
    }

}
</code></pre>