A* search algorithm: Difference between revisions

Content added Content deleted
Line 1,955: Line 1,955:
/*
/*
** Second method.
** Second method.
**
**
*/
/**
* calculate the cost from current node to goal.
* @param goal : goal
* @return : cost from current node to goal. use Manhattan distance.
*/
public int calculateCost(Coord goal){
int rState = this.getR();
int rGoal = goal.getR();
int diffR = rState - rGoal;
int diffC = this.getC() - goal.getC();
if(diffR * diffC > 0) { // same sign
return Math.abs(diffR) + Math.abs(diffC);
} else {
return Math.max(Math.abs(diffR), Math.abs(diffC));
}
}

public Coord getFather(){
return this.father;
}

public void setFather(Coord node){
this.father = node;
}

public int getDeep() {
return deep;
}

public void setDeep(int deep) {
this.deep = deep;
}

public int getCostToGoal() {
return costToGoal;
}

public void setCostToGoal(int costToGoal) {
this.costToGoal = costToGoal;
}
/*
** Third method.
**
**
**
**