Example #1
0
        public override bool Equals(object obj)
        {
            LifeGrid source = obj as LifeGrid;

            if (source == null)
            {
                return(false);
            }

            if (this == source)
            {
                return(true);
            }

            if (source.fGridWidth != fGridWidth || source.fGridHeight != fGridHeight)
            {
                return(false);
            }
            else
            {
                short[] sourceGrid = source.fGrid;
                for (int i = 0; i < fGridHeight * fGridWidth; i++)
                {
                    if (fGrid[i] != sourceGrid[i])
                    {
                        return(false);
                    }
                }

                return(true);
            }
        }
Example #2
0
        protected bool DoesCellLive(int X, int Y, LifeGrid grid)
        {
            bool result = grid.DoesCellLive(X, Y);

            if (fOnDoesCellLive != null)
            {
                fOnDoesCellLive(this, X, Y, grid, ref result);
            }
            return(result);
        }
Example #3
0
        public LifeViewer()
        {
            DoubleBuffered = true;

            fOptions       = new LifeOptions();
            fRules         = new LifeRules();
            fGrid          = new LifeGrid(LifeConsts.DefaultGridWidth, LifeConsts.DefaultGridHeight);
            fHistory       = new LifeHistory(LifeConsts.DefaultNumberOfHistoryLevels);
            fGridLineColor = LifeConsts.DefaultGridLineColor;
            fGridLineStyle = LifeConsts.DefaultGridLineStyle;
        }
        public LifeViewer()
        {
            this.DoubleBuffered = true;

            this.fOptions = new LifeOptions();
            this.fRules = new LifeRules();
            this.fGrid = new LifeGrid(LifeConsts.DefaultGridWidth, LifeConsts.DefaultGridHeight);
            this.fHistory = new LifeHistory(LifeConsts.DefaultNumberOfHistoryLevels);
            this.fGridLineColor = LifeConsts.DefaultGridLineColor;
            this.fGridLineStyle = LifeConsts.DefaultGridLineStyle;
        }
        public LifeGrid Add(LifeGrid grid)
        {
            if (this.fList.Count < this.fList.Capacity) {
                this.fList.Add(new LifeGrid());
                this.fMostRecent = this.fList.Count - 1;
            } else {
                this.fMostRecent = (this.fMostRecent + 1) % Count;
            }

            LifeGrid result = this.fList[this.fMostRecent];
            result.Assign(grid);
            return result;
        }
Example #6
0
        public int Contains(LifeGrid grid)
        {
            int result = 0;

            while ((result < fList.Count) && !grid.Equals(this[result]))
            {
                result++;
            }
            if (result >= fList.Count)
            {
                result = -1;
            }

            return(result);
        }
Example #7
0
        public LifeGrid Add(LifeGrid grid)
        {
            if (fList.Count < fList.Capacity)
            {
                fList.Add(new LifeGrid());
                fMostRecent = fList.Count - 1;
            }
            else
            {
                fMostRecent = (fMostRecent + 1) % Count;
            }

            LifeGrid result = fList[fMostRecent];

            result.Assign(grid);
            return(result);
        }
Example #8
0
        public int NextGeneration()
        {
            LifeGrid MostRecentGrid = fHistory.Add(fGrid);

            for (int y = 0; y < GridHeight; y++)
            {
                for (int x = 0; x < GridWidth; x++)
                {
                    bool live = DoesCellLive(x, y, MostRecentGrid);
                    SetCell(x, y, (short)((live) ? 1 : 0));
                }
            }

            fGeneration++;
            Change();

            int result = fHistory.Contains(fGrid) + 1;

            return(result);
        }
Example #9
0
 public void Assign(LifeGrid source)
 {
     this.SetGridSize(source.fGridWidth, source.fGridHeight);
     Array.Copy(source.fGrid, this.fGrid, fGridWidth * fGridHeight);
 }
Example #10
0
 public void Assign(LifeGrid source)
 {
     SetGridSize(source.fGridWidth, source.fGridHeight);
     Array.Copy(source.fGrid, fGrid, fGridWidth * fGridHeight);
 }
        public int Contains(LifeGrid grid)
        {
            int result = 0;
            while ((result < this.fList.Count) && !grid.Equals(this[result])) result++;
            if (result >= this.fList.Count) result = -1;

            return result;
        }
 private void cmpLifeDoesCellLive(int X, int Y, LifeGrid grid, ref bool result)
 {
     if (grid[X, Y] > 0) {
         result = this.fRules.GetLiveCells(grid.NumberOfNeighbours(X, Y));
     } else {
         result = this.fRules.GetDeadCells(grid.NumberOfNeighbours(X, Y));
     }
 }
 protected bool DoesCellLive(int X, int Y, LifeGrid grid)
 {
     bool result = grid.DoesCellLive(X, Y);
     if (fOnDoesCellLive != null) fOnDoesCellLive(this, X, Y, grid, ref result);
     return result;
 }