//the main loop
while (nextMove != null)
{
// connect current with the possible move that has minimum number of its (possible moves)
graph.insertEdge(parent, null, null, oldMove, nextMove);
resultPath.add(nextMove);
// that vertex becomes the current vertex and we repeat until no possible moves
currValue = (int) costFunction.getCost(new mxCellState(view, nextMove, null));
currCoords = getVertexGridCoords(xDim, yDim, currValue);