[英]Maze with path finding algorithm
I am working on learning how to us a A* algorithm to find paths and I want to see the best way of doing this. 我正在努力学习如何使用A *算法来查找路径,并且我想了解执行此操作的最佳方法。 This is what I was thinking I want to have a start point and end point then build the maze via a build function then populate it with obstetrical then runt the A* algorithm the print off the route in a table like format basically changing the 0 to a 3 to show the path that is taken (obstetrical will equal a 1). 这就是我想得到的起点和终点,然后通过构建函数构建迷宫,然后在产科中填充迷宫,然后运行A *算法,然后以格式将表格中的路线打印出来,基本上将0更改为3表示所采用的路径(产科等于1)。 Does this sound like a good plan? 这听起来不错吗?
What I am having trouble with is that I don't know the best way to put in the obstetrical in the array. 我遇到的麻烦是,我不知道将产科产品放入阵列的最佳方法。 This is what I have so far: 这是我到目前为止的内容:
public class Maze {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//start and end points in the array
int startx = 115;
int starty = 655;
int endx = 380;
int endy = 560;
//number of collums and rows
int row = 700;
int col = 500;
//size of maze
int maze [][] = new int [row][col];
makeMaze(row, col, maze);
printMaze(row, col, maze);
}
//fill mazz with 0
private static void makeMaze(int row, int col, int maze[][])
{
//fill maze with 0 for initilization
for(int i = 0; i < row; i++)
{
for(int j = 0; j < col; j++)
{
maze[i][j] = 0;
}
}
}
//print out array/maze
private static void printMaze(int row, int col, int maze[][])
{
//... Print array in rectangular form
for(int i = 0; i < row; i++)
{
for(int j = 0; j < col; j++)
{
System.out.print(" " + maze[i][j] );
}
System.out.println("");
}
}
//fill the array with obsticals
private void makeObsticals()
{
//obstical 1
//this represent the corners of the object
int ob1Point1 [][] = new int [220][616];
int ob1Point2 [][] = new int [220][666];
int ob1Point3 [][] = new int [251][670];
int ob1Point4 [][] = new int [272][647];
//object 2
int ob2Point1 [][] = new int [341][655];
int ob2Point2 [][] = new int [359][667];
int ob2Point3 [][] = new int [374][651];
int ob2Point4 [][] = new int [366][577];
//obejct 3
int ob3Point1 [][] = new int [311][530];
int ob3Point2 [][] = new int [311][559];
int ob3Point3 [][] = new int [339][578];
int ob3Point4 [][] = new int [361][560];
int ob3Point5 [][] = new int [361][528];
int ob3Point6 [][] = new int [113][516];
//object 4
int ob4Point1 [][] = new int [105][628];
int ob4Point2 [][] = new int [151][670];
int ob4Point3 [][] = new int [180][629];
int ob4Point4 [][] = new int [156][577];
int ob4Point5 [][] = new int [113][587];
//object 5
int ob5Point1 [][] = new int [118][517];
int ob5Point2 [][] = new int [245][517];
int ob5Point3 [][] = new int [245][577];
int ob5Point4 [][] = new int [118][577];
//object 6
int ob6Point1 [][] = new int [280][583];
int ob6Point2 [][] = new int [333][583];
int ob6Point3 [][] = new int [333][665];
int ob6Point4 [][] = new int [280][665];
//object 7
int ob7Point1 [][] = new int [252][594];
int ob7Point2 [][] = new int [290][562];
int ob7Point3 [][] = new int [264][538];
//object 8
int ob8Point1 [][] = new int [198][635];
int ob8Point2 [][] = new int [217][574];
int ob8Point3 [][] = new int [182][574];
}
//astar algorithum
private void findPath()
{
}
} }
thanks for any help with this 感谢您对此的任何帮助
Sorry but I don't understand why you have declared so many two dimensional array for obstacles... as you said. 抱歉,但我不明白为什么您要声明这么多的二维数组作为障碍物...正如您所说。 . 。 . 。
//obstacle1
//this represent the corners of the object
int ob1Point1 [][] = new int [220][616];
int ob1Point2 [][] = new int [220][666];
int ob1Point3 [][] = new int [251][670];
int ob1Point4 [][] = new int [272][647];
I think from above code you want to mean (220,616),(220,666),(251,670),(272,647) are corner points of 1 obstacle. 我认为从上面的代码中您想表示(220,616),(220,666),(251,670),(272,647)是1个障碍的拐角点。
If so then I will suggest not to take 4 two dimensional array but instead mark area covered by obstacle in maze[][] array by infinity ie the highest integer no. 如果是这样,那么我建议不要采用4个二维数组,而是用无穷大标记迷宫[] []数组中障碍物覆盖的区域,即最高整数no。 (let consider it as a 10000) (让我们将其视为10000)
and for other (x,y) position,in maze[x][y] put heuristic value of each position (which means cost to reach destination(endx,endy) from that (x,y)position) 对于其他(x,y)位置,在迷宫[x] [y]中放置每个位置的启发式值(这意味着从该(x,y)位置到达目的地(endx,endy)的成本)
and then apply A* algorithm to reach from start to end. 然后应用A *算法从头到尾进行搜索。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.