cellular automaton Fische2; const dimension = 2; distance = 1; type animaltype = (none, exists, accepted); type celltype = record dir: celladdress; animal: animaltype; farbe: (lila, gelb, gruen, rot); end; global phase : (move, turn, choose); const cell = (*[0, 0]); const constantcell = [0,0,none,0]; initial [0,1,exists,random(3)] ~ prob(0.05) and option = 0; initial [1,0,exists,random(3)] ~ prob(0.05)and option = 0; initial [0,-1,exists,random(3)] ~ prob(0.05) and option = 0; initial [-1,0,exists,random(3)] ~ prob(0.05)and option = 0; initial [0,1,exists,random(3)] ~ option = 1 and prob(0.5) and x < 3*lx/5 and x > 2*lx/5 and y < 4*ly/5 ; initial [0,1,exists,0] ~ option = 2 and prob(0.3) and x < 3*lx/5 and x > 2*lx/5 and y < 4*ly/5 ; initial [1,0,exists,1] ~ option = 2 and prob(0.3) and x < lx/5 and y < 2*ly/5 ; initial [-1,-1,exists,3] ~ option = 2 and prob(0.3) and x > 3*lx/5 and y > 3*ly/5 ; initial [0,0,none,random(3)] ~ true; color "fische.gif" (0:9,cell.farbe:4) ~ (cell.animal = exists and cell.dir = [1,0]); color "fische.gif" (1:9,cell.farbe:4) ~ (cell.animal = exists and cell.dir = [0,1]); color "fische.gif" (2:9,cell.farbe:4) ~ (cell.animal = exists and cell.dir = [0,-1]); color "fische.gif" (3:9,cell.farbe:4) ~ (cell.animal = exists and cell.dir = [-1,0]); color "fische.gif" (4:9,cell.farbe:4) ~ (cell.animal = exists and cell.dir = [0,0]); color "fische.gif" (5:9,cell.farbe:4) ~ (cell.animal = exists and cell.dir = [-1,1]); color "fische.gif" (6:9,cell.farbe:4) ~ (cell.animal = exists and cell.dir = [1,1]); color "fische.gif" (7:9,cell.farbe:4) ~ (cell.animal = exists and cell.dir = [1,-1]); color "fische.gif" (8:9,cell.farbe:4) ~ (cell.animal = exists and cell.dir = [-1,-1]); color [0, 255, 255] ~ true; var n : celltype; var sumx, sumy : -2..2; var rand: 0..3; dest, invdest : celladdress; group neighbors = {*[0, 1], *[0, -1], *[1, 0], *[-1, 0], *[1, 1], *[1, -1], *[-1, 1], *[-1, -1]}; group invneighbors = {[0, -1], [0, 1], [-1, 0], [1, 0], [-1, -1], [-1, 1], [1, -1], [1, 1]}; rule begin if (phase = move) then begin if cell.animal = exists then begin dest := cell.dir; if *dest.animal = accepted and *dest.dir = cell.dir then cell.animal := none else cell.dir := [0,0]; end; if cell.animal = accepted then begin cell.animal := exists; end; end; if phase = turn then begin if cell.animal = exists then begin sumx := sum(n in neighbors: n.dir.x); sumy := sum(n in neighbors: n.dir.y); cell.dir.x := sign(sumx); cell.dir.y := sign(sumy); end; if prob(0.01) then begin cell.dir.x := cell.dir.y; cell.dir.y := -cell.dir.x; end; if cell.dir = [0,0] and prob(0.1) then begin rand := random(7); case rand of 0: cell.dir := [0,1]; 1: cell.dir := [0,-1]; 2: cell.dir := [1,0]; 3: cell.dir := [-1,0]; 4: cell.dir := [1,1]; 5: cell.dir := [1,-1]; 6: cell.dir := [-1,1]; 7: cell.dir := [-1,-1]; end; end; end; if (phase = choose ) then begin if cell.animal = none then begin cell.dir := [0,0]; for n in neighbors & invdest in invneighbors do if n.animal = exists and n.dir = invdest then begin cell.animal := accepted; cell.dir := invdest; cell.farbe := n.farbe; end; end; end; end; rule global begin phase := next(phase); end;