Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-rosetta/blob/main/drafts/rosettacode/conways-game-of-life.wiki # omega-rosetta aien-dev/omega-rosetta Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-rosetta / drafts / rosettacode / conways-game-of-life.wiki` 156 lines ยท 2532 bytes Raw Blame History 1 =={{header|Omegese}}== 2 {{works with|omc|sha256 `2c824805`, aien-dev/omega-mv `e5b32567`, Linux AArch64}} 3 Omega has no imports, so the small output helpers (emit and friends) are part of the program. 4 5 om2 6 text nl "\n" 7 text sp " " 8 text minus "-" 9 text tgen "generation " 10 text tdot "." 11 text thash "#" 12 global cur uchar 64 13 global nxt uchar 64 14 global dim ulong 2 15 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 16 fn emit a view uchar * to void 17 o = ulong 0 18 while lt o len a bound 4096 19 k = write 1 a o sub len a o 20 if le k 0 21 exit 1 22 end 23 o = add o ulong k 24 end 25 end 26 note emitu writes n in decimal; 20 digits hold every ulong 27 fn emitu n ulong to void 28 d = new uchar 20 0 29 i = ulong 20 30 v = n 31 while true bound 20 32 i = sub i 1 33 put d i uchar add rem v 10 48 34 v = div v 10 35 if eq v 0 36 break 37 end 38 end 39 emit part d i sub 20 i 40 end 41 note the board is dim[0] rows by dim[1] columns, row by row, with dead cells beyond the edges; a live 42 note cell with 2 or 3 live neighbours lives on, a dead one with exactly 3 comes alive 43 fn alive r long c long to ulong 44 if or or lt r 0 ge r long get dim 0 or lt c 0 ge c long get dim 1 45 ret 0 46 end 47 ret ulong get cur add mul ulong r get dim 1 ulong c 48 end 49 fn around r long c long to ulong 50 n = ulong 0 51 for a ulong 3 52 for b ulong 3 53 if or ne a 1 ne b 1 54 n = add n alive sub add r long a 1 sub add c long b 1 55 end 56 end 57 end 58 ret n 59 end 60 fn step to void 61 w = get dim 1 62 for r ulong get dim 0 63 for c ulong w 64 n = around long r long c 65 v = uchar 0 66 if eq n 3 67 v = 1 68 end 69 if and eq n 2 eq get cur add mul r w c 1 70 v = 1 71 end 72 put nxt add mul r w c v 73 end 74 end 75 for i ulong mul get dim 0 w 76 put cur i get nxt i 77 end 78 end 79 fn show g ulong to void 80 emit tgen 81 emitu g 82 emit nl 83 w = get dim 1 84 for r ulong get dim 0 85 for c ulong w 86 if eq get cur add mul r w c 1 87 emit thash 88 else 89 emit tdot 90 end 91 end 92 emit nl 93 end 94 end 95 fn run gens ulong to void 96 for g ulong add gens 1 97 show g 98 if lt g gens 99 step 100 end 101 end 102 end 103 fn main to int 104 note a blinker on a 3 x 3 board for 3 generations 105 put dim 0 3 106 put dim 1 3 107 for i ulong 9 108 put cur i 0 109 end 110 put cur 3 1 111 put cur 4 1 112 put cur 5 1 113 run 2 114 emit nl 115 note a glider on an 8 x 8 board; after 4 generations it has moved one cell down and right 116 put dim 0 8 117 put dim 1 8 118 for i ulong 64 119 put cur i 0 120 end 121 put cur 1 1 122 put cur 10 1 123 put cur 16 1 124 put cur 17 1 125 put cur 18 1 126 run 4 127 ret 0 128 end 129 130 {{out}} 131

132 generation 0

133 ...

134 ###

135 ...

136 generation 1

137 .#.

138 .#.

139 .#.

140 generation 2

141 ...

142 ###

143 ...

144

145 generation 0

146 .#......

147 ...

148 ........

149 ..#.....

150 ...#....

151 .###....

152 ........

153 ........

154 ........

155 ........

156