I'm a little lost at the moment (can't seem to wrap my head around it) so I thought I'd try here. I have created an ActionScript3 implementation of A* and I'm wondering if I could have a little bug in my implementation. I can't think of a situation where it might go wrong, but maybe you guys can.
So, here's a little fragment of my code:
//loop over all the neighbours of the current nodewhile(i-- > [[0]]){ //cN is the current neighbor that is being examined cN = neighbours as DataTile; //makes sure that cN.getCost() is multiplied by [[[1]]].[[[4]]] if this path is diagonalcN.setDiag(_map.isDiagonal(current.getPosition(), cN.getPosition())); if(!cN.getOpen()) { //add to open-array openTile(cN, cN.getPosition(), current.getG(), this._end, current); } else { //already in open, check if F via current node is lower newF = cN.calculateUpdateF(current.getG()); if(newF < cN.getF()) { pos = this._heap.getPosition(cN); cN.setParent(current); cN.setG(current.getG()); this._heap.update_heap(pos); } }}
I think the code is pretty self explanatory, but if it's not, just let me know.
Now, the actual question: I think that 'cN.setDiag()' shouldn't be there. setDiag() makes sure that getCost() is multiplied by 1.4 if you access it diagonally. I think that the multiplier should only be used in calculateUpdateF (since you might want to access the tile diagonally) and right before/after calling setParent()
getCost() is used in calculateUpdateF() and is of course used in the getF() that's used by my binary heap to get the next best option.
If I'm asking for too much or my code isn't clear enough or anything else, just let me know.
Thanks!