Last active
April 28, 2020 07:48
-
-
Save adymitruk/875c92d76cd88cc7ef21e0af8eacdaff to your computer and use it in GitHub Desktop.
Conway's game of life in fishshell
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
set DEAD " "; set LIVE "🌱"; set wid 21; set hei 21 | |
for cell in b(seq 2)r(seq $hei)c(seq $wid); set -g $cell $DEAD; end | |
set -g flip 1; set -g flop 2 | |
function show_board | |
for row in (seq $hei); for col in (seq $wid); set -l cell b{$flip}r{$row}c{$col}; echo -n $$cell | |
end; echo; end; end | |
set b1r10c10 $LIVE; set b1r10c11 $LIVE; set b1r10c12 $LIVE; | |
set b1r11c10 $LIVE; set b1r11c12 $LIVE; | |
set b1r12c10 $LIVE; set b1r12c11 $LIVE; set b1r12c12 $LIVE; | |
while true | |
show_board | |
for row in (seq $hei); for col in (seq $wid); | |
set count 0 | |
set dest b{$flop}r{$row}c{$col}; | |
if test $row -ne 1 -a $col -ne 1; set r (math $row -1); set c (math $col -1); set src b{$flip}r{$r}c{$c}; | |
if test "$$src" = "$LIVE"; set count (math $count +1); end; end;# top left | |
if test $row -ne 1; set r (math $row -1); set c $col; set src b{$flip}r{$r}c{$c}; | |
if test "$$src" = "$LIVE"; set count (math $count +1); end; end;# top | |
if test $row -ne 1 -a $col -ne $wid; set r (math $row -1); set c (math $col +1); set src b{$flip}r{$r}c{$c}; | |
if test "$$src" = "$LIVE"; set count (math $count +1); end; end;# top right | |
if test $col -ne $wid; set r $row; set c (math $col +1); set src b{$flip}r{$r}c{$c}; | |
if test "$$src" = "$LIVE"; set count (math $count +1); end; end;# right | |
if test $row -ne $hei -a $col -ne $wid; set r (math $row +1); set c (math $col +1); set src b{$flip}r{$r}c{$c}; | |
if test "$$src" = "$LIVE"; set count (math $count +1); end; end;# bottom right | |
if test $row -ne $hei; set r (math $row +1); set c $col; set src b{$flip}r{$r}c{$c}; | |
if test "$$src" = "$LIVE"; set count (math $count +1); end; end;# bottom | |
if test $row -ne $hei -a $col -ne 1; set r (math $row +1); set c (math $col -1); set src b{$flip}r{$r}c{$c}; | |
if test "$$src" = "$LIVE"; set count (math $count +1); end; end;# bottom left | |
if test $col -ne 1; set r $row; set c (math $col -1); set src b{$flip}r{$r}c{$c}; | |
if test "$$src" = "$LIVE"; set count (math $count +1); end; end;# left | |
set src b{$flip}r{$row}c{$col} | |
if test "$$src" = "$LIVE" -a $count -gt 1 -a $count -lt 4; set $dest $LIVE; continue; end | |
if test "$$src" = "$DEAD" -a $count = 3; set $dest $LIVE; continue; end | |
set $dest $DEAD | |
end; end | |
if test $flip -eq 1; set flip 2; set flop 1; else; set flip 1; set flop 2; end | |
string repeat -n (math $hei + 1) \x1B\x5B\x41 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment