我有一个名为hashiwokakero的谜题,我在这里使用二维数组生成映射,该数组中的值是随机生成的。我认为,检查难题是否可解决的最有效方法是在向用户展示D-二维数组之前使用DFS。
我需要做的是检查一个节点是否可以与另一个节点桥接,如果它可以在那个位置绘制该节点。有关Hashiwokakero here
的更多信息这是我到目前为止尝试过的方法,但是我似乎无法解决。 这是一个用于搜索邻居的for循环,但我不确定它是否正确初始化。
private void InitializeEasy() {
Random rand = new Random();
String[][] debug_board_state = new String[4][4];
setCurrentState(new State(WIDTH_EASY));
for (int row = 0; row < debug_board_state.length; row++) {
for (int column = 0; column < debug_board_state[row].length; column++) {
debug_board_state[row][column] = String.valueOf(rand.nextInt(5));
}
}
for (int row = 0; row < debug_board_state.length; row++) {
for (int column = 0; column < debug_board_state[row].length; column++) {
System.out.print(debug_board_state[row][column] + " ");
}
System.out.println();
}
for (int row = 0; row < WIDTH_EASY; ++row) {
for (int column = 0; column < WIDTH_EASY; ++column) {
for (int colNum = column - 1 ; colNum <= (column + 1) ; colNum +=1 ) {
for (int rowNum = row - 1 ; rowNum <= (row + 1) ; rowNum +=1 ) {
//if not the center cell
if(! ((colNum == column) && (rowNum == row))) {
//make sure it is within grid
if(withinGrid (colNum, rowNum)) {
System.out.println("Neighbor of "+ column+ " "+ row + " - " + colNum +" " + rowNum );
}
}
}
}
getCurrentState().board_elements[row][column] = new BoardElement();
getCurrentState().board_elements[row][column].max_connecting_bridges = Integer.parseInt(debug_board_state[row][column]);
getCurrentState().board_elements[row][column].row = row;
getCurrentState().board_elements[row][column].col = column;
if (getCurrentState().board_elements[row][column].max_connecting_bridges > 0) {
getCurrentState().board_elements[row][column].is_island = true;
}
}
}
}