home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / xplatfrm / tierra / slicers.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-26  |  2.8 KB  |  101 lines

  1. /* slicers.c  28-10-91  Artificial Life simulator */
  2. /** Tierra Simulator V3.0: Copyright (c) 1991 Thomas S. Ray **/
  3.  
  4. #include "license.h"
  5.  
  6. #ifndef lint
  7. static char     sccsid[] = "%W%     %G%";
  8. #endif
  9.  
  10. #include "tierra.h"
  11. #include "extern.h"
  12.  
  13. void SlicerPhoton()
  14. {   Pcells  ce;
  15.     I32s  size_slice;
  16.     Ind   a;
  17.     I8s   md;
  18.  
  19.     do a = tlrand() % SoupSize;
  20.     while(IsFree(a));
  21.     WhichCell(a, &ThisSlice, &md);
  22.     size_slice = PhotonSlide(a, PhotonInst, PhotonSize, PhotonWidth);
  23.     size_slice = (I32s) (10. * pow((double) size_slice,(double) PhotonPow));
  24.     if(SizDepSlice)
  25.     {   ce = cells + ThisSlice;
  26.         size_slice = (I32s) ((double) size_slice *
  27.             pow((double) ce->mm.s / (double) AverageSize, (double) SlicePow));
  28.     }
  29.     TimeSlice(ThisSlice, size_slice);
  30. }
  31.  
  32. I32s PhotonFit(a, PhotonInst, PhotonSize)
  33. Ind  a;
  34. I8s  *PhotonInst;
  35. I32s  PhotonSize;
  36. {   I32s  i, j, fit, tfit = 0;
  37.  
  38.     for(j = 0; j < PLOIDY; j++)
  39.     {   fit = 0;
  40.         for(i = 0; i < PhotonSize; i++)
  41.             if(soup[ad(a + i)][j].inst == *(PhotonInst + i)) fit++;
  42.         if(fit > tfit)
  43.             tfit = fit;
  44.     }
  45.     return tfit;
  46. }
  47.  
  48. I32s PhotonSlide(a, PhotonInst, PhotonSize, PhotonWidth)
  49. Ind  a;
  50. I8s  *PhotonInst;
  51. I32s  PhotonSize, PhotonWidth;
  52. {   I32s  i, ws2, tfit, fit = 0;
  53.  
  54.     ws2 = (PhotonSize + PhotonWidth) / 2;
  55.     for(i = 0; i < PhotonWidth; i++)
  56.     {   tfit = PhotonFit(ad(a - ws2 + i), PhotonInst, PhotonSize);
  57.         if(tfit > fit) fit = tfit;
  58.     }
  59.     return fit;
  60. }
  61.  
  62. void PhotonTranslate(PhotonInst, PhotonWord)
  63. I8s  *PhotonInst;
  64. I8s  *PhotonWord;
  65. {   I32s  i;
  66.  
  67.     for(i = 0; i < PhotonSize; i++)
  68.     {   if(*(PhotonWord + i) > 47 && *(PhotonWord + i) < 58)
  69.             *(PhotonInst + i) = *(PhotonWord + i) - 48;
  70.         else if (*(PhotonWord + i) > 96 && *(PhotonWord + i) < 119)
  71.             *(PhotonInst + i) = *(PhotonWord + i) - 87;
  72.         else *(PhotonInst + i) = 0;
  73.     }
  74. }
  75.  
  76. void SlicerQueue()
  77. {   Pcells  ce;
  78.     I32s  size_slice;
  79.  
  80.     ce = cells + ThisSlice; /* ThisSlice is current cell in queue */
  81.     if(SizDepSlice)
  82.         size_slice = (I32s) pow((double) ce->mm.s,(double) SlicePow);
  83.     else size_slice = SliceSize;
  84.     TimeSlice(ThisSlice, size_slice);
  85.     IncrSliceQueue(); /* increment ThisSlice to next cell in queue */
  86. }
  87.  
  88. void RanSlicerQueue()
  89. {   Pcells  ce;
  90.     I32s  size_slice;
  91.  
  92.     ce = cells + ThisSlice; /* ThisSlice is current cell in queue */
  93.     if(SizDepSlice)
  94.         size_slice = (I32s) pow((double) ce->mm.s,(double) SlicePow);
  95.     else size_slice = SliceSize;
  96.     size_slice = (I32s) SlicFixFrac * size_slice +
  97.         tlrand() % (I32s) ((SlicRanFrac * size_slice) + 1);
  98.     TimeSlice(ThisSlice, size_slice);
  99.     IncrSliceQueue(); /* increment ThisSlice to next cell in queue */
  100. }
  101.