#include <NeoPixelBus.h>
#define colorSaturation 10

const int dtime=500;
const int fillp=750;

// make sure to set these panel values to the sizes of yours
const uint8_t PanelWidth = 8;  // 8 pixel x 8 pixel matrix of leds
const uint8_t PanelHeight = 8;
const uint8_t TileWidth = 3;  // laid out in 3 panels x 2 panels mosaic
const uint8_t TileHeight = 2;
const uint16_t PixelCount = PanelWidth * PanelHeight * TileWidth * TileHeight;
const uint16_t width=TileWidth*PanelWidth;
const uint16_t height=TileHeight*PanelHeight;


uint16_t countX=0;
uint16_t countY=0;

NeoPixelBus<NeoGrbFeature, NeoEsp8266Uart1Ws2812xMethod> strip(PixelCount, D4);

typedef ColumnMajorAlternatingLayout MyPanelLayout;
typedef RowMajorAlternatingLayout MyTilesLayout;
NeoTiles <MyPanelLayout, MyTilesLayout> tiles(PanelWidth, PanelHeight, TileWidth, TileHeight);

RgbColor red(colorSaturation, 0, 0);
RgbColor green(0, colorSaturation, 0);
RgbColor blue(0, 0, colorSaturation);
RgbColor black(0);

uint8_t  current[height][width];
uint8_t     next[height][width];
RgbColor rgbNext[height][width];

void setup() {
  Serial.begin(115200);

  // Make sure our two arrays are empty
  for(int n=0;n<height;n++) {
    for(int m=0;m<width;m++) {
      current[n][m]=0;
      next[n][m]=0;
    }
  }

  strip.Begin();
  initGOL();
  displayGOL()
}

void initGOL() {
  int r;
  for(int n=0;n<height;n++) {
    for(int m=0;m<width;m++) {
      r=random(1000);
      if(r<fillp) {
        rgbNext[n][m][0]=random(colorSaturation);
        rgbNext[n][m][1]=random(colorSaturation);
        rgbNext[n][m][2]=random(colorSaturation);
        current[n][m]=1;
      } else {
        rgbNext[n][m][0]=0;
        rgbNext[n][m][1]=0;
        rgbNext[n][m][2]=0;
        current[n][m]=0;
      }
    }
  }
  Serial.println("init done");
}

void updateGOL() {

}

uint8_t countNeighbours(uint8_t x, uint8_t y) {

  uint8_t count=0;

  if(y>0current 

}

void displayGOL() {
  strip.ClearTo(black);
  for(int n=0;n<height;n++) {
    for(int m=0;m<width;m++) {
      strip.SetPixelColor(tiles.Map(m,n), rgbNext[n][m]);
    }
  }
  strip.Show();
  Serial.println("show done");
}

void loop() {
  delay(dtime);
  updateGOL();
  displayGOL();
  // strip.SetPixelColor(tiles.Map(countX,countY), red);
  // strip.Show();
  Serial.println("Next loop");
}