Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么在我的生活游戏(使用处理)中的几代人都是无序的? import processing.core.PApplet; 导入静态java.lang.System.out; 公共类GoL2扩展PApplet{ int rectSideLength=25;//rectSideLength=表示单元格的矩形每边的长度 整数代=0; int windowWidth=1920; 内窗高度=950; int[][]currentGeneration=new int[windowWidth][windowHeight];//currentGeneration=2D数组到当前生成的金色单元格值 int[][]nextGeneration=new int[windowWidth][windowHeight];//nextGeneration=2D数组,用于保存下一代的单元格值 尼堡国际酒店; 国际临时国民基金会; 整数计数器; 公共静态void main(字符串[]args){ 主PApplet(“GoL2”); } 公共无效设置(){ 尺寸(窗宽、窗高); } int numRectWidth=width/rectSideLength;//numRectWidth=适合窗口x轴的宽矩形数 int numRectHeight=高度/rectSideLength;//numRectHeight=适合窗口y轴的矩形数 //前面的语句之所以出现在这里,是因为它们需要帧的大小 //为了准确地设置变量而进行设置,以免它们最终等于100 /*public void setup(){ *背景(255); *帧率(1); *对于(int y=0;y_Java_Multidimensional Array_Processing_Conways Game Of Life - Fatal编程技术网

为什么在我的生活游戏(使用处理)中的几代人都是无序的? import processing.core.PApplet; 导入静态java.lang.System.out; 公共类GoL2扩展PApplet{ int rectSideLength=25;//rectSideLength=表示单元格的矩形每边的长度 整数代=0; int windowWidth=1920; 内窗高度=950; int[][]currentGeneration=new int[windowWidth][windowHeight];//currentGeneration=2D数组到当前生成的金色单元格值 int[][]nextGeneration=new int[windowWidth][windowHeight];//nextGeneration=2D数组,用于保存下一代的单元格值 尼堡国际酒店; 国际临时国民基金会; 整数计数器; 公共静态void main(字符串[]args){ 主PApplet(“GoL2”); } 公共无效设置(){ 尺寸(窗宽、窗高); } int numRectWidth=width/rectSideLength;//numRectWidth=适合窗口x轴的宽矩形数 int numRectHeight=高度/rectSideLength;//numRectHeight=适合窗口y轴的矩形数 //前面的语句之所以出现在这里,是因为它们需要帧的大小 //为了准确地设置变量而进行设置,以免它们最终等于100 /*public void setup(){ *背景(255); *帧率(1); *对于(int y=0;y

为什么在我的生活游戏(使用处理)中的几代人都是无序的? import processing.core.PApplet; 导入静态java.lang.System.out; 公共类GoL2扩展PApplet{ int rectSideLength=25;//rectSideLength=表示单元格的矩形每边的长度 整数代=0; int windowWidth=1920; 内窗高度=950; int[][]currentGeneration=new int[windowWidth][windowHeight];//currentGeneration=2D数组到当前生成的金色单元格值 int[][]nextGeneration=new int[windowWidth][windowHeight];//nextGeneration=2D数组,用于保存下一代的单元格值 尼堡国际酒店; 国际临时国民基金会; 整数计数器; 公共静态void main(字符串[]args){ 主PApplet(“GoL2”); } 公共无效设置(){ 尺寸(窗宽、窗高); } int numRectWidth=width/rectSideLength;//numRectWidth=适合窗口x轴的宽矩形数 int numRectHeight=高度/rectSideLength;//numRectHeight=适合窗口y轴的矩形数 //前面的语句之所以出现在这里,是因为它们需要帧的大小 //为了准确地设置变量而进行设置,以免它们最终等于100 /*public void setup(){ *背景(255); *帧率(1); *对于(int y=0;y,java,multidimensional-array,processing,conways-game-of-life,Java,Multidimensional Array,Processing,Conways Game Of Life,我是一个试图编写生活游戏的初学者,我不确定如何找到问题的根源。我将游戏设置为只从一个简单的滑翔机开始,相信我已经发现了问题的影响 我在牢房里放了标记 import processing.core.PApplet; import static java.lang.System.out; public class GoL2 extends PApplet { int rectSideLength = 25; // rectSideLength = length of each side of t

我是一个试图编写生活游戏的初学者,我不确定如何找到问题的根源。我将游戏设置为只从一个简单的滑翔机开始,相信我已经发现了问题的影响

我在牢房里放了标记
import processing.core.PApplet;
import static java.lang.System.out;

public class GoL2 extends PApplet {

int rectSideLength = 25; // rectSideLength = length of each side of the rectangles drawn that represent cells
int generation = 0;
int windowWidth = 1920;
int windowHeight = 950;

int[][] currentGeneration = new int[windowWidth][windowHeight]; // currentGeneration = 2D array to gold cell values of current generation
int[][] nextGeneration = new int[windowWidth][windowHeight]; // nextGeneration = 2D array to hold cell values of next generation

int sumOfNeighbors;
int temporarySumOfNeighbors;
int counter;

public static void main(String[] args) {
    PApplet.main("GoL2");

}

public void settings() {
    size(windowWidth, windowHeight);

}

int numRectWidth = width / rectSideLength; // numRectWidth = the number of rectangles wide that will fit in the x axis of window
int numRectHeight = height / rectSideLength; // numRectHeight = the number of rectangles that will fit in the y axis of window
                                                // The previous statements are here because they need the size of the frame to
                                                // be set in order to accurately set the variables, lest they end up equal to 100

/* public void setup() { 
 *  background(255); 
 *  frameRate(1); 
 *  for (int y = 0; y < windowHeight; y++) { // For each row, 
 *      for (int x = 0; x < windowWidth; x++) { // For each element in the current row, 
 *          currentGeneration[x][y] = (int) random(0, 2); // Set element (cell) equal to either 0 or 1 (on or off) 
 *      } 
 *  } 
 * } */

public void setup() {
    background(255);
    frameRate(1);
    for (int y = 0; y < windowHeight; y++) { // For each row,
        for (int x = 0; x < windowWidth; x++) { // For each element in the current row,
            currentGeneration[x][y] = 0; // Set element (cell) equal to either 0 or 1 (on or off)
        }
    }
    currentGeneration[25][25] = 1;
    currentGeneration[25][26] = 1;
    currentGeneration[25][27] = 1;
    currentGeneration[26][27] = 1;
    currentGeneration[27][26] = 1;

}

public void draw() {
    numRectWidth = width / rectSideLength;
    numRectHeight = height / rectSideLength;

    displayCurrentGeneration();
    try {
        Thread.sleep(2);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    fill(255, 20, 147);
    textSize(30);
    text(generation, 20, 30);

    textSize(10);
    text("25,25", 625, 645);
    text("24,27", 600, 695);
    text(generation, 580, 695);
    generation++;
    generateNextGeneration();

}

public void displayCurrentGeneration() {
    background(255);
    for (int y = 0; y < 950; y++) { // For each row,
        for (int x = 0; x < 1920; x++) { // For each element in the current row,
            if (currentGeneration[x][y] == 0) { // If element equals zero, make rectangle white
                fill(255);
                stroke(0);
            } else if (currentGeneration[x][y] == 1) { // If element equals one, make rectangle black
                fill(0);
                stroke(255);
            } else {
                out.println("Inappropriate value for currentGeneration[" + x + "][" + y + "]. Value: "
                        + currentGeneration[x][y] + ", generation: " + generation);
            }
            rect(x * rectSideLength, y * rectSideLength, rectSideLength, rectSideLength); // Display rectangle (cell)
        }
    }

    // out.println("Generation " + generation);

}

public void generateNextGeneration() {
    out.println("Generating gen " + generation);
    for (int y = 1; y < numRectHeight - 1; y++) { // For each row,
        for (int x = 1; x < numRectWidth - 1; x++) { // For each element in the current row,
            sumOfNeighbors = 0;
            sumOfNeighbors = getSumOfNeighbors(x, y);
            if (sumOfNeighbors != 2 && sumOfNeighbors != 3) { // Death
                nextGeneration[x][y] = 0;
            } else if (sumOfNeighbors == 3 && currentGeneration[x][y] == 0) { // Birth
                nextGeneration[x][y] = 1;
            } else if ((sumOfNeighbors == 2 || sumOfNeighbors == 3) && currentGeneration[x][y] == 1) { // Stasis
                nextGeneration[x][y] = 1;
            }
        }
    }
    currentGeneration = nextGeneration.clone();
}

public int getSumOfNeighbors(int xAxis, int yAxis) {
    temporarySumOfNeighbors = 0;

    for (int i = -1; i < 2; i++) {
        for (int j = -1; j < 2; j++) {
            if (xAxis == 24 && yAxis == 27 && j != 0 && i != 0) {
                out.println("X" + j + ", Y" + i + ":: " + currentGeneration[xAxis + j][yAxis + i]);
            } else if (xAxis == 24 && yAxis == 27 && j == 0 && i != 0) {
                out.println("X" + ", Y" + i + ":: " + currentGeneration[xAxis + j][yAxis + i]);
            } else if (xAxis == 24 && yAxis == 27 && j != 0 && i == 0) {
                out.println("X" + j + ", Y" + ":: " + currentGeneration[xAxis + j][yAxis + i]);
            } else if (xAxis == 24 && yAxis == 27 && j == 0 && i == 0) {
                out.println("X" + ", Y" + ":: " + currentGeneration[xAxis + j][yAxis + i]);
            }
            temporarySumOfNeighbors += currentGeneration[xAxis + j][yAxis + i];
        }
    }
    temporarySumOfNeighbors -= currentGeneration[xAxis][yAxis];
    if (temporarySumOfNeighbors > 8) {
        out.println("temporarySumOfNeighbors > 8: " + temporarySumOfNeighbors);
    }
    if (xAxis == 24 && yAxis == 27) {
        out.println("Generation: " + generation + "- " + xAxis + ", " + yAxis + ": " + temporarySumOfNeighbors);
    }

    return temporarySumOfNeighbors;

 }

}
currentGeneration = nextGeneration.clone();
public class Test {
    public static void main(String... args){

        //create an array
        int[][] array = {{1, 2, 3}, {4, 5, 6}};

        //clone the array
        int[][] arrayTwo = array.clone();

        //change the original array
        array[0][0] = 99;

        //second array has also changed!
        System.out.println(arrayTwo[0][0]);
    }
}