Exemplo n.º 1
0
        //Any live cell with two or three live neighbours lives on to the next generation.
        public void testRule2()
        {
            //test with 2 live neighbors
            StandardLife test = new StandardLife(3);
            test.GetCell(0, 0).IsAlive = false;
            test.GetCell(0, 1).IsAlive = false;
            test.GetCell(0, 2).IsAlive = false;
            test.GetCell(1, 0).IsAlive = true;
            test.GetCell(1, 1).IsAlive = true;
            test.GetCell(1, 2).IsAlive = true;
            test.GetCell(2, 0).IsAlive = false;
            test.GetCell(2, 1).IsAlive = false;
            test.GetCell(2, 2).IsAlive = false;

            test.Iterate();
            Console.WriteLine(test);

            Assert.IsFalse(test.GetCell(0, 0).IsAlive);
            Assert.IsTrue(test.GetCell(0, 1).IsAlive);
            Assert.IsFalse(test.GetCell(0, 2).IsAlive);
            Assert.IsFalse(test.GetCell(1, 0).IsAlive);
            Assert.IsTrue(test.GetCell(1, 1).IsAlive);
            Assert.IsFalse(test.GetCell(1, 2).IsAlive);
            Assert.IsFalse(test.GetCell(2, 0).IsAlive);
            Assert.IsTrue(test.GetCell(2, 1).IsAlive);
            Assert.IsFalse(test.GetCell(2, 2).IsAlive);


        }
Exemplo n.º 2
0
        //Any live cell with fewer than two live neighbours dies, as if caused by under-population.
        public void testRule1_oneNeighbor()
        {
            //test with exactly one live neighbor each
            StandardLife test = new StandardLife(2);
            test.GetCell(0, 0).IsAlive = true;
            test.GetCell(0, 1).IsAlive = true;
            test.GetCell(1, 0).IsAlive = false;
            test.GetCell(1, 1).IsAlive = false;
            test.Iterate();

            Assert.IsFalse(test.GetCell(0,0).IsAlive);
            Assert.IsFalse(test.GetCell(0, 1).IsAlive);
            Assert.IsFalse(test.GetCell(1, 0).IsAlive);
            Assert.IsFalse(test.GetCell(1 ,1).IsAlive);

        }
Exemplo n.º 3
0
        public void testRule1_noNeighbors()
        {

            //test with no live neighbors
            StandardLife test2 = new StandardLife(2);
            test2.GetCell(0, 0).IsAlive = true;
            test2.GetCell(0, 1).IsAlive = false;
            test2.GetCell(1, 0).IsAlive = false;
            test2.GetCell(1, 1).IsAlive = false;
            test2.Iterate();

            Assert.IsFalse(test2.GetCell(0, 0).IsAlive);
            Assert.IsFalse(test2.GetCell(0, 1).IsAlive);
            Assert.IsFalse(test2.GetCell(1, 0).IsAlive);
            Assert.IsFalse(test2.GetCell(1, 1).IsAlive);


        }
Exemplo n.º 4
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            _lifeMatrices = new ObservableCollection<LifeMatrix>();
            LifeMatrix matrix1 = new StandardLife(20);
            matrix1.Randomize();
            _lifeMatrices.Add(matrix1);
            LifeMatrix matrix2 = new RedBlueLife(20);
            _lifeMatrices.Add(matrix2);
            matrix2.Randomize();
            LifeMatrix matrix3 = new GeneticLife(20);
            matrix3.Randomize();
            _lifeMatrices.Add(matrix3);

            activeLifeMatrix = matrix2;
            typesBox.DataContext = _lifeMatrices;

            matrix.RowDefinitions.Clear();

            for (int rowIndex = 0; rowIndex < activeLifeMatrix.Size; rowIndex++)
            {
                RowDefinition rowDef = new RowDefinition();
                rowDef.Height = new GridLength((int)(matrix.ActualHeight / activeLifeMatrix.Size));
                matrix.RowDefinitions.Add(rowDef);
            }
            matrix.ColumnDefinitions.Clear();
            for (int columnIndex = 0; columnIndex < activeLifeMatrix.Size; columnIndex++)
            {
                ColumnDefinition colDef = null;
                colDef = new ColumnDefinition();
                colDef.Width = new GridLength(matrix.ActualWidth / activeLifeMatrix.Size);
                matrix.ColumnDefinitions.Add(colDef);
            }
            
            activeLifeMatrix.Iterate();
            updateDisplay();


        }