나는 A * 알고리즘을 연구 중이다. 이것은 길 찾기 메소드의 코드입니다. 참고로,이 보드는 내가 작업하고있는 보드입니다. http://i.imgur.com/xaAzNSw.png?1 각 색상 타일은 다른 휴리스틱 값을 나타냅니다. 알려지지 않은 일부 이유 때문에 매번 경로를 찾지 만 항상 정확한 경로는 아닙니다. 다음은 길 찾기 메소드의 코드입니다. 누구든지 명확한 설명이 필요한 경우이를 제공하게되어 기쁩니다.* 길 찾기 알고리즘 - 경로를 찾지 만 최적의 최적 경로가 아님
public List<Point> findPath(Point start, Point end) {
//declarations and instantiations
List<PathState> closedList = new ArrayList<PathState>(); //the nodes already considered
List<PathState> openList = new ArrayList<PathState>(); //nodes to be considered
openList.add(new PathState(start, end, tm)); //add starting point
PathState current = openList.get(0);
while(!current.isGoal()){
//sort open list to find the pathstate with the best hscore(sorts by hscore)
Collections.sort(openList);
current = openList.get(openList.size() - 1);
closedList.add(current);
openList.remove(current);
//get the valid children of current node
List<PathState> children = current.getChildren();;
if(!current.isGoal()){
for(int i = 0; i < children.size(); i++){
if(!closedList.contains(children.get(i))){
if(openList.contains(children.get(i))){
if(openList.get(openList.indexOf(children.get(i))).getgScore() > children.get(i).getgScore()){
//child is already on the open list, but this node has lower g value
//change g value and parent of node on open list
openList.get(openList.indexOf(children.get(i))).setG(children.get(i).getgScore());
openList.get(openList.indexOf(children.get(i))).changeParent(current);
}
}else{
//child not in closed list
openList.add(children.get(i));
//repaint the terrain panel with shades
tp.addAstarState(children.get(i));
tp.repaint();
try {
Thread.sleep(25);
} catch(Exception e) {
e.printStackTrace();
}
}
}
}
}
}
//returns the path from winning node to start for output
return current.getPath();
}
당신이 단계에서 촬영 경로를 시각화 시도했다 및 인쇄 콘솔에 정의 논리를 찍은 단계? 또한 확인하기 위해 연산자를''openList.get (openList.indexOf (children.get (i)). getgScore()> children.get (i) ''보다 큰 값에서 작은 값으로 변경하면 어떻게 될까요? getgScore())'? –
목적지까지의 거리를 추정하는 기능은 무엇입니까? 아마도 getScore() 함수에있을 것입니다. – mohsaied