Hi all, i need help to build up a cellular automata program.
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.
For example, an array is listed as following:
0123456
#. .+++
This is the rule:
- If both of the neighbouring cells have a state equal to the next state then the cell is
changed to the previous state. - If only one of the neighbouring cells has a state equal to the next state then the cell is
changed to the next state - If both neighbours have the same state as the cell then the cell is changed to the next
state - If neither rule 1, 2 or 3 applies then the cell remains unchanged.
So, after applying the rule, the example array will be :
0123456
#.#++##
I have write 2 .cs file : Cell.cs and program.cs, but there are some bugs in my job, so if anybody can help me to look through the code?
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace cell1
{
class Program
{
static void Main(string[] args)
{
string seed = Console.ReadLine();
int seed_R = Convert.ToInt32(seed);
Demo demo = new Demo();
demo.GenerateCell(seed_R);
Console.ReadLine();
}
}
public class Demo
{
private const int ARRAYSIZE = 64;
private const int GENERATION = 20;
private Cell[] Cells;
private Cell[] temp;
public void scramble()
{
Cells = new Cell[ARRAYSIZE];
for (int i = 0; i < ARRAYSIZE; i++)
{
Cells[i] = new Cell();
}
}
public void GenerateCell(int seed)
{
int rand;
Random r = new Random(seed);
for (int i = 0; i < ARRAYSIZE; i++)
{
rand = r.Next(4);
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;
}
Console.Write("gen " + " 1 ");
}
public void PrintCell()
{
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();
}
}
}
Cell.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace cell1
{
enum CellState
{
SPACE,
DOT,
PLUS,
HASH
}
class Cell
{
private CellState defaultCell;
public Cell()
{
defaultCell = CellState.SPACE;
}
public CellState DefaultCell
{
get { return defaultCell; }
set { defaultCell = value; }
}
/*
public void ChangeRule1
{
}
public void ChangeRule2
{
}
public void ChangeRule3
{
}
public void ChangeRule4
{
}
*/
}
}