使用Java编写的B*算法 (二)
tList.contains(nextp))
addToSearch(p,nextp,this.rightList);
}
nextp = nextPassPointSide(p,end,1,canPenetrate);
if(nextp == end){
nextp.parent = p;
return true;
}
if(nextp != null){
if(this.closeList.contains(nextp))
return sideNext(nextp, end, side, canPenetrate);
// return false;
else if(!this.rightList.contains(nextp))
addToSearch(p,nextp,this.leftList);
}
}
}
else if(side>0){
nextp = p.getPassPointByDir(dir);
if(nextp == end){
nextp.parent = p;
return true;
}
if(nextp != null && !this.closeList.contains(nextp)){
addToSearch(p,nextp,this.openList);
}
else
{
nextp = nextPassPointSide(p,end,1,canPenetrate);
if(nextp == end){
nextp.parent = p;
return true;
}
if(nextp != null && !this.closeList.contains(nextp) && !this.rightList.contains(nextp)){
addToSearch(p,nextp,this.leftList);
}
}
}
else if(side<0){
nextp = p.getPassPointByDir(dir);
if(nextp == end){
nextp.parent = p;
return true;
}
if(nextp != null && !this.closeList.contains(nextp)){
addToSearch(p,nextp,this.openList);
}
else
{
nextp = nextPassPointSide(p,end,-1,canPenetrate);
if(nextp == end){
nextp.parent = p;
return true;
}
if(nextp != null && !this.closeList.contains(nextp) && !this.leftList.contains(nextp)){
addToSearch(p,nextp,this.rightList);
}
}
}
return false;
}
protected void addToSearch(Point parent,Point next,HashSet
list){
next.clear();
next.parent = parent;
list.add(next);
}
/**
*
* @param p
* @param side >0 或者 <0
* @param canPenetrate
* @return
*/
protected Point nextPassPointSide(Point p,Point end,int side,boolean canPenetrate){
int dir = Point.getDirSimple(p, end);
Point nextp = null;
if(side<0){
while(side>=-7){
dir = Point.rightdir(dir);
if(p.canWalkDir(dir,canPenetrate)){
nextp = p.getPassPointByDir(dir);
if(!this.closeList.contains(nextp)){
break;
}
}
side--;
}
}
else
{
while(side<=7){
dir = Point.leftdir(dir);
if(p.canWalkDir(dir,canPenetrate)){
nextp = p.getPassPointByDir(dir);
if(!this.closeList.contains(nextp)){
break;
}
}
side++;
}
}
return nextp;
}
}