# Finite-State Cellular Automata

Page 1 of 1

## 1 Replies - 4623 Views - Last Post: 08 October 2010 - 04:34 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=194022&amp;s=89d1e00590db0c3397cf677228e185e5&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 jvelasco

Reputation: 0
• Posts: 32
• Joined: 07-October 10

# Finite-State Cellular Automata

Posted 07 October 2010 - 10:23 PM

We are currently working with arrays in class and now I have a programming assignment where I need to model the Rule 30 cellular Automaton. My teacher gave us the basic skeleton file for this assignment but I am completely lost. I've been staring at this code for the past hours and haven't been able to do much. Could anybody explain to me in a more thorough way how to implement the program, or how to get started.

```#include <iostream>
#include <cstdlib>
using namespace std;

void setupRow();
void printRow();
void updateRow();
int findNextCellState(int left_neighbor, int cell, int right_neighbor);

const int WIDTH=80;
int row[WIDTH];

int main()
{
setupRow();
printRow();

for (int i = 0; i < 40; i++)
{
updateRow();
printRow();
}
}

// The setupRow function creates an initial state for the cellular autonoma
void setupRow()
{
int row[ WIDTH ] = {};
row[39]=1;

// IMPLEMENTATION GOES HERE

}

// The printRow function outputs the state of the row to the user.  For all
// cells that are 0, it outputs a space (" "), for all cells that are 1, it
// outputs a star ("*")
void printRow()
{
if ( int row=0)
{cout<< " " <<;}
else if ( int row=1)
{
cout<< "*" <<;
}// cout << " " << when x = 0
// cout << "*" << when x = 1
// IMPLEMENTATION GOES HERE
//
//
}

// The updateRow function updates the contents of the row after calculating
// the next states using the findNextCellState function
void updateRow()
{

}

// The findNextCellState function implements the Rule 30 celular autonoma rules.
// The states for this are:
//
// 111 110 101 100 011 010 001 000
//  0   0   0   1   1   1   1   0

int findNextCellState(int left_neighbor, int cell, int right_neighbor)
{
if (0 == cell)
{
if (1 == (left_neighbor + right_neighbor))
{
return 1;
}
else
{
return 0;
}
}
else
{
if (1 == left_neighbor)
{
return 0;
}
else
{
return 1;
}
}
}

```

Here are the instructions that we got.

* Use a global integer array of width 80 to represent the current state
* When the main starts, use a function to populate the array with all 0s, except for the middle (40th) element which should be set to 1
* Implement a method that will print the row to the screen. Whenever the state is a 0, output a space (" ") and whenever the state is a 1, output a star("*")
* Implement a method that will look at every element in the current array, determine the next state, and save it in to a new array. When the method is finished, copy all elements of the new array in to the global array.
* Run a loop in the main method which will update the state and print out the new state 40 times

I understand that this is MY homework and I am in no way expecting anybody to do it. I just need more of a technical explanation to get started.

Is This A Good Question/Topic? 0

## Replies To: Finite-State Cellular Automata

• Saucy!

Reputation: 6246
• Posts: 24,014
• Joined: 23-August 08

## Re: Finite-State Cellular Automata

Posted 08 October 2010 - 04:34 AM

I don't understand...you've been told EXACTLY what to do!? Maybe you need to read about arrays?

If you don't understand an assignment given to you by your teacher, then you need to go see the teacher and talk to them about it. Random strangers on the Internet are not a great substitute for your actual teacher.