[英]How create an adjacency matrix of a Maze graph
我正在使用 Prim 算法制作迷宮生成器。 我知道我必須制作一個無向加權圖並在鄰接矩陣或列表上表示它。 我創建了 boolean[][] adjacenyMatrix 數組來顯示迷宮中當前存在哪些邊。 但是我在嘗試實現我想到的算法時遇到了問題。 這是我的代碼:
導入 java.util.Scanner;
公共 class 主要 {
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;
}
}
}
}
休息后; 我看了看它,意識到我忘了包括“=”符號>。<
所以 j += mazeWidth
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.