-- Adam's occam life implementation. vim:et:ts=2 #INCLUDE "consts.inc" #USE "course.lib" VAL INT grid.size IS 100: PROC cell (VAL BOOL init, [8]CHAN OF BOOL ins, outs, CHAN OF BOOL tick, out) BOOL state: SEQ state := init [8]BOOL others: INT count: WHILE TRUE SEQ PAR out ! state PAR i = 0 FOR 8 outs[i] ! state PAR i = 0 FOR 8 ins[i] ? others[i] count := 0 SEQ i = 0 FOR 8 IF others[i] count := count + 1 TRUE SKIP IF state AND (count = 2) state := TRUE count = 3 state := TRUE TRUE state := FALSE BOOL b: tick ? b : PROC ticker ([grid.size][grid.size]CHAN OF BOOL tick) WHILE TRUE PAR x = 0 FOR grid.size PAR y = 0 FOR grid.size tick[x][y] ! TRUE : PROC display ([grid.size][grid.size]CHAN OF BOOL state, CHAN OF BYTE out) [grid.size][grid.size]BOOL grid: WHILE TRUE SEQ PAR x = 0 FOR grid.size PAR y = 0 FOR grid.size state[x][y] ? grid[x][y] goto.x.y (0, 0, out) SEQ y = 0 FOR grid.size SEQ SEQ x = 0 FOR grid.size IF grid[x][y] out ! '#' TRUE out ! ' ' out ! '*c' out ! '*n' : PROC life (CHAN OF BYTE in, out, err) [grid.size][grid.size][4][2]CHAN OF BOOL links: #PRAGMA SHARED links [grid.size][grid.size]CHAN OF BOOL tick, state: [grid.size][grid.size]BOOL init: VAL INT half IS grid.size / 2: SEQ erase.screen (out) PAR x = 0 FOR grid.size PAR y = 0 FOR grid.size init[x][y] := FALSE -- The R pentomino init[half-1][half] := TRUE init[half][half-1] := TRUE init[half][half] := TRUE init[half][half+1] := TRUE init[half+1][half-1] := TRUE PAR PAR x = 0 FOR grid.size PAR y = 0 FOR grid.size [8]CHAN OF BOOL ins IS [links[x][y][0][1], links[x][y][1][0], links[x][y][2][1], links[x][y][3][1], links[(x+1)\grid.size][(y+1)\grid.size][0][0], links[x][(y+1)\grid.size][1][1], links[(x+(grid.size-1))\grid.size][(y+1)\grid.size][2][0], links[(x+(grid.size-1))\grid.size][y][3][0]]: [8]CHAN OF BOOL outs IS [links[x][y][0][0], links[x][y][1][1], links[x][y][2][0], links[x][y][3][0], links[(x+1)\grid.size][(y+1)\grid.size][0][1], links[x][(y+1)\grid.size][1][0], links[(x+(grid.size-1))\grid.size][(y+1)\grid.size][2][1], links[(x+(grid.size-1))\grid.size][y][3][1]]: cell (init[x][y], ins, outs, tick[x][y], state[x][y]) ticker (tick) display (state, out) :