src/main/java/cursor/rybak/model/maze/impl/Maze.java
/**
     * Randomized Prim's algorithm
     *
     * @param width  count of columns
     * @param height count of rows
     */
Randomized Prim's algorithm
@param width  count of columns
@param height count of rows
Randomized Prim ' s algorithm @param width count of columns @param height count of rows
private void generate(int width, int height) {
        maze = new int[width][height];
        List<int[]> walls = new ArrayList<>();
        Random random = new Random();
        int initX = random.nextInt(width - width / 2) + 2;
        int initY = height - 1;
        maze[initX - 1][initY] = PATH;
        maze[initX][initY] = PATH;
        maze[initX+1][initY] = PATH;
        maze[initX+1][initY-1] = PATH;
        maze[initX+2][initY] = PATH;
        maze[initX+3][initY] = PATH;
        walls.add(randomStartPoint(random));
        while (!walls.isEmpty()) {
            final int[] candidateToCheck = walls.remove(random.nextInt(walls.size()));
            int x = candidateToCheck[2];
            int y = candidateToCheck[3];
            if (maze[x][y] == WALL) {
                maze[candidateToCheck[0]][candidateToCheck[1]] = maze[x][y] = PATH;
                if (x >= 2 && maze[x - 2][y] == WALL)
                    walls.add(new int[]{x - 1, y, x - 2, y});
                if (y >= 2 && maze[x][y - 2] == WALL)
                    walls.add(new int[]{x, y - 1, x, y - 2});
                if (x < width - 2 && maze[x + 2][y] == WALL)
                    walls.add(new int[]{x + 1, y, x + 2, y});
                if (y < height - 2 && maze[x][y + 2] == WALL)
                    walls.add(new int[]{x, y + 1, x, y + 2});
            }
        }
        maze[initX+1][initY] = TEAM_VECTOR_UP;
        this.setTeamStartPoint(new int[]{initX+1, initY});
    }
private void generate ( int width , int height ) { maze = new int [ width ] [ height ] ; List < int [ ] > walls = new ArrayList < > ( ) ; Random random = new Random ( ) ; int initX = random . nextInt ( width - width / 2 ) + 2 ; int initY = height - 1 ; maze [ initX - 1 ] [ initY ] = PATH ; maze [ initX ] [ initY ] = PATH ; maze [ initX + 1 ] [ initY ] = PATH ; maze [ initX + 1 ] [ initY - 1 ] = PATH ; maze [ initX + 2 ] [ initY ] = PATH ; maze [ initX + 3 ] [ initY ] = PATH ; walls . add ( randomStartPoint ( random ) ) ; while ( ! walls . isEmpty ( ) ) { final int [ ] candidateToCheck = walls . remove ( random . nextInt ( walls . size ( ) ) ) ; int x = candidateToCheck [ 2 ] ; int y = candidateToCheck [ 3 ] ; if ( maze [ x ] [ y ] == WALL ) { maze [ candidateToCheck [ 0 ] ] [ candidateToCheck [ 1 ] ] = maze [ x ] [ y ] = PATH ; if ( x >= 2 && maze [ x - 2 ] [ y ] == WALL ) walls . add ( new int [ ] { x - 1 , y , x - 2 , y } ) ; if ( y >= 2 && maze [ x ] [ y - 2 ] == WALL ) walls . add ( new int [ ] { x , y - 1 , x , y - 2 } ) ; if ( x < width - 2 && maze [ x + 2 ] [ y ] == WALL ) walls . add ( new int [ ] { x + 1 , y , x + 2 , y } ) ; if ( y < height - 2 && maze [ x ] [ y + 2 ] == WALL ) walls . add ( new int [ ] { x , y + 1 , x , y + 2 } ) ; } } maze [ initX + 1 ] [ initY ] = TEAM_VECTOR_UP ; this . setTeamStartPoint ( new int [ ] { initX + 1 , initY } ) ; }
Randomized Prim's algorithm
 @param width  count of columns
 @param height count of rows
Randomized Prim ' s algorithm @param width count of columns @param height count of rows
// this whole construction is a Prim's algorithm // and shouldn't split to separate methods // define current position to start