Created
April 14, 2024 06:38
-
-
Save kwccoin/c745221c1e696543f4efde3fc016e796 to your computer and use it in GitHub Desktop.
start of full screen Brexx game of life ver 0.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* CONWAY'S GAME OF LIFE FOR REXX */ | |
/* FOR BREXX ON MVS 3.8 and VM */ | |
/* COPYRIGHT 2024 BY MOSHIX */ | |
/* BREXX.V2R3M3.SAMPLES(#TSOAPPL) */ | |
/* Modified by KWC Ver 0.1 */ | |
CALL IMPORT FSSAPI | |
ADDRESS FSS | |
CALL FSSINIT | |
CALL FSSDISPLAY | |
version="0.2" | |
rows = 20 | |
cols = 30 | |
generations = 5 | |
/* initialize the board with random data */ | |
do row = 1 to rows | |
do col = 1 to cols | |
world.row.col = random(0,1) | |
end | |
end | |
/* display the initial random world */ | |
call DisplayWorld | |
/* run throu generations */ | |
do gen = 1 to generations | |
/*say ' ' */ | |
/*say 'Genneration nr: 'gen */ | |
/*say '------------------' */ | |
/*say ' ' */ | |
call NextGeneration | |
/*say ' ' */ | |
call DisplayWorld | |
end | |
CALL FSSDISPLAY | |
say ' ' | |
say 'Initial, random world' | |
say '=====================' | |
say 'Conway Game of life for BREXX' | |
say '=============================' | |
say ' ' | |
say 'Nr. Rows for this run: 'rows | |
say 'Nr. Cols for this run: 'cols | |
say ' ' | |
CALL FSSCLOSE | |
exit /* end of the program */ | |
NextGeneration: | |
/* implement the rules of Conways Game of life */ | |
do row = 1 to rows | |
do col = 1 to cols | |
neighbors = CountNeighbors(row, col) | |
if world.row.col = 1 then do | |
/* strange this ¶ becomes a wrong characer Ñú when to ebcdid */ | |
/* seems ! is still not become Ñú, not ¶ */ | |
if neighbors < 2 | neighbors > 3 then | |
temp.row.col = 0 | |
else | |
temp.row.col = 1 | |
end | |
else do | |
if neighbors = 3 then | |
temp.row.col = 1 | |
else | |
temp.row.col = 0 | |
end | |
end | |
end | |
/* if C one can pointer */ | |
/* can we have a current world.#.row.col */ | |
/* then switch the number # ? */ | |
/* copy temp map to display map */ | |
do row = 1 to rows | |
do col = 1 to cols | |
world.row.col = temp.row.col | |
end | |
end | |
return | |
CountNeighbors: | |
/* count neighbors per cell */ | |
parse arg row,col | |
neighbors = 0 | |
do dr = -1 to 1 | |
do dc = -1 to 1 | |
if dr = 0 & dc = 0 then iterate | |
nr = row + dr | |
nc = col + dc | |
if nr > 0 & nr <= rows & nc > 0 & nc <= cols then | |
neighbors = neighbors + world.nr.nc | |
end | |
end | |
return neighbors | |
DisplayWorld: | |
CALL FSSREFRESH | |
/* show the map on the screen */ | |
do row = 1 to rows | |
line = '' | |
do col = 1 to cols | |
if world.row.col = 1 then | |
/* also here all 4 Ñú need to becomes ¶ */ | |
/* may need a mainframe utilty to change ¶ */ | |
line = line || '#' | |
/* CALL FSSTEXT '#',row,col,#HI */ | |
else | |
line = line || ' ' | |
/* CALL FSSTEXT '_',row,col,#NON */ | |
end | |
say line | |
end | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment