Thanks for the looky! Those are millisecs, not seconds. I was thinking 3 millisecs was pretty fast considering that it could do that same routine 300 more times before getting even close to 1 second. Hahahaha. Until I saw Appels that is.
I am thinking that main slowdown is when I gather and set all the neighbor cells. It takes 6 checks to make sure each neighbor cell is valid, than it sets each cell’s f,g,h and parent values. It must do this 8 times for each cell that gets checked on the openlist to determine if the cell is valid and should be put on the openlist. This was the main problem in my code that took me a day to figure out. I dont think it can be broke, I tested it many many times on blocked targets and inaccessible targets, plus different size maps, etc. I cant think of any other way of checking and setting the neighbor cells. Ive looked through tons and tons of examples and source but cant really get a grip on how other people do it.
Heres the code that checks and sets the neighbor cells, topleft, top, topright, left, right, bottomleft, bottom, and bottomright cells of current cell being checked…
//Add adjacent squares to the openlist unless they are already there
//or they are on the closed list
//If they are already on the open list, supposed to check them for a better path
//TopLeft Cell
int celNum = currCell-(mapRow+1);
int totCells = mapRow*mapCol;
if(celNum > -1 && celNum < totCells && cell[celNum].block == 0){
if(cell[celNum].row == cell[currCell].row-1 && cell[celNum].col == cell[currCell].col-1){
if(cell[celNum].listType == 0){
addOpenList(celNum);
cell[celNum].gVal = cell[currCell].gVal+14;
cell[celNum].hVal = findDistance(celNum,tCell);
cell[celNum].fVal = cell[celNum].gVal+cell[celNum].hVal;
cell[celNum].parent = currCell; //Make currCell the parent of adjacent cells
//System.out.println("1Checked topleft cell "+celNum);
}
}
}
//TopCell
celNum = currCell-(mapRow);
if(celNum > -1 && celNum < totCells && cell[celNum].block == 0){
if(cell[celNum].row == cell[currCell].row-1 &&cell[celNum].col == cell[currCell].col){
if(cell[celNum].listType == 0){
addOpenList(celNum);
cell[celNum].gVal = cell[currCell].gVal+10;
cell[celNum].hVal = findDistance(celNum,tCell);
cell[celNum].fVal = cell[celNum].gVal+cell[celNum].hVal;
cell[celNum].parent = currCell; //Make currCell the parent of adjacent cells
//System.out.println("2Checked top cell "+celNum);
}
}
}
//TopRight Cell
celNum = currCell-(mapRow-1);
if(celNum > -1 && celNum < totCells && cell[celNum].block == 0){
if(cell[celNum].row == cell[currCell].row-1 &&cell[celNum].col == cell[currCell].col+1){
if(cell[celNum].listType == 0){
addOpenList(celNum);
cell[celNum].gVal = cell[currCell].gVal+14;
cell[celNum].hVal = findDistance(celNum,tCell);
cell[celNum].fVal = cell[celNum].gVal+cell[celNum].hVal;
cell[celNum].parent = currCell; //Make currCell the parent of adjacent cells
//System.out.println("3Checked topright cell "+celNum);
}
}
}
//Left Cell
celNum = currCell-1;
if(celNum > -1 && celNum < totCells && cell[celNum].block == 0){
if(cell[celNum].row == cell[currCell].row &&cell[celNum].col == cell[currCell].col-1){
if(cell[celNum].listType == 0){
addOpenList(celNum);
cell[celNum].gVal = cell[currCell].gVal+10;
cell[celNum].hVal = findDistance(celNum,tCell);
cell[celNum].fVal = cell[celNum].gVal+cell[celNum].hVal;
cell[celNum].parent = currCell; //Make currCell the parent of adjacent cells
//System.out.println("4Checked left cell "+celNum);
}
}
}
//Right Cell
celNum = currCell+1;
if(celNum > -1 && celNum < totCells && cell[celNum].block == 0){
if(cell[celNum].row == cell[currCell].row &&cell[celNum].col == cell[currCell].col+1){
if(cell[celNum].listType == 0){
addOpenList(celNum);
cell[celNum].gVal = cell[currCell].gVal+10;
cell[celNum].hVal = findDistance(celNum,tCell);
cell[celNum].fVal = cell[celNum].gVal+cell[celNum].hVal;
cell[celNum].parent = currCell; //Make currCell the parent of adjacent cells
//System.out.println("5Checked right cell "+celNum);
}
}
}
//BottomLeft Cell
celNum = currCell+(mapRow-1);
if(celNum > -1 && celNum < totCells && cell[celNum].block == 0){
if(cell[celNum].row == cell[currCell].row+1 && cell[celNum].col == cell[currCell].col-1){
if(cell[celNum].listType == 0){
addOpenList(celNum);
cell[celNum].gVal = cell[currCell].gVal+14;
cell[celNum].hVal = findDistance(celNum,tCell);
cell[celNum].fVal = cell[celNum].gVal+cell[celNum].hVal;
cell[celNum].parent = currCell; //Make currCell the parent of adjacent cells
//System.out.println("6Checked Bottomleft cell "+celNum);
}
}
}
//Bottom Cell
celNum = currCell+(mapRow);
if(celNum > -1 && celNum < totCells && cell[celNum].block == 0){
if(cell[celNum].row == cell[currCell].row+1 &&cell[celNum].col == cell[currCell].col){
if(cell[celNum].listType == 0){
addOpenList(celNum);
cell[celNum].gVal = cell[currCell].gVal+10;
cell[celNum].hVal = findDistance(celNum,tCell);
cell[celNum].fVal = cell[celNum].gVal+cell[celNum].hVal;
cell[celNum].parent = currCell; //Make currCell the parent of adjacent cells
//System.out.println("7Checked bottom cell "+celNum);
}
}
}
//BottomRight Cell
celNum = currCell+(mapRow+1);
if(celNum > -1 && celNum < totCells && cell[celNum].block == 0){
if(cell[celNum].row == cell[currCell].row+1 &&cell[celNum].col == cell[currCell].col+1){
if(cell[celNum].listType == 0){
addOpenList(celNum);
cell[celNum].gVal = cell[currCell].gVal+14;
cell[celNum].hVal = findDistance(celNum,tCell);
cell[celNum].fVal = cell[celNum].gVal+cell[celNum].hVal;
cell[celNum].parent = currCell; //Make currCell the parent of adjacent cells
//System.out.println("8Checked bottomright cell "+celNum);
}
}
}
If anyone sees anything that could help speed this up, it would be greatly appreciated. As I said, Ive looked at others codes and tried chasing down this step, but it seems to be elluding me.