Jump to content

One-dimensional cellular automata: Difference between revisions

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