コード例 #1
0
ファイル: Population.cs プロジェクト: FryDay/CellSharp
 public Population(Population existingPopulation)
 {
     CellList = new List<Cell>();
     Rules = existingPopulation.Rules;
     foreach (Cell thisCell in existingPopulation.CellList)
         CellList.Add(new Cell(thisCell));
 }
コード例 #2
0
ファイル: Main.cs プロジェクト: FryDay/CellSharp
 public Main(int birthMin, int birthMax, int survivalMin, int survivalMax, int maxIterations, Population pop)
 {
     Rules = new Ruleset(birthMin, birthMax, survivalMin, survivalMax);
     LivingCells = pop;
     CurrentIteration = 0;
     MaxIterations = maxIterations;
 }
コード例 #3
0
ファイル: Form1.cs プロジェクト: FryDay/CellSharp
        //Draw cells
        private void DrawCells(Population livingCells)
        {
            foreach (Cell cell in livingCells.CellList)
                Gpx.FillRectangle(CellBrush, (cell.XPos * CellSize), (cell.YPos * CellSize), CellSize, CellSize);

            pix_Grid.Refresh();
        }
コード例 #4
0
ファイル: Population.cs プロジェクト: FryDay/CellSharp
        public void CheckForDuplicates()
        {
            Population tempPop = new Population(this);

            foreach (Cell thisCell in tempPop.CellList)
            {
                if (thisCell.CheckNumberDuplicates(tempPop.CellList) > 1)
                {
                    this.RemoveCell(thisCell);
                    tempPop.Nullify(thisCell);
                }
            }
        }
コード例 #5
0
ファイル: Main.cs プロジェクト: FryDay/CellSharp
        //True = keep iterating, False = stop iterating
        public bool Iterate()
        {
            LivingCells = new Population(LivingCells.Run(Rules));
            LivingCells.CheckForDuplicates();
            LivingCells.UpdateCellCount();
            UpdateGridEvent(this, EventArgs.Empty);
            CurrentIteration++;

            if (CurrentIteration >= MaxIterations && MaxIterations != 0)
            {
                CurrentIteration = 0;
                return false;
            }
            else
                return true;
        }
コード例 #6
0
ファイル: Population.cs プロジェクト: FryDay/CellSharp
        public Population Run(Ruleset rules)
        {
            Population tempPop = new Population(this);

            for (int index = 0; index < CellList.Count; index++)
            {
                if (!Survive(CellList[index], rules))
                    tempPop.RemoveCell(CellList[index]);
            }

            tempPop.UpdateCellCount();

            Reproduction(tempPop);

            return tempPop;
        }
コード例 #7
0
ファイル: Main.cs プロジェクト: FryDay/CellSharp
 public Main(int birthMin, int birthMax, int survivalMin, int survivalMax, int maxIterations)
 {
     Rules = new Ruleset(birthMin, birthMax, survivalMin, survivalMax);
     LivingCells = new Population(Rules);
     CurrentIteration = 0;
 }
コード例 #8
0
ファイル: Population.cs プロジェクト: FryDay/CellSharp
        private bool CheckReproduction(Population currentPop, Cell thisCell)
        {
            thisCell.CountNeighbors(currentPop.CellList);

            if (thisCell.NeighborCount >= Rules.BirthMinimum && thisCell.NeighborCount <= Rules.BirthMaximum)
                return true;

            return false;
        }
コード例 #9
0
ファイル: Population.cs プロジェクト: FryDay/CellSharp
 private void Reproduction(Population tempPopulation)
 {
     foreach (Cell thisCell in this.CellList)
         tempPopulation.CellList.AddRange(tempPopulation.MakeNewCells(this, thisCell).CellList);
 }
コード例 #10
0
ファイル: Population.cs プロジェクト: FryDay/CellSharp
        private Population MakeNewCells(Population currentPop, Cell thisCell)
        {
            Population spawn = new Population(this.Rules);

            for (int x = -1; x <= 1; x++)
            {
                for (int y = -1; y <= 1; y++)
                {
                    if (CheckReproduction(currentPop, new Cell(thisCell.XPos + x, thisCell.YPos + y)))
                        spawn.AddCell(new Cell(thisCell.XPos + x, thisCell.YPos + y));
                }
            }

            return spawn;
        }