Anonymous user
Conway's Game of Life: Difference between revisions
m
→version 1: added/changed comments, indentations, and whitespace, made general improvements.
m ((reorder of entry)) |
m (→version 1: added/changed comments, indentations, and whitespace, made general improvements.) |
||
Line 7,533:
=={{header|REXX}}==
===version 1===
This version has been trimmed down from the original REXX program, otherwise the size of the program (with all its options and optional formatting)
<br>would probably be on the
<lang rexx>/*REXX program displays the Conway's game of life, it stops after N repeats. */
signal on halt /*handle a cell growth interruptus. */
parse arg peeps '(' rows cols empty life! clearScreen repeats generations
rows = p(rows 3) /*the maximum number of cell rows. */
cols = p(cols 3) /* " " " " "
emp = pickChar(empty 'blank') /*an empty cell character (glyph). */
clearScr = p(clearScreen 0) /* "1" indicates to clear the screen.*/
clearscr=1
clearscr=0
life! = pickChar(life! '☼') /*the gylph kinda looks like an
reps = p(repeats 2) /*stop pgm if there are
generations = p(generations 100) /*the number of generations allowed. */
usw=max(linesize()-1,cols) /*usable screen width for the display. */
#reps=0; $.=emp /*the universe is new, ··· and barren.*/
gens=abs(generations)
x=space(peeps); upper x /*elide superfluous spaces;
if x=='' then x=
if x=='BLINKER' then x=
if x=='GLIDER' then x=
if x=='OCTAGON' then x=
call assign. /*assign the initial state of all cells
call showCells /*show the initial state of the cells.*/
/* [↓] cell colony
do life=1 for gens; call assign@ /*construct
if generations>0 | life==gens then call showCells /*
end /*life*/
fin: exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
showCells: if clearScr then 'CLS' /* ◄─── change this for your OS. */
call showRows; ?='▒' /*show the rows in the proper order. */
say right(copies(
if _=='' then call fin /*if there's no life,
if !._ then #reps=#reps+1 /*we detected a repeated cell pattern. */
!._=1 /*existence state
if reps\==0 & #reps<=reps then return /*so far, so good, regarding
say; say center('
call fin /*stick a fork in it, we're all done. */
/*───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────*/
$: parse arg _row,_col; return $._row._col==life!
assign$: do r=1 for rows; do c=1 for cols; $.r.c=@.r.c; end; end; return
assign.: do while x\==''; parse var x r
assign?: ?=$.r.c; n=neighbors(); if ?==emp then do;if n==3 then ?=life!; end; else if n<2 | n>3 then ?=emp; @.r.c=?; return
assign@: @.=emp; do r=1 for rows; do c=1 for cols; call assign?; end; end; call assign$;
halt: say; say 'REXX program halted.';
neighbors: rm=r-1; rp=r+1; cm=c-1; cp=c+1;
p: return word(arg(1), 1)
pickChar: _=p(arg(1)); arg u .; if u=='BLANK' then _=
showRows: _=; do r=rows by -1 for rows; z=; do c=1 for cols; z=z||$.r.c; end; z=strip(z,'T',emp); say z; _=_||z; end; return</lang>
This REXX program makes use of '''
<br>The '''LINESIZE.REX''' REXX program is included here ──► [[LINESIZE.REX]]. <br>
Line 7,590:
☼☼☼
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 0
☼
☼
☼
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 1
☼☼☼
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 2
☼
☼
☼
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 3
☼☼☼
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 4
</pre>
|