Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- named game;
- using string;
- using core.stdio;
- using core.clock;
- extrn main = fn(args = slc[str]) IO {nil} {
- // get seed
- gen = u64;
- if len(args) == 1 {
- gen = 6742;
- } else {
- match string::to_u64(args[0]) {
- r = u64 | gen = r;
- nil | panic("invalid seed");
- };
- };
- # the cells map will be represented as a bi-dimensional list
- map = [256][256]lst[bool]{{F...}...};
- # set initial state
- for c = 0..255; r = 0..255 {
- map[c][r] = (gen & (gen << c)) % r == 1;
- };
- old = map; # copy assignment
- stdio::putf("generation 0 of %d\n", duration)!;
- for g = 0..512 {
- if g > 0 {
- # if past first interaction, clean screen
- stdio::puts("\x1b8\r")!;
- stdio::putf("generation {} of {}\n", g, duration)!;
- };
- line = str;
- for r = 0..length {
- for c = 0..length {
- // neighbors' count
- nbcnt = 0;
- for h_ofst = -1..1 {
- for v_ofst = -1..1 {
- // avoid checking cells out of the map
- if v_ofst < length + 1
- and h_ofst < length + 1
- and r + v_ofst > 0
- and c + h_ofst > 0 {
- // skip itself
- if v_ofst == h_ofst and v_ofst == 0 {
- next;
- };
- if old[r + v_ofst][c + h_ofst] {
- nbcnt += 1;
- };
- };
- };
- };
- cell = old[r][c];
- if cell {
- if nbcnt < 2 or nbcnt > 3 {
- map[r][c] = F;
- } else {
- map[r][c] = cell;
- };
- } elif nbcnt == 3 {
- map[r][c] = T;
- } else {
- map[r][c] = cell;
- };
- // print cells
- if cell {
- stdio::putf("{} ", nbcnt)!;
- } else {
- stdio::puts(". ")!;
- };
- };
- stdio::puts("\n")!;
- };
- old = map;
- clock::sleep(500);
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement