home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / cellsim / v2_5 / rule_src / bzm256.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-26  |  1.3 KB  |  57 lines

  1. /*
  2.  * File: bz.m256.c
  3.  *   By: Dave Hiebeler
  4.  *       hiebeler@turing.cs.rpi.edu
  5.  *       February 1990
  6.  *
  7.  * The version of the Belousov-Zhabotinski ("BZ") reaction described in
  8.  * the CAM book by Toffoli and Margolus (also discussed as the "hodgepodge"
  9.  * model in A.K. Dewdney's "Computer Recreations" colum in Scientific
  10.  * American, sometime in 1989).
  11.  *
  12.  * The low bitplane represents the presence of a "tubeworm" (to use the
  13.  * language of Toffoli and Margolus).  If a worm is present and sees
  14.  * too many neighbors also active, it retreats into its tube and hides
  15.  * there for a few time-steps  (a timer is on the upper 2 bitplanes).
  16.  */
  17.  
  18.  
  19. #include "nborhood.h"
  20.  
  21. #define WORM 0x04    /* mask to get low bitplane */
  22. #define CLOCK 0x03
  23.  
  24.  
  25. byte bz();
  26.  
  27. void
  28. init_function()
  29. {
  30.     update_function = bz;
  31.     parm1 = 3;
  32. }
  33.  
  34.  
  35. byte
  36. bz(nbors)
  37. moore_nbors *nbors;
  38. {
  39.     int nbor_sum;
  40.     byte ret_val;
  41.     
  42.     Get_moore_nbors;
  43.     ret_val = 0;
  44.     nbor_sum = (tl&WORM) + (l&WORM) + (bl&WORM) + (t&WORM) + (b&WORM) +
  45.     (tr&WORM) + (r&WORM) + (br&WORM);
  46.     nbor_sum = nbor_sum >> 2;
  47.     if (!(c&CLOCK))
  48.     ret_val = 0x04;
  49.     if ((nbor_sum >= parm1) || (nbor_sum == parm2))
  50.     ret_val |= 0x08;
  51.     if ((c&0x0c) == 0x0c)
  52.     ret_val |= 3;
  53.     else if (c&0x03)
  54.     ret_val |= (c&0x03)-1;
  55.     return ret_val;
  56. }
  57.