Exemple #1
0
int placeNewPerturbor(LifeList *seed, LifeList *perturbs,
                       Cell *placed, int nplaced, int newperturb,
                       int initialGen, int finalGen, Cell *aligns) {
  int i, j;
  int  nconv, nold, naligns, nelim;

  copyLifeList(perturbs+newperturb, &thisperturb);

  copyLifeList(&thisperturb, &spread1);
  spread(&spread1, 1);

  copyLifeList(&spread1, &spread2);
  spread(&spread2, 1);

  removeLifeList(&spread2, &spread1, 0);

  copyLifeList(seed, &cells);

  setupPerturbors(perturbs, placed, nplaced, &perturbcells, &cells);

  naligns=0;
  for (i=0; i<finalGen; i++) {

    nconv=convolve(spread2.cellList, spread2.ncells,
                   cells.cellList, cells.ncells,
                   &convolution, &scratch1, &scratch2,
                   makeWorkSpace);

    makeWorkSpace(spread1.ncells*cells.ncells);
    nold=convolve(spread1.cellList, spread1.ncells,
                  cells.cellList, cells.ncells,
                  &oldAlignments, &scratch1, &scratch2,
                  makeWorkSpace);

    nconv=subtractLists(oldAlignments, nold, convolution, nconv);

    nconv=subtractLists(aligns, naligns, convolution, nconv);

    setValues(convolution, nconv, i);

    nelim=0;
    for (j=0; j<nconv; j++) {
      copyLifeList(&cells, &tmp);
      intersectLifeLists(&tmp, &spread2, convolution[j].position);

      if (interact(&tmp, &thisperturb, convolution[j].position)) {
        convolution[nelim++]=convolution[j];
      }
    }

    makeWorkSpace(nelim + naligns);
    naligns=combineLists(convolution, nelim, aligns, naligns, scratch1);
    copyList(scratch1, naligns, aligns, 0);
    
    if (i == 0) {
        setValues(oldAlignments, nold, -1);
        makeWorkSpace(nold + naligns);
        naligns=combineLists(oldAlignments, nold, aligns, naligns, scratch1);
        copyList(scratch1, naligns, aligns, 0);
    }

    generate(&cells);

    if (broken(cells.cellList, cells.ncells,
               perturbcells.cellList, perturbcells.ncells))
      break;
  }

  naligns=removeLessThan(aligns, naligns, initialGen);
  return naligns;
}
Exemple #2
0
main(int argc, char *argv[]) {

    static LifeList cells;
    static LifeList matchcells;
    static LifeList outcells;
    int i,j,n=0;
    int gens=500;
    int x,y;
    int match;
    int pos;
    int count[240];
    int least= 0;
    int fail;
    int damaged;
    int restored;
    int prodcells;
    int restorefilter=10;
    char outpat[100000];


    History hist;
    int period, repetitions;
    Cell lifetrail[5000];
    static char nextpat[10000];
    int ncls;

    initLifeList(&cells);
    initLifeList(&matchcells);
    initLifeList(&outcells);

    if (argc>2) {
        sscanf(argv[2], "%d", &restorefilter);
    }

    while(gets(nextpat)) {

        for (i=0; i<240; i++) {
            count[i] = i;
        }

        getpat(nextpat, &cells);
        copyLifeList(&cells, &matchcells);

        if (argc>1) {
            for (i=0; argv[1][i]; i++) {
                matchcells.ncells =
                    removeIfEquals(matchcells.cellList, matchcells.ncells, argv[1][i]);
            }
        }

        fail=0;
        damaged=0;
        restored=0;
        for (i=0; i<gens; i++) {
            generate(&cells);

            //      printf("%d %d %d %d\n", i, fail, damaged, restored);

            count[i%240] = cells.ncells;

            if (cells.ncells == 0) break;

            match = 1;
            for (j=0; j<180; j++) {
                if (count[j] != count[j+60]) {
                    match = 0;
                    break;
                }
            }

            if (match) break;

            if ( matchLifeList(&cells, &matchcells, 0) < matchcells.ncells) {
                fail++;
                restored=0;
            } else {
                prodcells = cells.ncells - matchcells.ncells;
                copyLifeList(&cells, &outcells);

                restored++;
                if (restored>restorefilter) {
                    if (fail>damaged) damaged=fail;
                    fail = 0;
                }
            }

            if (fail>150) break;

        }

        if (damaged) {
            fflush(stdout);
            removeLifeList(&outcells, &matchcells, 0);
            makeString(outcells.cellList, outcells.ncells, outpat);

            printf("%s %d %d %d %d %s\n", nextpat, damaged, fail, i-fail, prodcells, outpat);
        }

    }
}
Exemple #3
0
main(int argc, char *argv[]) {

  static LifeList cells;
  static LifeList matchcells;
  static LifeList boundarycells;
  static LifeList intercells;
  static LifeList outcells;
  int i,j,n=0;
  int gens=500;
  int x,y;
  int match;
  int pos;
  int count[240];
  int least= 0;
  int fail;
  int damaged;
  int restored;
  int firstgen;
  int maxgen;
  int survivegen;
  int restorefilter=10;
  int maxrecoverytime=20;
  char interpat[100000];
  char outpat[100000];


  History hist;
  int period, repetitions;
  Cell lifetrail[50000];
  static char nextpat[100000];
  int ncls;

  initLifeList(&cells);
  initLifeList(&matchcells);
  initLifeList(&boundarycells);
  initLifeList(&intercells);
  initLifeList(&outcells);

  if (argc>2) {
      sscanf(argv[2], "%d", &restorefilter);
  }

  while(gets(nextpat)) {

    for (i=0; i<240; i++) { count[i] = i; }

    getpat(nextpat, &cells);
    copyLifeList(&cells, &matchcells);

    if (argc>1) {
      for (i=0; argv[1][i]; i++) {
        matchcells.ncells =
          removeIfEquals(matchcells.cellList, matchcells.ncells, argv[1][i]);
      }
    }

    copyLifeList(&matchcells, &boundarycells);
    spread(&boundarycells, 1);

    fail=0;
    damaged=0;
    restored=0;
    firstgen=0;
    maxgen=0;
    survivegen=0;
    for (i=0; i<gens; i++) {

      //      printf("%d %d %d %d\n", i, fail, damaged, restored);

      count[i%240] = cells.ncells;

      if (cells.ncells == 0) break;

      match = 1;
      for (j=0; j<180; j++) {
        if (count[j] != count[j+60]) {
          match = 0;
          break;
        }
      }

      if (match) break;

      if ( matchLifeList(&cells, &matchcells, 0) < matchcells.ncells
           || matchLifeList(&cells, &boundarycells, 0) != matchcells.ncells) {
        fail++;
        restored=0;
        if (firstgen == 0) {
          firstgen = i;
          maxgen = i + restorefilter + maxrecoverytime;
        }
      } else {
        restored++;
        survivegen = i;
        if (restored>restorefilter) {
          if (restored == restorefilter + 1) {
              copyLifeList(&cells, &intercells);
              copyLifeList(&cells, &outcells);
          }
          if (i <= maxgen) {
              copyLifeList(&cells, &outcells);
          }

          if (fail>damaged) damaged=fail;
          fail = 0;
          firstgen = 0;
        }
      }

      if (fail>150) break;

      generate(&cells);
    }

    if (damaged) {
      fflush(stdout);
      removeLifeList(&outcells, &matchcells, 0);
      makeString(outcells.cellList, outcells.ncells, outpat);
      removeLifeList(&intercells, &matchcells, 0);
      makeString(intercells.cellList, intercells.ncells, interpat);

      printf("%s %d %s %s\n", nextpat, survivegen, interpat, outpat);
    }

  }
}