简体   繁体   中英

How create an adjacency matrix of a Maze graph

I'm working on making a maze Generator using Prim's Algorithm. I understand i have to make an undirected weighted graph and represent it on an Adjacency Matrix or List. i created the boolean[][] adjacenyMatrix array to show which edges currently exist in the maze. But i have an issue trying to implement the algorithm i thought of. Here is my code:

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
    Scanner scanner = new Scanner (System.in);
    System.out.println("Please enter the size of the maze");
    int mazeHeight = scanner.nextInt();
    int mazeWidth = scanner.nextInt();
    int noOfNodes = mazeHeight * mazeWidth;

    boolean[][] adjacencyMatrix = new boolean[noOfNodes][noOfNodes];


    for (int i = 0; i < mazeHeight; i++) {
        for (int j = 0; j < mazeWidth; j++ ) {
            // Edges exist from left to right
            adjacencyMatrix[i][j] = true;
            adjacencyMatrix[j][i] = true;
        }
    }

    for (int i = 0; i < mazeWidth; i++) {
        for (int j = 0; j < noOfNodes; j + mazeWidth) {  // <-----------I'm having an issue here; Not a statement
            // Edges exist from top to bottom
            adjacencyMatrix[i][j] = true;
            adjacencyMatrix[j][i] = true;
        }
    }
}

}

After taking a break; i looked over it and realised that i forgot to include the "=" symbol >.<

so j += mazeWidth

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM