// field array for scanning each field without having to use explicit name fld choices[] = { :scissor, :rock, :dynamite, :paper}; // threshold value to determine winner int threshold=3; // index variables int i, j; nbr y; // counter array for the four different fields int sum[4]; // as usual, default is no change to any field default init=init; default scissor=scissor; default rock=rock; default dynamite=dynamite; default paper=paper; // the init field is used only between epoch 0 -> 1 to initialize the // four different fields, making sure that only one field is set. After // that the init field itself is reset to zero. Note that init's initial // value range is 1 through 4. if (init) { choices[init-1]=1; init=0; // now we enter the actual rule set that determines the diffusion behavior } else { // first we initialize the counter array to zeros i=0; while (i<4) { sum[i]=0; i++; } // next we scan all four fields in all Moore neighbors to count values over each other y: { i=0; while (i<4) { if (y:choices[i]) sum[i]++; i++; } } // finally, determine if a value migration is called for i=0; while (i<4) { if (choices[i] && sum[(i+1)%4]>=threshold) { choices[i]=0; choices[(i+1)%4]=1; break; } i++; } }