MadonnaModel Arial!D(.2> B 6:N1 ! =({Conway's game of "Life" -- original von Neuman neighborhood} {simulation control parameters} METHOD Euler STARTTIME = 0 STOPTIME= 10 DT = 1 DTOUT = 1 {specify the size of the grid by the value of end} begin = 1 end = 5 {Initialize the cells by reading external data} init cells[begin..end,begin..end] = #cell_init_neuman(i,j) {ensure cell values do not become negative or greater than one} limit cells >= 0 limit cells <= 1 {specify the number of neighbors who must be alive to sustain life in a cell} {different values for central, corner, and edge cells} CELL_LIVE = 3 CELL_LIVE_CORNER = 1 CELL_LIVE_EDGE = 2 {count the number of von Neuman neighbors who are alive} status_count[begin..end,begin..end] = IF ((i = begin) AND (j = begin)) THEN cells[i,j+1] + cells[i+1,j] ELSE IF ((i = begin) AND (j = end)) THEN cells[i,j-1] + cells[i+1,j] ELSE IF ((i = end) AND (j = end)) THEN cells[i,j-1] + cells[i-1,j] ELSE IF ((i = end) AND (j = begin)) THEN cells[i,j+1] + cells[i-1,j] ELSE IF ((i-1 < begin)) THEN cells[i,j+1] + cells[i,j-1] + cells[i+1,j] ELSE IF ((i+1 > end)) THEN cells[i,j+1] + cells[i,j-1] + cells[i-1,j] ELSE IF ((j-1 < begin)) THEN cells[i+1,j] + cells[i-1,j] + cells[i,j+1] ELSE IF ((j+1 > end)) THEN cells[i+1,j] + cells[i-1,j] + cells[i,j-1] ELSE cells[i+1,j] + cells[i-1,j] + cells[i,j+1] + cells[i,j-1] {apply the alive rule to each cell based on its number of live neighbors} cell_state[begin..end,begin..end] = IF ((i = begin) AND (j = begin) AND (status_count[i,j] = CELL_LIVE_CORNER)) THEN 1 ELSE IF ((i = begin) AND (j = end) AND (status_count[i,j] = CELL_LIVE_CORNER)) THEN 1 ELSE IF ((i = end) AND (j = end) AND (status_count[i,j] = CELL_LIVE_CORNER)) THEN 1 ELSE IF ((i = end) AND (j = begin) AND (status_count[i,j] = CELL_LIVE_CORNER)) THEN 1 ELSE IF ((i-1 < begin) AND (j <> end) AND (j <> begin) AND (status_count[i,j] = CELL_LIVE_EDGE)) THEN 1 ELSE IF ((i+1 > end) AND (j <> end) AND (j <> begin) AND (status_count[i,j] = CELL_LIVE_EDGE)) THEN 1 ELSE IF ((j-1 < begin) AND (i <> end) AND (i <> begin) AND (status_count[i,j] = CELL_LIVE_EDGE)) THEN 1 ELSE IF ((j+1 > end) AND (i <> end) AND (i <> begin) AND (status_count[i,j] = CELL_LIVE_EDGE)) THEN 1 ELSE IF ((i <> end) AND (i <> begin) AND (j <> end) AND (j <> begin) AND (status_count[i,j] = CELL_LIVE)) THEN 1 ELSE 0 {calculate the number of alive cells over the grid -- used for display only} cell_sum = ARRAYSUM(cells[*]) {initiate cell to next state on next time step} next cells[begin..end,begin..end] = cell_state[i,j])A ) q Y#cell_init ?@@@@@?????@?@@????@??@???)!*m,"#cell_init_neuman ?@@@@@???@??@@?@??@??,,9/u,A/A@ eulerMbP?MbP?MbP? $HLP & ,6b.Fjnr z ))/v)y)e)m/) )$0&0(1* 1,/./1