I just can not figure out how to search in width to find the shortest path in the maze. I can not deal with these queues, etc. Can anyone please help write the algorithm? Very urgent need
Here is the implementation of my search. The method takes two parameters as input - the coordinates of the starting point. In my case it is (2, 0). I can't deal with these queues. I want to first output the array to the console and display the shortest path there, and then, based on this, move the smiley in the maze using the same indices
public void findPath(int x,int y) { ArrayList<Pair<Integer,Integer>> queue = new ArrayList<Pair<Integer,Integer>>(); queue.add(new Pair<Integer,Integer>(x,y)); mas[x][y] = 1; while (queue.size() > 0) { Pair<Integer,Integer> cur = queue.remove(queue.size() - 1); // if (x < width - 1 && mas[x + 1][y] == 0) { queue.add(new Pair<Integer,Integer>(x+1, y)); mas[x+1][y] = 1; } if (x > 0 && mas[x - 1][y] == 0) { queue.add(new Pair<Integer,Integer>(x-1,y)); mas[x-1][y] = 1; } if (y < height - 1 && mas[x][y+1] == 0) { queue.add(new Pair<Integer,Integer>(x, y + 1)); mas[x][y+1] = 1; } if (y > 0 && mas[x][y-1] == 0) { queue.add(new Pair<Integer,Integer>(x, y - 1)); mas[x][y-1] = 1; } // } }