예제 #1
0
        private void runMasButton_Click(object sender, EventArgs e)
        {
            worldEnv = new World(Settings.NoTurns); // derived from ActressMas.TurnBasedEnvironment
            worldEnv.SetControls(listBox1, richTextBox1);

            int noCells = Settings.GridSize * Settings.GridSize;

            int[] randVect = Settings.RandomPermutation(noCells);

            for (int i = 0; i < Settings.NoDoodlebugs; i++)
            {
                var a = new DoodlebugAgent();
                worldEnv.Add(a, worldEnv.CreateName(a)); // unique name
                worldEnv.AddAgentToMap(a, randVect[i]);
            }

            for (int i = Settings.NoDoodlebugs; i < Settings.NoDoodlebugs + Settings.NoAnts; i++)
            {
                var a = new AntAgent();
                worldEnv.Add(a, worldEnv.CreateName(a));
                worldEnv.AddAgentToMap(a, randVect[i]);
            }

            worldEnv.Start();

            richTextBox1.LoadFile(Settings.WorldStateFileName, RichTextBoxStreamType.PlainText);
        }
예제 #2
0
        public void Eat(DoodlebugAgent da, int newLine, int newColumn)
        {
            // removing the ant

            AntAgent ant = (AntAgent)_map[newLine, newColumn].AgentInCell;

            this.Remove(ant); // from ActressMas.Environment

            if (Settings.Verbose)
            {
                Console.WriteLine($"Removing {ant.Name}");
            }

            // moving the doodlebug

            if (Settings.Verbose)
            {
                Console.WriteLine($"Moving {da.Name}");
            }

            _map[newLine, newColumn].State       = CellState.Doodlebug;
            _map[newLine, newColumn].AgentInCell = _map[da.Line, da.Column].AgentInCell;

            _map[da.Line, da.Column].State       = CellState.Empty;
            _map[da.Line, da.Column].AgentInCell = null;

            // updating doodlebug position

            da.Line   = newLine;
            da.Column = newColumn;
        }
예제 #3
0
        public void Die(DoodlebugAgent da)
        {
            this.Remove(da); // from ActressMas.Environment

            _map[da.Line, da.Column].State       = CellState.Empty;
            _map[da.Line, da.Column].AgentInCell = null;
        }
예제 #4
0
        public void Breed(InsectAgent a, int newLine, int newColumn)
        {
            InsectAgent offspring = null;

            if (a.GetType().Name == "AntAgent")
            {
                offspring = new AntAgent();
            }
            else if (a.GetType().Name == "DoodlebugAgent")
            {
                offspring = new DoodlebugAgent();
            }

            Add(offspring, CreateName(offspring)); // Add is from ActressMas.Environment
            AddAgentToMap(offspring, newLine, newColumn);

            if (Settings.Verbose)
            {
                Console.WriteLine($"Breeding {offspring.Name}");
            }
        }