@Override
    public List<Point> startPathfinder(boolean diagonalAllowed) {
        begin.setWaveNum(0);
        setWaveNums();
//        System.out.println("----------------");
//        for (int i = 0; i < cells.length; i++) {
//            for (int j = 0; j < cells.length; j++) {
//                if (begin.getX() == j && begin.getY() == i) {
//                    System.out.print("<" + cells[j][i].getWavenum() + ">");
//                    continue;
//                }
//                if (end.getX() == j && end.getY() == i) {
//                    System.out.print(">" + cells[j][i].getWavenum() + "<");
//                    continue;
//                }
//                if (cells[j][i] != null) {
//                    System.out.print(cells[j][i].getWavenum() + " ");
//                }
//                else
//                {
//                    System.out.print(-1);
//                }
//            }
//            System.out.println("");
//        }
        //End of marking

        //bactracking
        ArrayList<Point> arr = new ArrayList<>();
        int dx[] = {1, 0, -1, 0};
        int dy[] = {0, 1, 0, -1};
        int d = end.getWavenum();
        Cell curCell = end;
        while (d > 0) {
            for (int i = 0; i < 4; ++i) {
                if (curCell.getX() + dx[i] < cells.length
                        && curCell.getY() + dy[i] < cells.length
                        && curCell.getX() + dx[i] >= 0
                        && curCell.getY() + dy[i] >= 0
                        && cells[curCell.getX() + dx[i]][curCell.getY() + dy[i]] != null
                        && d - 1 == cells[curCell.getX() + dx[i]][curCell.getY() + dy[i]].getWavenum()) {
                    arr.add(new Point(cells[curCell.getX() + dx[i]][curCell.getY() + dy[i]].getX(), cells[curCell.getX() + dx[i]][curCell.getY() + dy[i]].getY()));
                    curCell = cells[curCell.getX() + dx[i]][curCell.getY() + dy[i]];
                    break;
                }
            }
            d--;
        }
        Collections.reverse(arr);
        return arr;
    }