I have implemented Game of Life.
What I cannot work out is how to print every iteration of the cell array in the shell. I want to make the output appear animated.
Here is my array print code
def print_board board
wipe_screen
board.each_with_index do |row,y|
row.each_with_index do |cell,x|
print cell == 1 ? '*' : ' '
end
print "\n"
end
end
and here is the wipe_screen
method:
def wipe_screen
Board_Height.each do |_|
# print "\r"
# $stdout.write "\e[A\e[2K"
end
end
You can see in the commented out bits what I have already tried.
How can I achieve animated output inside the shell?
EDIT:
Allow me to clarify with an example.
It simply prints out each iteration of the Game of Life cycle):
* * * * ** **
*** * ** * * * **
** **** * * **** *
** * ** * ** **
* * ** * *****
***** * **** *
***** * * ** * *
* ** *** * ** ****
* ** * ** ***** *
** * * * *****
* ** *
** **** *** *
*** * *** *
* ** *****
** *****
** *
** ****
** * * *
**** * *****
* ****
* ** *
* **** *** *
*** * *** *
** *****
** ***
** ***
*** * **
* * ****
***** ** ****
* ****
* ** *
**** *** *
** * *** *
** ***
** ***
** ***
*** * **
* * **
***** *** **
* ****
** *
**** *** *
** * * *
** ***
** ***
** ***
*** ** *
* * *
***** **** *
* ****
Whereas what I want is:
* * * * ** **
*** * ** * * * **
** **** * * **** *
** * ** * ** **
* * ** * *****
***** * **** *
***** * * ** * *
* ** *** * ** ****
* ** * ** ***** *
** * * * *****
Then, as it iterates over the game of life cycle, replaced by:
* ****
** *
**** *** *
** * * *
** ***
** ***
** ***
*** ** *
* * *
***** **** *
* ****
EDIT:
game of life gist