One-dimensional cellular automata: Difference between revisions

Content added Content deleted
Line 672: Line 672:


<lang cobol>
<lang cobol>
* one-dimensional cellular automata
Identification division.
Identification division.
Program-id. rc-1d-cell.
Program-id. rc-1d-cell.
Line 678: Line 679:
Working-storage section.
Working-storage section.
* "Constants."
* "Constants."
01 max-gens pic 999 value 9.
01 max-gens pic 999 value 9.
01 state-width pic 99 value 20.
01 state-width pic 99 value 20.
Line 685: Line 686:
01 dead pic x value ".".
01 dead pic x value ".".
* The current state.
* The current state.
01 state-gen pic 999 value 0.
01 state-gen pic 999 value 0.
01 state-row.
01 state-row.
Line 693: Line 694:
10 state-cells pic x occurs 20 times.
10 state-cells pic x occurs 20 times.
* The new state.
* The new state.
01 new-state-table.
01 new-state-table.
05 new-state-cells pic x occurs 20 times.
05 new-state-cells pic x occurs 20 times.
* Pointer into cell table during generational production.
* Pointer into cell table during generational production.
01 cell-index pic 99.
01 cell-index pic 99.
88 at-beginning value 1.
88 at-beginning value 1.
Line 703: Line 704:
88 at-end value 20.
88 at-end value 20.
* The cell's neighborhood.
* The cell's neighborhood.
01 neighbor-count-table.
01 neighbor-count-table.
03 neighbor-count pic 9 occurs 20 times.
03 neighbor-count pic 9 occurs 20 times.
Line 722: Line 723:
Display state-row.
Display state-row.
* Determine who lives and who dies.
* Determine who lives and who dies.
Next-state.
Next-state.
Add 1 to state-gen.
Add 1 to state-gen.
Line 747: Line 748:
move new-state-table to state-table.
move new-state-table to state-table.
* Living cell with wrong number of neighbors...
* Living cell with wrong number of neighbors...
Die-off.
Die-off.
if state-cells(cell-index) =
if state-cells(cell-index) =
Line 755: Line 756:
.
.
* Empty cell with exactly two neighbors are...
* Empty cell with exactly two neighbors are...
New-births.
New-births.
if state-cells(cell-index) = dead and is-ripe (cell-index)
if state-cells(cell-index) = dead and is-ripe (cell-index)
Line 761: Line 762:
end-if
end-if
.
.
* How many living neighbors does a cell have?
* How many living neighbors does a cell have?
Count-neighbors.
Count-neighbors.
Move 0 to neighbor-count(cell-index)
Move 0 to neighbor-count(cell-index)
Line 778: Line 779:
.
.
* String is easier to enter, but table is easier to work with,
* String is easier to enter, but table is easier to work with,
* so move each character of the initialization string to the
* so move each character of the initialization string to the
* state table.
* state table.
Init-state-table.
Init-state-table.