Пример #1
0
        // Draw the current generation.
        internal void DrawGeneration(
            LifeGeneration genCurr,
            LifeGeneration genPrev,
            Graphics graphLifeGame)
        {
            // Calculate the range of rows to display.
            int displayLo =
                genCurr.middle - ((LifeMain.noofDisplay - 1) / 2);
            int displayHi =
                displayLo + (LifeMain.noofDisplay - 1);

            // For each of those rows.
            for (int j = displayLo; j <= displayHi; j++)
            {
                // Only draw the row if necessary.
                if (LifeMain.boolPaintAll == true ||
                    genCurr.countGeneration <= 1 ||
                    genCurr.Rows[j].CompareTo(genPrev.Rows[j])
                    != 0)
                {
                    this.DrawRow(genCurr.Rows[j],
                                 genPrev.Rows[j],
                                 j,
                                 graphLifeGame);
                }
            }
        }
Пример #2
0
 internal void CopyTo(LifeGeneration genTarget)
 {
     //	Copy the relevant info from gen to gen.
     for (int j = lo; j <= hi; j++)
     {
         this.Rows[j].CopyTo(genTarget.Rows[j]);
     }
     genTarget.countGeneration = this.countGeneration;
 }
Пример #3
0
        internal int CompareTo(LifeGeneration genTarget)
        {
            //	CompareTo tradionally returns three
            //		possible values, 0 (==), -1 (<)
            //		and +1 (>); and we wish to
            //		maintain that convention.  But,
            //		for a generation, only "=="
            //		and "!=" is meaningful.  So the
            //		definition of "<" and ">" is somewhat
            //		arbitrary here.

            if (genTarget == null)
            {
                return(1);
            }

            if (this.noofLive == 0 && genTarget.noofLive == 0)
            {
                return(0);
            }

            if (this.noofLive < genTarget.noofLive)
            {
                return(-1);
            }
            if (this.noofLive > genTarget.noofLive)
            {
                return(1);
            }

            for (int j = lo; j <= hi; j++)
            {
                if (Rows[j].CompareTo(genTarget.Rows[j]) == 0)
                {
                    continue;
                }
                if (Rows[j].CompareTo(genTarget.Rows[j]) < 0)
                {
                    return(-1);
                }
                if (Rows[j].CompareTo(genTarget.Rows[j]) > 0)
                {
                    return(+1);
                }
            }
            return(0);
        }
Пример #4
0
        public void CalcNextGen()
        {
            //	Have the current generation calculate
            //		the next generation.
            genNext = genCurr.CalcNextGen();

            //	Check to see if a static state has been
            //		has been reached.
            if (genNext.countGeneration >= 4 && genNext.CompareTo(genFour) == 0)
            {
                OnStableStateReached();
            }

            //	Age the generations
            genFour  = genGrand;
            genGrand = genPrev;
            genPrev  = genCurr;
            genCurr  = genNext;
        }
Пример #5
0
        internal LifeGeneration CalcNextGen()
        {
            //	Each row is used to calculate its next
            //		generation.
            //	The target row, the row above, and the
            //		row below must be examined to determine
            //		the target row's next generation.
            //	The outermost border of cells is always
            //		left blank.
            LifeGeneration genNext = new LifeGeneration();

            genNext.countGeneration = this.countGeneration + 1;

            genNext.Rows[lo] = new LifeRow();
            for (int j = lo + 1; j <= hi - 1; j++)
            {
                genNext.Rows[j] =
                    Rows[j].CalcNextGen(Rows[j - 1], Rows[j + 1]);
            }
            genNext.Rows[hi] = new LifeRow();

            return(genNext);
        }