@Test public void testSimpleDCT() { DensityClassificationTask dct = new DensityClassificationTask(1, 1); CARule rule = new CARule(new int[] { 0, 0, 0, 1, 0, 1, 1, 1 }); CAConfiguration test = new CAConfiguration(new int[] { 1, 1, 0, 1 }); GameOutcome play = dct.play(rule, test, null); Assert.assertEquals(1, (int) play.playerPoints()); }
@Override public GameOutcome play(CARule rule, CAConfiguration test, RandomDataGenerator random) { int[] ca = test.toArray(); int[] newca = new int[ca.length]; final int target = test.getTarget(); final int size = ca.length; if (target == 0 && rule.getFirst() != 0) { return new GameOutcome(0, 1); } if (target == 1 && rule.getLast() != 1) { return new GameOutcome(0, 1); } for (int time = 0; time < timeSteps; time++) { int cnt = 0; int num = 0; int exp = 2 * radius; for (int j = 0; j < 2 * radius + 1; ++j) { num += (1 << exp) * ca[j]; exp -= 1; } newca[0] = rule.get(num); if (newca[0] == target) { cnt += 1; } int end = 2 * radius; for (int i = 1; i < size; ++i) { end += 1; if (end >= size) { end -= size; } num = ((num << 1) & ((1 << 2 * radius + 1) - 1)) ^ ca[end]; newca[i] = rule.get(num); if (newca[i] == target) { cnt += 1; } } if (cnt == size) { return new GameOutcome(1, 0); } ca = Arrays.copyOf(newca, newca.length); } return new GameOutcome(0, 1); }
DensityClassificationTask implements Game<CARule, CAConfiguration> { @Override public GameOutcome play(CARule rule, CAConfiguration test, RandomDataGenerator random) { int[] ca = test.toArray(); int[] newca = new int[ca.length]; final int target = test.getTarget(); final int size = ca.length; if (target == 0 && rule.getFirst() != 0) { return new GameOutcome(0, 1); } if (target == 1 && rule.getLast() != 1) { return new GameOutcome(0, 1); } for (int time = 0; time < timeSteps; time++) { int cnt = 0; int num = 0; int exp = 2 * radius; for (int j = 0; j < 2 * radius + 1; ++j) { num += (1 << exp) * ca[j]; exp -= 1; } newca[0] = rule.get(num); if (newca[0] == target) { cnt += 1; } int end = 2 * radius; for (int i = 1; i < size; ++i) { end += 1; if (end >= size) { end -= size; } num = ((num << 1) & ((1 << 2 * radius + 1) - 1)) ^ ca[end]; newca[i] = rule.get(num); if (newca[i] == target) { cnt += 1; } } if (cnt == size) { return new GameOutcome(1, 0); } ca = Arrays.copyOf(newca, newca.length); } return new GameOutcome(0, 1); } }
DensityClassificationTask implements Game<CARule, CAConfiguration> { @Override public GameOutcome play(CARule rule, CAConfiguration test, RandomDataGenerator random) { int[] ca = test.toArray(); int[] newca = new int[ca.length]; final int target = test.getTarget(); final int size = ca.length; if (target == 0 && rule.getFirst() != 0) { return new GameOutcome(0, 1); } if (target == 1 && rule.getLast() != 1) { return new GameOutcome(0, 1); } for (int time = 0; time < timeSteps; time++) { int cnt = 0; int num = 0; int exp = 2 * radius; for (int j = 0; j < 2 * radius + 1; ++j) { num += (1 << exp) * ca[j]; exp -= 1; } newca[0] = rule.get(num); if (newca[0] == target) { cnt += 1; } int end = 2 * radius; for (int i = 1; i < size; ++i) { end += 1; if (end >= size) { end -= size; } num = ((num << 1) & ((1 << 2 * radius + 1) - 1)) ^ ca[end]; newca[i] = rule.get(num); if (newca[i] == target) { cnt += 1; } } if (cnt == size) { return new GameOutcome(1, 0); } ca = Arrays.copyOf(newca, newca.length); } return new GameOutcome(0, 1); } DensityClassificationTask(int timeSteps, int radius); }
DensityClassificationTask implements Game<CARule, CAConfiguration> { @Override public GameOutcome play(CARule rule, CAConfiguration test, RandomDataGenerator random) { int[] ca = test.toArray(); int[] newca = new int[ca.length]; final int target = test.getTarget(); final int size = ca.length; if (target == 0 && rule.getFirst() != 0) { return new GameOutcome(0, 1); } if (target == 1 && rule.getLast() != 1) { return new GameOutcome(0, 1); } for (int time = 0; time < timeSteps; time++) { int cnt = 0; int num = 0; int exp = 2 * radius; for (int j = 0; j < 2 * radius + 1; ++j) { num += (1 << exp) * ca[j]; exp -= 1; } newca[0] = rule.get(num); if (newca[0] == target) { cnt += 1; } int end = 2 * radius; for (int i = 1; i < size; ++i) { end += 1; if (end >= size) { end -= size; } num = ((num << 1) & ((1 << 2 * radius + 1) - 1)) ^ ca[end]; newca[i] = rule.get(num); if (newca[i] == target) { cnt += 1; } } if (cnt == size) { return new GameOutcome(1, 0); } ca = Arrays.copyOf(newca, newca.length); } return new GameOutcome(0, 1); } DensityClassificationTask(int timeSteps, int radius); @Override GameOutcome play(CARule rule, CAConfiguration test, RandomDataGenerator random); }
DensityClassificationTask implements Game<CARule, CAConfiguration> { @Override public GameOutcome play(CARule rule, CAConfiguration test, RandomDataGenerator random) { int[] ca = test.toArray(); int[] newca = new int[ca.length]; final int target = test.getTarget(); final int size = ca.length; if (target == 0 && rule.getFirst() != 0) { return new GameOutcome(0, 1); } if (target == 1 && rule.getLast() != 1) { return new GameOutcome(0, 1); } for (int time = 0; time < timeSteps; time++) { int cnt = 0; int num = 0; int exp = 2 * radius; for (int j = 0; j < 2 * radius + 1; ++j) { num += (1 << exp) * ca[j]; exp -= 1; } newca[0] = rule.get(num); if (newca[0] == target) { cnt += 1; } int end = 2 * radius; for (int i = 1; i < size; ++i) { end += 1; if (end >= size) { end -= size; } num = ((num << 1) & ((1 << 2 * radius + 1) - 1)) ^ ca[end]; newca[i] = rule.get(num); if (newca[i] == target) { cnt += 1; } } if (cnt == size) { return new GameOutcome(1, 0); } ca = Arrays.copyOf(newca, newca.length); } return new GameOutcome(0, 1); } DensityClassificationTask(int timeSteps, int radius); @Override GameOutcome play(CARule rule, CAConfiguration test, RandomDataGenerator random);  }