nextCell :: Generation -> Int -> Int -> Int
nextCell gen@(Generation _ _ _ _ brd) !idx !state
  | nc < 2 || nc > 3 = 0
  | nc == 3 = 1
  | otherwise = state
  where
    (!x, !y) = getCoords gen idx
    {-
    -- this way it creates a huge allocation rate
    nc = L.sum [ gn neg neg, gn zro neg, gn pos neg
               , gn neg zro, 0         , gn pos zro
               , gn neg pos, gn zro pos, gn pos pos]
    -}
    !nc = gn neg neg + gn zro neg + gn pos neg
        + gn neg zro + gn zro zro + gn pos zro
        + gn neg pos + gn zro pos + gn pos pos
    gn !mx !my
      | midx < 0 = 0
      | midx >= U.length brd = 0
      | otherwise  = brd U.! midx
      where
        !midx = fromCoords gen (x + mx, y + my)
    !neg = -1
    !pos = 1
    !zro = 0
nextCell :: Generation -> Int -> Int -> Int
nextCell gen@(Generation _ _ _ _ brd) !idx !state
  | nc < 2 || nc > 3 = 0
  | nc == 3 = 1
  | otherwise = state
  where
    (!x, !y) = getCoords gen idx
    {-
    -- this way it creates a huge allocation rate
    nc = L.sum [ gn neg neg, gn zro neg, gn pos neg
               , gn neg zro, 0         , gn pos zro
               , gn neg pos, gn zro pos, gn pos pos]
    -}
    !nc = gn neg neg + gn zro neg + gn pos neg
        + gn neg zro + gn zro zro + gn pos zro
        + gn neg pos + gn zro pos + gn pos pos
    gn !mx !my
      | midx < 0 = 0
      | midx >= U.length brd = 0
      | otherwise  = brd U.! midx
      where
        !midx = fromCoords gen (x + mx, y + my)
    !neg = -1
    !pos = 1
    !zro = 0
nextCell gen@(Generation _ _ _ _ brd) !idx !state
  | nc < 2 || nc > 3 = 0
  | nc == 3 = 1
  | otherwise = state
  where
    (!x, !y) = getCoords gen idx
    {-
    -- this way it creates a huge allocation rate
    nc = L.sum [ gn neg neg, gn zro neg, gn pos neg
               , gn neg zro, 0         , gn pos zro
               , gn neg pos, gn zro pos, gn pos pos]
    -}
    !nc = gn neg neg + gn zro neg + gn pos neg
        + gn neg zro + gn zro zro + gn pos zro
        + gn neg pos + gn zro pos + gn pos pos
    gn !mx !my
      | midx < 0 = 0
      | midx >= U.length brd = 0
      | otherwise  = brd U.! midx
      where
        !midx = fromCoords gen (x + mx, y + my)
    !neg = -1
    !pos = 1
    !zro = 0