The algorithm itself does not need to be changed. A-star can work on any type of graph. A grid is a graph. Graphs have nodes and edges. Nodes are the places your search algorithm can visit. Edges are the connections between nodes.
Empty grids have graphs like this:
1 2 3 4 5 6 7
| +E+E+E+E+E+E+E+E+E+E+ E E E E E E E E E E E +E+E+E+E+E+E+E+E+E+E+ E E E E E E E E E E E +E+E+E+E+E+E+E+E+E+E+ E E E E E E E E E E E +E+E+E+E+E+E+E+E+E+E+ |
Grids with occupied squares have graphs like this
1 2 3 4 5 6 7
| +E+E+E+E+E+E+E+E+E+E+ E E E E E E E E E E +E+E+ +E+E+E+E+E+E+ E E E E E E E E E +E+E+E+E+E+E+ +E+E+ E E E E E E E E E E +E+E+E+E+E+E+E+E+E+E+ |
Grids with walls on their cell edges have graphs like this:
1 2 3 4 5 6 7
| +E+E+E+E+ +E+E+E+E+E+ E E E E E E E E E E E +E+E+ +E+ +E+ +E+E+E+ E E E E E E E E E E E +E+E+ +E+ +E+ +E+E+E+ E E E E E E E E E E E +E+E+ +E+E+E+ +E+E+E+ |
When adding nodes to the list you add the neighboring node
if(!grid.edgeBlocked(currentCell, aNeighbor) && !grid.isOccupied(aNeighbor)) |
instead of
if(!grid.isOccupied(aNeighbor)) |