Hi, i need help in building a program about automata cellular.
So, there is 4 state of cells, 0 = space, 1 = ".", 2 = "+", 3 = "#"
This state is continuous from 0 - 3, after 3, it will be back to 0.
we need to compare each cell to the cell on their left and right.
So for example, i already generate random number and representated as this cells..
012345
#. +
This is the rules, if either one of the neighbouring cells has a state equal to the next state of the cell, then the cell is changed to the next state.
So, in the example, the result will be.
012345
#.. #
So this rules is applied to cell 2 and 5
i have dificulties in finding the right algorithm.
namespace coba2
{
class scramble
{
private const int ARRAYSIZE = 20;
private Cell[] Cells;
public scramble()
{
Cells = new Cell[ARRAYSIZE];
for (int i = 0; i < ARRAYSIZE; i++)
{
Cells[i] = new Cell();
}
}
/// <summary>
/// Generates random number and assign the symbol to each number
/// </summary>
public void scrambles(int seed)
{
int rand;
// set up random object and initialise with seed
Random r = new Random(seed);
for (int i = 0; i < ARRAYSIZE; i++)
{
rand = r.Next(4);
//Console.Write("{0}", Cells[i]);
// applying symbol to generated number
if (rand == 0) Cells[i].DefaultCell = CellState.SPACE;
else if (rand == 1) Cells[i].DefaultCell = CellState.DOT;
else if (rand == 2) Cells[i].DefaultCell = CellState.PLUS;
else Cells[i].DefaultCell = CellState.HASH;
}
}
/// <summary>
/// Print out the cells using symbol
/// </summary>
public void PrintCell()
{
// print the cells in the row
for (int i = 0; i < ARRAYSIZE; i++)
{
if (Cells[i].DefaultCell == CellState.SPACE)
Console.Write(" ");
else if (Cells[i].DefaultCell == CellState.DOT)
Console.Write(".");
else if (Cells[i].DefaultCell == CellState.PLUS)
Console.Write("+");
else
Console.Write("#");
}
Console.WriteLine();
}
public void operation1()
{
for (int i = 0; i < 19; i++)
{
else if (Cells[i].DefaultCell == Cells[i + 1].DefaultCell && Cells[i].DefaultCell == Cells[i - 1].DefaultCell)
{
Cells[i].ChangeState();
}
PrintCell();
}
}
}
the void operation1 didn't work well, i want to put the algorithm here..
i already have another class that apply the ChangeState() to change the cell state to the next state..
can anyone help me? thanks