import java.util.*; import java.io.*; public class CA { private int[][] A; private int[][] B; // is A after deaths private int[][] C; // is new births in A private int[][] neighbourhood; private int n; private double pointSize; private boolean trace; private Random gen; private double density; // between 0 and 1 private double pBirth, pDeath; private int population; private int iteration; public CA(int n,double density,double pBirth,double pDeath){ this.n = n; gen = new Random(); pointSize = 0.1; this.density = density; this.pBirth = pBirth; this.pDeath = pDeath; population = 0; iteration = 0; A = new int [n][n]; B = new int [n][n]; C = new int [n][n]; neighbourhood = new int[2][9]; // see getNeighbourhood() for explanation for (int i=0;in-1) xt = n - i; yt = j; if (j<0) yt = j + n; if (j>n-1) yt = n - j; if (X[xt][yt] == 0){ k++; neighbourhood[0][k] = xt; neighbourhood[1][k] = yt; } } neighbourhood[0][0] = k; } public void iterate(){ for (int i=0;i 0){ int k = gen.nextInt(neighbourhood[0][0]) + 1; int x = neighbourhood[0][k]; int y = neighbourhood[1][k]; if (C[x][y] == 0){ C[x][y] = 1; population++; if (trace) System.out.println("+[" + x +"]["+ y +"]"); } } } // Copy over A = A - B + C for (int i=0;i