cellular automaton robot ; /* robot CA */ type celltype = record s: integer; dir: 0..4; end; const dimension = 2; distance = 1; group neighbors4 = {*[0,1],*[0,-1],*[1,0],*[-1,0]}; group neighbors8 = {*[0,1],*[0,-1],*[1,0],*[-1,0], *[1,1],*[-1,1],*[1,-1],*[-1,-1]}; initial [3,0] ~ (x = 2*lx/3 and y = 2*ly/3) ; [1,0] ~ x+1 = lx/2 and (y = ly/2 or y = ly/2+1) ; [2,0] ~ x = lx/3 and y = ly/3 ; [1,0] ~ x = lx/4+2 and y = ly/2+1; [1,0] ~ x = lx/2-2 and y = ly/4; [0,0] ~ true; color [255,0,0] ~ *[0,0].s = 1; [255,255,0] ~ *[0,0].s = 2 or *[0,0].dir > 0; [8**[0,0].s mod 255,8**[0,0].s mod 255,8* *[0,0].s mod 255] ~ *[0,0].s > 2; var c: celltype; temp : integer; global t: integer; rule global begin t := t+1; end; rule begin temp := 10000; for c in neighbors4 do if (c.s > 2 and c.s < temp) then temp := c.s; if *[0,0].s = 0 then if t < 3 and one (c in neighbors8: c.s = 1) then *[0,0].s := 1 else if t > 3 and t < 50 and temp != 10000 then *[0,0].s := temp+1; if t >= 50 then begin if *[0,0].s = 2 then begin if *[0,1].s = temp then *[0,0].dir := 1; if *[0,-1].s = temp then *[0,0].dir := 2; if *[1,0].s = temp then *[0,0].dir := 3; if *[-1,0].s = temp then *[0,0].dir := 4; end; if *[0,0].s > 3 then begin if *[0,-1].dir = 1 or *[0,1].dir = 2 or *[-1,0].dir = 3 or *[1,0].dir = 4 then *[0,0].s := 2; end; if *[0,0].dir > 0 then *[0,0].s := 0; end; end;