I made terminal CGOL. It has flicker on Windows though. Apparently you can't attach and exe.
https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
c++ code:
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <vector>
#include <sstream>
#include <iostream>
//#include <chrono>
//#include <thread>
//https://stackoverflow.com/questions/10918206/cross-platform-sleep-function-for-c
using namespace std;
int ww, hh, count, dens;
int noffs[8][2] = {
{-1, -1}, {0, -1}, {1, -1},
{-1, 0}, {1, 0},
{-1, 1}, {0, 1}, {1, 1}
};
class Thing {
public:
bool alive;
int ncount;
int xx, yy;
static Thing createInstance(int ind) {
return Thing(ind);
}
void updateCount(vector<Thing>* gd) {
ncount = 0;
for(int a=0; a<8; a++) {
int nx = xx+noffs[a][0];
int ny = yy+noffs[a][1];
int nind = ny*ww+nx;
if(nind < 0 || nind >= count) continue;
if(gd->at(nind).alive) ncount++;
}
}
bool updateState() {
if(!alive && ncount != 3) return false;
if(ncount < 2 || ncount > 3) alive = false;
if(ncount == 3) alive = true;
return alive;
}
private:
Thing(int ind) {
init(ind);
}
void init(int ind) {
ncount = 0;
xx = ind%ww;
yy = (int)floor(ind/ww);
alive = rand()%100 < dens;
}
};
vector<Thing> grid;
int limit(int in, int mn, int mx) {
int ret;
ret = min(mx, in);
ret = max(mn, in);
return ret;
}
void update() {
for(int a=0; a<count; a++) {
grid.at(a).updateCount(&grid);
}
}
void display() {
for(int a=0; a<count; a++) {
if(a%ww==0) cout << endl;
cout << (grid.at(a).updateState()?"+":" ");
}
cout << endl;
}
void tick(int time, float start, float sleep, int frameCount) {
if(time < sleep) {
while((float)(clock()-start)/CLOCKS_PER_SEC < sleep) {}
cout << endl;
update();
display();
cout << endl << endl;
tick(0, (float)clock(), sleep, ++frameCount);
}
}
int main(int argc, char** argv) {
srand(time(NULL));
if(argc < 3) {
cout << "cgol # #" << endl;
return 0;
}
ww = atoi(argv[1]);
hh = atoi(argv[2]);
dens = argc>3?atoi(argv[3]):5;
ww = limit(ww, 5, 50);
hh = limit(hh, 5, 50);
dens = limit(dens, 5, 90);
count = ww*hh;
for(int a=0; a<count; a++) {
grid.push_back(Thing::createInstance(a));
}
tick(0, (float)clock(), .1, 0);
cout << endl;
}