コード例 #1
0
ファイル: AutomatonViewModel.cs プロジェクト: IReznykov/Apps
        private void UserSettingsOnPropertyChanged(object sender, PropertyChangedEventArgs args)
        {
            if (Automaton == null)
            {
                return;
            }

            PauseIteration();

            switch (args.PropertyName)
            {
            case nameof(Settings.Width):
            case nameof(Settings.Height):
                ImplementNewSize();
                break;

            case nameof(Settings.KnownLifePreset):
                CellLifeService.LifePreset = KnownLifePresets.GetKnownLifePreset(Settings.KnownLifePreset);
                break;

            case nameof(Settings.InitialAutomatonType):
                if (Settings.InitialAutomatonType != InitialAutomatonType.Previous)
                {
                    Automaton.Clear();
                    AutomatonSetPoints(InitialAutomaton());
                }
                break;

            case nameof(Settings.IterationDelay):
                _iterateTimer.Interval = TimeSpan.FromMilliseconds(Settings.IterationDelay);
                break;
            }

            ContinueIteration();
        }
コード例 #2
0
        public void Automaton_Should_ClearAllCells()
        {
            const int width  = 4;
            const int height = 7;

            var cellLifeService = Mock.Of <ICellLifeService>();
            var automaton       = new Automaton(width, height, cellLifeService, Mock.Of <ILogger>());

            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    ((Cell)automaton.GetCell(x, y)).State = (x % 3 == 0) && (y % 2 == 0);
                }
            }

            automaton.Clear();

            // checks
            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    var cell = automaton.GetCell(x, y);
                    cell.Should().NotBeNull().And.BeDeadCell();
                }
            }
        }
コード例 #3
0
ファイル: AutomatonViewModel.cs プロジェクト: IReznykov/Apps
        /// <summary>
        /// Set initial automaton.
        /// </summary>
        private void SetInitialAutomaton()
        {
            // prevent timer's start until automaton will be reinit
            SetAutomatonCommandProviderMode(AutomatonCommandProviderMode.None);
            PauseIteration();

            using (Application.Current.Dispatcher.DisableProcessing())
            {
                Automaton.Clear();
                AutomatonSetPoints(InitialAutomaton());
            }

            // post recreating actions
            ContinueIteration(true);
        }
コード例 #4
0
ファイル: AutomatonViewModel.cs プロジェクト: IReznykov/Apps
        private void Iterate()
        {
            if (Automaton == null)
            {
                return;
            }

            using (Application.Current.Dispatcher.DisableProcessing())
            {
                var statistics = new Statistics();
                var result     = Automaton.Iterate(ref statistics);

                UpdateChartRepository(statistics);

                // if there are no cells that change their state - reinit automaton
                if (result && statistics.Changed == 0)
                {
                    Automaton.Clear();
                    AutomatonSetPoints(InitialAutomaton());
                }
            }
        }
コード例 #5
0
        public void Automaton_Should_ClearAfterSetPoint()
        {
            const int width  = 10;
            const int height = 10;

            var cellLifeService = Mock.Of <ICellLifeService>();
            var automaton       = new Automaton(width, height, cellLifeService, Mock.Of <ILogger>());
            var pointList       = new[]
            {
                // Lightweight spaceship
                new Point(1, 1),
                new Point(4, 1),
                new Point(5, 2),
                new Point(1, 3),
                new Point(5, 3),
                new Point(2, 4),
                new Point(3, 4),
                new Point(4, 4),
                new Point(5, 4),
            };

            var statistics = new Statistics();

            automaton.SetPoints(pointList, ref statistics);
            automaton.Clear();

            // checks
            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    var cell = automaton.GetCell(x, y);
                    cell.Should().NotBeNull().And.BeDeadCell();
                }
            }
        }