Ejemplo n.º 1
0
        public World(int initWidth, int initHeight)
        {
            height = initHeight;
            width = initWidth;

            for (int r = 0; r < initWidth; r++)
            {
                for ( int c = 0; c < initHeight; c++)
                    cells[c,r] = new Cell(this,c,r);
            }
        }
Ejemplo n.º 2
0
        private int[] GenerateGene(Cell[] surroundingCells)
        {
            int[] generatedGene = new int[256];
            double genesPerCell = 256/surroundingCells.Count();

            /*for (int i = 0; i < 256; i++)
            {
                int whichSurroundingCell = Convert.ToInt32(Math.Floor(i/genesPerCell));
                Cell surroundingCell = surroundingCells[whichSurroundingCell];

                generatedGene[i] = surroundingCell.Gene(rand.Next(255));
            }*/

            for (int i = 0; i < 256; i++)
            {
                if (rand.Next(100) < 50)
                    generatedGene[i] = surroundingCells[Convert.ToInt32(Math.Floor(i / genesPerCell))].Gene(rand.Next(255));
                else
                    generatedGene[i] = colorGene[i];
            }

            return generatedGene;
        }
Ejemplo n.º 3
0
        public Cell[] GetSurroundingCells(int x, int y)
        {
            int index = 0;
            Cell[] surroundingCells = new Cell[8];

            for (int c = -1 ; c < 2; c++)
                for (int r = -1; r < 2; r++)
                {
                    if ((x + c >= 0) && (x + c < Window.WIDTH) && (y + r >= 0) && (y + r < Window.WIDTH) && (x + c != x) && (y + r != y))
                    {
                        surroundingCells[index] = cells[x+c, y+r];
                        index++;
                    }
                }

            Cell[] surroundingCellsClean = new Cell[index];

            for (int i = 0; i < index; i++)
            {
                surroundingCellsClean[i] = surroundingCells[i];
            }
            return surroundingCellsClean;
        }