home *** CD-ROM | disk | FTP | other *** search
- (* enhanced version of Conveys LIFE program with 4 different states:
- alive, dead, just_born, just_died
- and some statistical information *)
-
- RECIPE XYSize = 20;
- Zet = 4;
- Colors = 4;
-
- CONST dead = %00; (* bit sample 0000 *)
- just_died = %01; (* bit sample 0001 *)
- just_born = %10; (* bit sample 0010 *)
- alive = %11; (* bit sample 0011 *)
- (* A *)
- (* | *)
- (* "alive bit" *)
-
- REF east [1,0];
- west [-1,0];
- north [0,-1];
- south [0,1];
- north_ea [1,-1];
- north_we [-1,-1];
- south_ea [1,1];
- south_we [-1,1];
-
- VAR a, dead_count, alive_count, generation_count;
-
-
- PROC add_second_bit:; (* procedure evaluates second bit of *)
- (* neighbors that indicate alive state *)
- BEGIN (* and returns sum of found bits *)
- RETURN ((east XOR %01) SHR 1) + ((west XOR %01) SHR 1) +
- ((north XOR %01) SHR 1) + ((south XOR %01) SHR 1) +
- ((north_ea XOR %01) SHR 1) + ((north_we XOR %01) SHR 1) +
- ((south_ea XOR %01) SHR 1) + ((south_we XOR %01) SHR 1)
- END add_second_bit;
-
- EVENT SetUp;
- PlClipActive;
- dead_count := 0;
- alive_count := 0;
- generation_count := 0;
-
- EVENT E0; (* assignment of colors to states *)
- RGBBrush (dead, 0, 0, 0); (* black *)
- RGBBrush (just_died, 152, 88, 46); (* brown *)
- RGBBrush (just_born, 74, 229, 3); (* light green *)
- RGBBrush (alive, 50, 174, 30); (* dark green *)
-
- EVENT E1; (* initialization a *)
- PARALLEL DO
- a := Random (500);
- IF a > 492
- THEN Self := alive
- ELSE Self := dead
- FI;
- OD;
- ShowPlane;
-
- EVENT E2; (* initialization b *)
- PlFillRandom (dead, alive);
- generation_count := 0;
- ShowPlane;
-
- EVENT E3;
- generation_count := generation_count + 1;
-
- PARALLEL DO
- a := add_second_bit;
-
- IF (a = 2) OR (a = 3)
- THEN IF (a = 3) AND ((Self = dead) OR (Self = just_died))
- THEN Self := just_born;
- alive_count := alive_count + 1;
- ELSE Self := alive;
- alive_count := alive_count + 1;
- FI;
- ELSE IF (Self = alive) OR (Self = just_born)
- THEN Self := just_died;
- dead_count := dead_count + 1;
- ELSE Self := dead;
- dead_count := dead_count + 1;
- FI;
- FI;
- OD;
-
- WRITE ('', 'GEN. :', generation_count, ' DEAD :', dead_count, ' ALIVE :', alive_count );
- dead_count := 0;
- alive_count := 0;
- ShowPlane;
-
- END.
-
- ********************************
- * compilation o.k. *
- ********************************
-
- GEN. :1 DEAD :258 ALIVE :142
-
- GEN. :2 DEAD :246 ALIVE :154
-
- GEN. :3 DEAD :220 ALIVE :180
- GEN. :4 DEAD :239 ALIVE :161
- GEN. :5 DEAD :252 ALIVE :148
- GEN. :6 DEAD :222 ALIVE :178
- GEN. :7 DEAD :241 ALIVE :159
- GEN. :8 DEAD :219 ALIVE :181
-
-