Пример #1
0
        // Metóda, ktorá získa údaje o nastaveniach simulácie zo vstupu, pokúsi sa ich zparsrovať a použiť v simulácií.
        public bool TryApplySimulationSetings(ref OptionsInput input)
        {
            var parsedSettings = this.ParseSimulationSettings(ref input);

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

            this.SetSimulationSettings(parsedSettings);
            return(true);
        }
Пример #2
0
        // Metóda, v ktorej dochádza k parsovaniu vstupov a v prípade chyby k priradeniu chybovej hlášky.
        private SimulationSettings ParseSimulationSettings(ref OptionsInput input)
        {
            int    numberOfReplications = -1;
            int    xSize          = -1;
            int    ySize          = -1;
            int    xStart         = -1;
            int    yStart         = -1;
            int    seed           = -1;
            int    preheating     = -1;
            int    recordInterval = -1;
            double tresHold       = -1;

            bool xSizeError = false;
            bool ySizeError = false;

            if (!Int32.TryParse(input.xSize, out xSize))
            {
                input.errorOccured = true;
                xSizeError         = true;
                input.xSize        = "Error";
            }
            else
            {
                if (xSize < 0)
                {
                    input.errorOccured = true;
                    xSizeError         = true;
                    input.xSize        = "Error: less than 0";
                }
            }

            if (!Int32.TryParse(input.ySize, out ySize))
            {
                input.errorOccured = true;
                ySizeError         = true;
                input.ySize        = "Error";
            }
            else
            {
                if (ySize < 0)
                {
                    input.errorOccured = true;
                    ySizeError         = true;
                    input.ySize        = "Error: less than 0";
                }
            }

            if (!Int32.TryParse(input.xStart, out xStart))
            {
                input.errorOccured = true;
                input.xStart       = "Error";
            }
            else
            {
                if (!xSizeError && (xStart >= xSize || xStart < 0))
                {
                    input.errorOccured = true;
                    input.xStart       = $"Error: value have to be between 0 and {xSize}";
                }
            }

            if (!Int32.TryParse(input.yStart, out yStart))
            {
                input.errorOccured = true;
                input.yStart       = "Error";
            }
            else
            {
                if (!ySizeError && (yStart >= ySize || yStart < 0))
                {
                    input.errorOccured = true;
                    input.xStart       = $"Error: value have to be between 0 and {ySize}";
                }
            }

            if (!Int32.TryParse(input.numberOfReplications, out numberOfReplications))
            {
                input.errorOccured         = true;
                input.numberOfReplications = "Error";
            }

            if (!Double.TryParse(input.tresHold, out tresHold))
            {
                input.errorOccured = true;
                input.tresHold     = "Error";
            }

            if (!Int32.TryParse(input.preheating, out preheating))
            {
                input.errorOccured = true;
                input.preheating   = "Error";
            }
            else
            {
                if (preheating < 0)
                {
                    input.errorOccured = true;
                    input.preheating   = "Error: less than 0";
                }
            }

            if (!Int32.TryParse(input.recordInterval, out recordInterval))
            {
                input.errorOccured   = true;
                input.recordInterval = "Error";
            }
            else
            {
                if (recordInterval < 0)
                {
                    input.errorOccured   = true;
                    input.recordInterval = "Error: less than 0";
                }
            }

            if (!input.autoSeed)
            {
                if (!Int32.TryParse(input.seed, out seed))
                {
                    input.errorOccured = true;
                    input.seed         = "Error";
                }
            }

            if (input.errorOccured)
            {
                return(null);
            }

            return(new SimulationSettings {
                XSize = xSize,
                YSize = ySize,
                XStart = xStart,
                YStart = yStart,
                NumberOfReplications = numberOfReplications,
                TresHold = tresHold,
                Seed = seed,
                Preheating = preheating,
                RecordInterval = recordInterval,
                AutoSeed = input.autoSeed
            });
        }