cellular automaton Ants; const dimension = 2; distance = 1; type animaltype = (none, exists, accepted, obstacle); type celltype = record dir: celladdress; animal: animaltype; farbe: (lila, gelb, gruen, rot); timeleft : 0..100; corpse : boolean; carrying: boolean; end; global phase : (move, turn, choose); const cell = (*[0, 0]); const constantcell = [0,0,none,0]; initial [0,0,obstacle,0,0,true,false] ~ x = lx/3 and y > ly/3 and y < 2*ly/3 and option = 0; initial [0,0,obstacle,0,0,true,false] ~ y = ly/3 and x >= lx/3 and x <= 2*lx/3 and option = 0; initial [0,0,obstacle,0,0,true,false] ~ x = 2*lx/3 and y > ly/3 and y < 2*ly/3 and option = 0; initial [0,1,exists,random(3),10,prob(0.05),false] ~ prob(0.01) and option = 0; initial [1,0,exists,random(3),10,prob(0.05),false] ~ prob(0.01)and option = 0; initial [0,-1,exists,random(3),10,prob(0.05),false] ~ prob(0.01) and option = 0; initial [-1,0,exists,random(3),10,prob(0.05),false] ~ prob(0.01)and option = 0; initial [0,0,none,random(3),15,prob(0.05),false] ~ true; color [30,30,0] ~ cell.animal = obstacle; color [0,128,128] ~ cell.corpse and not (cell.animal=exists) ; color "fische.gif" (0:9,(cell.carrying?1:0)+(cell.corpse?1:0):4) ~ (cell.animal = exists and cell.dir = [1,0]); color "fische.gif" (1:9,(cell.carrying?1:0)+(cell.corpse?1:0):4) ~ (cell.animal = exists and cell.dir = [0,1]); color "fische.gif" (2:9,(cell.carrying?1:0)+(cell.corpse?1:0):4) ~ (cell.animal = exists and cell.dir = [0,-1]); color "fische.gif" (3:9,(cell.carrying?1:0)+(cell.corpse?1:0):4) ~ (cell.animal = exists and cell.dir = [-1,0]); color "fische.gif" (4:9,(cell.carrying?1:0)+(cell.corpse?1:0):4) ~ (cell.animal = exists and cell.dir = [0,0]); color "fische.gif" (5:9,(cell.carrying?1:0)+(cell.corpse?1:0):4) ~ (cell.animal = exists and cell.dir = [-1,1]); color "fische.gif" (6:9,(cell.carrying?1:0)+(cell.corpse?1:0):4) ~ (cell.animal = exists and cell.dir = [1,1]); color "fische.gif" (7:9,(cell.carrying?1:0)+(cell.corpse?1:0):4) ~ (cell.animal = exists and cell.dir = [1,-1]); color "fische.gif" (8:9,(cell.carrying?1:0)+(cell.corpse?1:0):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 testing 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 and cell.timeleft <= 0 then begin cell.dir.x := random(2)-1; cell.dir.y := random(2)-1; cell.timeleft := random(100); end; if cell.corpse and cell.animal=exists and not cell.carrying and prob(0.5) then begin cell.carrying := true; cell.corpse := false; end else if cell.animal=exists and cell.carrying and (not cell.corpse) and one (n in neighbors: n.corpse) then begin cell.carrying := false; cell.corpse := true; end; if cell.dir = [0,0] 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; cell.timeleft := n.timeleft-1; cell.carrying := n.carrying; end; end; end; end; rule global begin phase := next(phase); end;