/ Published in: Java
Expand |
Embed | Plain Text
public class SpielDesLebens { int msize = field(); int[][]setrix; int[][] matrix = new int [msize][msize]; for(int i = 0; i < msize; i++ ){ for(int j = 0; j < msize; j++ ){ } } setrix = compare(matrix); output(matrix); output(setrix); } public static int[][] compare(int[][] matrix){ int z; int[][] setrix = new int [matrix.length][matrix.length]; for(int y = 0; y < matrix.length; y++){ for(int x = 0; x < matrix.length; x++){ z = 0; for(int shifty = -1; shifty <= 1; shifty++){ for(int shiftx = -1; shiftx <= 1; shiftx++){ int nachbarx = x+shiftx; int nachbary = y+shifty; if (nachbarx < 0) nachbarx = (nachbarx + matrix.length); if (nachbary < 0) nachbary = (nachbary + matrix.length); if (nachbarx >= matrix.length) nachbarx = (nachbarx - matrix.length); if (nachbary >= matrix.length) nachbary = (nachbary - matrix.length); if (nachbarx == x && nachbary == y) continue; if (matrix[nachbary][nachbarx] > 0) z++; } } setrix [y][x] = 0; if (matrix [y][x] == 1 && (z == 2 || z == 3)) setrix [y][x] = 1; if (matrix [y][x] == 0 && z == 3) setrix [y][x] = 1; } } return setrix; } public static void output(int[][] matrix){ for(int i = 0; i < matrix.length; i++){ for(int j = 0; j < matrix.length; j++){ } } } public static int field(){ int z; z = In.readInt(); return z; } }
You need to login to post a comment.
