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

Edited 7 Years Ago by wewehalim: n/a

Let's say it's a table (columns -cells- and rows)

public class MyTable()
{
Public MyTable(int columnsNumber, int rowsNumber)
{
Table = new object[rowsNumber, columnsNumber];
}
public object[,] Table; 
}

Then you can apply your logic

MyTable bla = new MyTable(20, 64);
//bla.Table[0,0]; 
//if bla.Table[0,0] > bla.Table[0,1] 
//then bla.Table[1,0] = anything....

Got it?

hm i got it, so i need to use 2 arrays like table (row and col).
I have tried this once yesterday, but the cell still be compared with the cell that already changed. Strange!! let me check it once more.

Yes because you are working with arrays and array is reference type and passed to any method as reference without prefix it with 'ref' so you can declare more than instance of object[,] and assign them to your bla.Table;

object [,] tempTable = bla.Table;
//....doing some operations
//at this point you don't need on of them you can reassign it again and work..
tempTable = bla.Table;
This article has been dead for over six months. Start a new discussion instead.