// // abstract Discrete Time CA // import java.util.*; import java.io.*; import java.awt.*; public abstract class CA { int[][] A; int[][] B; double[] pBirth; // m birth probabilities double[] pDeath; // m death probabilities double[] birthRate; // birth rate double[] deathRate; // death rate int n; // n X n grid, as a torus int m; // m species int totalPopulation; // sum of all populations of species double pointSize; boolean trace; int[] population; // m population sizes RandomSet freeSpace; // initially all points on the grid Random gen; boolean draw; // true <-> plot double time; int maxTime; static int empty = -1; static Color background = Color.LIGHT_GRAY; static Color[] color = {Color.BLUE,Color.RED,Color.YELLOW,Color.GREEN,Color.CYAN,Color.MAGENTA}; static int[] deltaY = {-1,-1,-1, 0, 0, 1, 1, 1}; // describes neighbourhood static int[] deltaX = {-1, 0, 1,-1, 1,-1, 0, 1}; // describes neighbourhood public CA(int n,int m,boolean draw){ this.n = n; this.m = m; totalPopulation = 0; pointSize = 0.4; gen = new Random(); A = new int[n][n]; B = new int[n][n]; pBirth = new double[m]; pDeath = new double[m]; birthRate = new double[m]; deathRate = new double[m]; population = new int[m]; freeSpace = new RandomSet(n*n); gen = new Random(); this.draw = draw; time = 0.0; maxTime = 0; for (int i=0;i