Ok, here's my final for pathfinding:
it works fine (all status start "CLOSED"), on matrices under 7*7, but it hangs on bigger ones. I've made it sweet and simple but not so efficient... any ideas?
(my previous post on the issue)http://cboard.cprogramming.com/showthread.php?t=112079
Code:
long int GetMin(Node** matrix,int currentR,int currentC,int endR,int endC,
int rows,int columns)
{
long int result;
//if out of bounds return max of field
if (currentR==rows || currentC==columns || currentR<0 || currentC<0)
return LARGE;
//if reached end
if (currentC==endC && currentR==endR)
return (matrix[currentR][currentC].value);
//if already checked here
if (matrix[currentR][currentC].status==OPEN)
return LARGE;
//if not reached end
matrix[currentR][currentC].status=OPEN;
result=Smallest4(
GetMin(matrix,currentR,currentC+1,endR,endC,rows,columns),
GetMin(matrix,currentR,currentC-1,endR,endC,rows,columns),
GetMin(matrix,currentR+1,currentC,endR,endC,rows,columns),
GetMin(matrix,currentR-1,currentC,endR,endC,rows,columns));
//set current status to closed- can try here again
matrix[currentR][currentC].status=CLOSED;
//if was blocked all directions
if (result==LARGE)
return LARGE;
return matrix[currentR][currentC].value+result;
}
oh, and of course
Code:
#define LARGE LONG_MAX