473,320 Members | 2,027 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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
  1. int cellular_iterations = 50;
  2.  
  3. srand((ax * CX) + (ay * CY) + (az * CZ));
  4. for (int x = 0; x < CX+2; x++)
  5.     for (int y = 0; y < CY+2; y++)
  6.         for (int z = 0; z < CZ+2; z++)
  7.         {
  8.             float rd = (float)rand() / (float)RAND_MAX;
  9.             if (rd > 0.5f)  cellules[x][y][z] = 1;
  10.             else    cellules[x][y][z] = 0;
  11.  
  12.             if (ay == (-SCY/2)) cellules[x][y][z] = 1;
  13.         }
  14.  
  15. std::vector<std::vector<std::vector<int>>> cellules_(CX + 2, std::vector<std::vector<int>>(CY + 2, std::vector<int>(CZ + 2, -1)));
  16. for (int i = 0; i < cellular_iterations; i++)
  17. {
  18.     for (int x = 1; x < CX+1; x++)
  19.         for (int y = 1; y < CY+1; y++)
  20.             for (int z = 1; z < CZ+1; z++)
  21.             {
  22.                 bool isalive = false;
  23.                 int alive_blocks = 0;
  24.                 for (int x_ = -1; x_ < 2; x_++)
  25.                     for (int y_ = -1; y_ < 2; y_++)
  26.                         for (int z_ = -1; z_ < 2; z_++)
  27.                         {
  28.                             if (!(x_ == 0 && y_ == 0 && z_ == 0))
  29.                             {
  30.                                 alive_blocks += (cellules[x+x_][y+y_][z+z_] == 1) ? 1 : 0;
  31.                             }
  32.                             else
  33.                             {
  34.                                 if(cellules[x + x_][y + y_][z + z_] == 1)   isalive = true;
  35.                             }
  36.                         }
  37.                 if (isalive && alive_blocks >= 13)
  38.                 {
  39.                     cellules_[x][y][z] = 1;
  40.                 }
  41.                 else if (!isalive && ((13 <= alive_blocks && alive_blocks <= 14) || (17 <= alive_blocks && alive_blocks <= 19)))
  42.                 {
  43.                     cellules_[x][y][z] = 1;
  44.                 }
  45.                 else
  46.                 {
  47.                     cellules_[x][y][z] = 0;
  48.                 }
  49.             }
  50.     for (int x = 0; x < CX + 2; x++)
  51.         for (int y = 0; y < CY + 2; y++)
  52.             for (int z = 0; z < CZ + 2; z++)
  53.             {
  54.                 cellules[x][y][z] = cellules_[x][y][z];
  55.                 if (ay == (-SCY/2)) cellules[x][y][z] = 1;
  56.             }
  57. }
  58.  
Dec 18 '20 #1
1 1444
Rabbit
12,516 Expert Mod 8TB
You need to create the next generation into a new array. Right now, you're using the state of cellules to update itself, changing its state.
Dec 18 '20 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: CK | last post by:
I am a "newbie" to python and today I had the need to write a program which generated a lot of tcp connections to a range of addresses (10.34.32.0/22) in order to troubleshoot a problem with a...
6
by: Cro | last post by:
Dear Access Developers, The 'Allow Additions' property of my form is causing unexpected results. I am developing a form that has its 'Default View' property set to 'Continuous Forms' and am...
10
by: Sean | last post by:
I have a struct that I wrote to test a protocol. The idea I had was to just declare the elements of the struct in the order in which they are sent and received as defined by the protocol. ...
7
by: defcon8 | last post by:
Hello. I have recently been experimenting with cellular automata and I would like to know how I could convert a 2d list of 0's and 1's into white and black squares on an image. I have tried to...
5
by: defcon8 | last post by:
I thought people would be interested in this little script I wrote to reproduce the 256 simple automata that is shown in the first chapters of "A New Kind of Science". You can see a few results...
4
by: onkar | last post by:
Can any one suggest me a game which uses FA as central concept and to be written in C.
2
by: Martijn Mulder | last post by:
/* GraphicsPath.IsVisible() gives unexpected results. I fill a System.Drawing.Drawing2D.GraphicsPath-object with PointF-structures that define the unit-square (0,0), (1,0), (1,1) and (0,1). Then I...
13
by: bintom | last post by:
I ran the following simple code in C++ and got unexpected results: float f = 139.4; cout << f; Output: 139.399994;
6
by: HypeBeast McStreetwear | last post by:
Hi, I've been doin a project for my C++ class pertaining to Cellular Automata. I'm having a little trouble so before I start I'll give you guys all the details so what I know, you'll know. ...
1
by: newphpcoder | last post by:
Good day! I upgrade my version of mysql from mysql 4.1.10 to mysql 5.0.15. Now I used phpmyadmin to access my database using XAMPP. Now, I need to create a report generation and I have no idea how I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.