1
- package com .ai .astar ;
1
+ package com .ai .astar . domain ;
2
2
3
- import com .ai .astar .domain .Node ;
4
3
import com .ai .astar .domain .searchstrategy .DiagonalMapChecker ;
5
4
import com .ai .astar .domain .searchstrategy .HorizontalVerticalChecker ;
6
5
import com .ai .astar .domain .searchstrategy .MapChecker ;
@@ -19,7 +18,15 @@ public class AStar {
19
18
private final MapChecker diagonalsChecker ;
20
19
private final MapChecker hvChecker ;
21
20
22
- public AStar (int rows , int cols , Node initialNode , Node finalNode , int [][] blocksArray , boolean searchDiagonals ) {
21
+ public AStar (
22
+ int rows ,
23
+ int cols ,
24
+ Node initialNode ,
25
+ Node finalNode ,
26
+ int [][] blocksArray ,
27
+ boolean searchDiagonals ,
28
+ int diagonalCost ,
29
+ int hvCost ) {
23
30
this .initialNode = initialNode ;
24
31
this .finalNode = finalNode ;
25
32
this .searchArea = new Node [rows ][cols ];
@@ -28,27 +35,31 @@ public AStar(int rows, int cols, Node initialNode, Node finalNode, int[][] block
28
35
initBlocks (blocksArray );
29
36
this .closedSet = new HashSet <>();
30
37
if (searchDiagonals ) {
31
- this .diagonalsChecker = new DiagonalMapChecker (searchArea , openList , closedSet , DEFAULT_DIAGONAL_COST );
38
+ this .diagonalsChecker = new DiagonalMapChecker (searchArea , openList , closedSet , diagonalCost );
32
39
} else {
33
40
this .diagonalsChecker = new NoOpChecker (null , null , null );
34
41
}
35
- this .hvChecker = new HorizontalVerticalChecker (searchArea , openList , closedSet , DEFAULT_HV_COST );
42
+ this .hvChecker = new HorizontalVerticalChecker (searchArea , openList , closedSet , hvCost );
43
+ }
44
+
45
+ public AStar (int rows , int cols , Node initialNode , Node finalNode , int [][] blocksArray , boolean searchDiagonals ) {
46
+ this (rows , cols , initialNode , finalNode , blocksArray , searchDiagonals , DEFAULT_DIAGONAL_COST , DEFAULT_HV_COST );
36
47
}
37
48
38
49
private void initNodes () {
39
50
for (int i = 0 ; i < searchArea .length ; i ++) {
40
51
for (int j = 0 ; j < searchArea [0 ].length ; j ++) {
41
- Node node = new Node (i , j );
52
+ Node node = Node . of (i , j );
42
53
node .calculateHeuristic (finalNode );
43
54
this .searchArea [i ][j ] = node ;
44
55
}
45
56
}
46
57
}
47
58
48
59
private void initBlocks (int [][] blocksArray ) {
49
- for (int [] ints : blocksArray ) {
50
- int row = ints [0 ];
51
- int col = ints [1 ];
60
+ for (int [] block : blocksArray ) {
61
+ int row = block [0 ];
62
+ int col = block [1 ];
52
63
if (row < 0 || row >= searchArea .length ) {
53
64
continue ;
54
65
}
0 commit comments