i am developing 64 cell(column) for 20 rows of automata.
I need to compare each cell (in a row) with the left and right cell.
And then, after i finish 1 row, i need to do it for the next row.
So, for example, after i have compared each cell in row 1, then row 2 will be the output.
row 2 is the result of row 1, row 3 is the result of row 3, and etc.
the problem is, for example in row 1, when i compared each cell FROM left to right, the cell will be compared to the left cell that has been changed to row 2. But i want the cell to be always compared to the original cell..
So it thought of using temporary array. But i don't know how to do so.
Can someone help me?
This is the main code that i write, i will not include my class.
namespace coba2
{
class scramble
{
private const int CELLSIZE = 20;
private const int GENERATION = 20;
private Cell[] Cells;
public scramble()
{
Cells = new Cell[CELLSIZE];
for (int i = 0; i < CELLSIZE; 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 < CELLSIZE; 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 < CELLSIZE; 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 j = 0; j < GENERATION - 1; j++)
{
for (int i = 0; i < CELLSIZE; i++)
{
if (Cells[i].DefaultCell == Cells[i + 1].DefaultCell && Cells[i].DefaultCell == Cells[i - 1].DefaultCell)
{
Cells[i].ChangeState();
}
}
PrintCell();
}
}
}
}
i know it a bit messy. operation1 is the rules that i pllied to each cell.
Cells.ChangeState is the method to change each cell to the next state. I think this Cell.ChangeState() needs to be changed to temporary array. So all of the result will be stored in temp first. So i can compare each cell with original array.
Thanks