示例#1
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 (a.GetType().Name == "AntAgent")
            {
                _activeAnts.Add(offspring.Name);
            }
            else if (a.GetType().Name == "DoodlebugAgent")
            {
                _activeDoodlebugs.Add(offspring.Name);
            }

            if (Utils.Verbose)
            {
                Console.WriteLine("Breeding " + offspring.Name);
            }

            offspring.Start();
        }
示例#2
0
        public InsectAgent 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();
            }

            string name = CreateName(offspring);

            offspring.Name = name;
            AddAgentToMap(offspring, newLine, newColumn);

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

            return(offspring);
        }
示例#3
0
        public string CreateName(InsectAgent a)
        {
            if (a.GetType().Name == "AntAgent")
            {
                return(string.Format("a{0}", _currentId++));
            }
            else if (a.GetType().Name == "DoodlebugAgent")
            {
                return(string.Format("d{0}", _currentId++));
            }

            throw new Exception("Unknown agent type: " + a.GetType().ToString());
        }
示例#4
0
        public string CreateName(InsectAgent a)
        {
            if (a.GetType().Name == "AntAgent")
            {
                return($"a{_currentId++}");
            }
            else if (a.GetType().Name == "DoodlebugAgent")
            {
                return($"d{_currentId++}");
            }

            throw new Exception($"Unknown agent type: {a.GetType()}");
        }
示例#5
0
        public void AddAgentToMap(InsectAgent a, int line, int column)
        {
            if (a.GetType().Name == "AntAgent")
            {
                _map[line, column].State = CellState.Ant;
            }
            else if (a.GetType().Name == "DoodlebugAgent")
            {
                _map[line, column].State = CellState.Doodlebug;
            }

            a.Line = line; a.Column = column;
            _map[line, column].AgentInCell = a;
        }