예제 #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);
            }
        }
예제 #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);
        }
예제 #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;
        }
예제 #4
0
        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;
        }
예제 #5
0
        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;
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #9
0
 public void Assign(LifeGrid source)
 {
     this.SetGridSize(source.fGridWidth, source.fGridHeight);
     Array.Copy(source.fGrid, this.fGrid, fGridWidth * fGridHeight);
 }
예제 #10
0
 public void Assign(LifeGrid source)
 {
     SetGridSize(source.fGridWidth, source.fGridHeight);
     Array.Copy(source.fGrid, fGrid, fGridWidth * fGridHeight);
 }
예제 #11
0
        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;
        }
예제 #12
0
 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));
     }
 }
예제 #13
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;
 }