Skip to content

Commit

Permalink
fix #3
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaymanTwinkle authored and chenqitian committed Jul 28, 2021
1 parent 3e787c3 commit 1f1b115
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ A星算法的代价计算使用了被称作是启发式的代价函数。

G的计算方式:计算方式有挺多种的,这里我们就用这种吧,假设每个结点代表一个正方形,横竖移动距离:斜移动距离=1:1.4(根号2),我们取个整数10和14吧,也就是说当前结点G值=父节点的G+(10或14)。

H的计算方式:估价计算也有很多种方式,我们这里使用“曼哈顿”法,H=|当前结点x值-最终结点x值|+|当前结点y值-最终结点y值|("||"表示绝对值)。
H的计算方式:估价计算也有很多种方式,我们这里使用“曼哈顿”法,H=(|当前结点x值-最终结点x值|+|当前结点y值-最终结点y值|) * 横竖移动代价值("||"表示绝对值)。

如下图(图不是自己做的,从网上借来的,自己画的话~...惨不忍睹!)

Expand Down Expand Up @@ -227,7 +227,7 @@ public class MapInfo
```java
private int calcH(Coord end,Coord coord)
{
return Math.abs(end.x - coord.x) + Math.abs(end.y - coord.y);
return (Math.abs(end.x - coord.x) + Math.abs(end.y - coord.y)) * DIRECT_VALUE;
}
```

Expand Down
3 changes: 1 addition & 2 deletions src/com/kesar/a/AStar.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ private Node findNodeInOpen(Coord coord)
*/
private int calcH(Coord end,Coord coord)
{
return Math.abs(end.x - coord.x)
+ Math.abs(end.y - coord.y);
return (Math.abs(end.x - coord.x) + Math.abs(end.y - coord.y)) * DIRECT_VALUE;
}

/**
Expand Down

0 comments on commit 1f1b115

Please sign in to comment.