Exemple #1
0
        private void StartHerding()
        {
            ButtonPause.Enabled  = true;
            ButtonResume.Enabled = false;

            ButtonStepBack.Enabled    = false;
            ButtonStepForward.Enabled = false;

            TransformPositions();
            var parameters = (OptimizationParameters) new XmlSerializer(typeof(OptimizationParameters)).Deserialize(new StringReader(richTextBoxParameters.Text));

            if (checkBoxRandom.Checked)
            {
                parameters.PositionsOfShepherds = parameters.PositionsOfShepherds.Randomize(0, 400).ToList();
                parameters.PositionsOfSheep     = parameters.PositionsOfSheep.Randomize(0, 400).ToList();
            }

            var sheep = AgentFactory.GetSheep(parameters.PositionsOfSheep, parameters.SheepType, parameters.SeedForRandomSheepForBest);

            var shepherds = richTextBoxShepherds.Text.Split('\n')
                            .Where(x => string.IsNullOrEmpty(x) == false)
                            .Select(x => repository.LoadShepherd(x));

            var team = TeamFactory.GetNotIdenticalTeam(shepherds.Cast <ThinkingAgent>().ToList());

            team.Resize(parameters.PositionsOfShepherds.Count());
            team.SetPositions(parameters.PositionsOfShepherds);

            world = new ViewableWorld(
                HerdingX,
                HerdingY,
                checkBoxAnimationMode.Checked ? MilisecondsBetweenSteps : 0,
                team,
                sheep);

            world.Start(parameters.TurnsOfHerding);

            paint = true;
        }