467,166 Members | 1,043 Online

# Cave generation using cellular automata unexpected results

 So I've been implementing a cave generating algorithm for a game that I'm working on. I'm using a cellular automaton for this algorithm but I've been facing some problems, it doesn't seem to be working properly. About the cellular automaton I'm using the following rule i found on a website: Clouds 1 rule: 13-26/13-14,17-19/2/M Alive cells with 13,14,15,16,17,18,19,20,21,22,23,24,25 or 26 neighbors survive. Empty cells with 13,14,17,18 or 19 neighbors have a new cell born at that location. 2 states. Cells are either dead or alive. No refractory period they fade from birth to death. M means a Moore neighborhood. About Moore neighborhood : consider a 3x3x3 3D grid of little cubes. The interior cube is the current cell, so the remaining 26 cubes around it are the neighbors of the center cube. Is there anything that I'm doing wrong? It's not giving me the expected results. And by the way here is the code i used to generate the caves : Expand|Select|Wrap|Line Numbers int cellular_iterations = 50;   srand((ax * CX) + (ay * CY) + (az * CZ)); for (int x = 0; x < CX+2; x++)     for (int y = 0; y < CY+2; y++)         for (int z = 0; z < CZ+2; z++)         {             float rd = (float)rand() / (float)RAND_MAX;             if (rd > 0.5f)  cellules[x][y][z] = 1;             else    cellules[x][y][z] = 0;               if (ay == (-SCY/2)) cellules[x][y][z] = 1;         }   std::vector>> cellules_(CX + 2, std::vector>(CY + 2, std::vector(CZ + 2, -1))); for (int i = 0; i < cellular_iterations; i++) {     for (int x = 1; x < CX+1; x++)         for (int y = 1; y < CY+1; y++)             for (int z = 1; z < CZ+1; z++)             {                 bool isalive = false;                 int alive_blocks = 0;                 for (int x_ = -1; x_ < 2; x_++)                     for (int y_ = -1; y_ < 2; y_++)                         for (int z_ = -1; z_ < 2; z_++)                         {                             if (!(x_ == 0 && y_ == 0 && z_ == 0))                             {                                 alive_blocks += (cellules[x+x_][y+y_][z+z_] == 1) ? 1 : 0;                             }                             else                             {                                 if(cellules[x + x_][y + y_][z + z_] == 1)   isalive = true;                             }                         }                 if (isalive && alive_blocks >= 13)                 {                     cellules_[x][y][z] = 1;                 }                 else if (!isalive && ((13 <= alive_blocks && alive_blocks <= 14) || (17 <= alive_blocks && alive_blocks <= 19)))                 {                     cellules_[x][y][z] = 1;                 }                 else                 {                     cellules_[x][y][z] = 0;                 }             }     for (int x = 0; x < CX + 2; x++)         for (int y = 0; y < CY + 2; y++)             for (int z = 0; z < CZ + 2; z++)             {                 cellules[x][y][z] = cellules_[x][y][z];                 if (ay == (-SCY/2)) cellules[x][y][z] = 1;             } }   Dec 18 '20 #1
• viewed: 1024
Share:
 2 posts views Thread by CK | last post: by 6 posts views Thread by Cro | last post: by 10 posts views Thread by Sean | last post: by 7 posts views Thread by defcon8@gmail.com | last post: by 5 posts views Thread by defcon8 | last post: by 4 posts views Thread by onkar | last post: by 2 posts views Thread by Martijn Mulder | last post: by 13 posts views Thread by bintom | last post: by 6 posts views Thread by HypeBeast McStreetwear | last post: by 1 post views Thread by newphpcoder | last post: by 6 posts views Thread by Otekpo Emmanuel | last post: by reply views Thread by SwissProgrammer | last post: by reply views Thread by SwissProgrammer | last post: by 1 post views Thread by SwissProgrammer | last post: by 2 posts views Thread by SwissProgrammer | last post: by reply views Thread by isladogs | last post: by reply views Thread by jobsrod | last post: by reply views Thread by nearlyhub | last post: by 1 post views Thread by MinkiChung | last post: by