Ejemplo n.º 1
0
        /// <summary>
        /// Eat
        /// </summary>
        /// <param name="da">Doodle agent</param>
        /// <param name="newLine">Line</param>
        /// <param name="newColumn">Column</param>
        /// <returns>The eaten ant</returns>
        public AntAgent Eat(DoodlebugAgent da, int newLine, int newColumn)
        {
            AntAgent ant = (AntAgent)_map[newLine, newColumn].AgentInCell;

            Move(da, newLine, newColumn);
            return(ant);
        }
Ejemplo n.º 2
0
        private static void Main(string[] args)
        {
            var worldEnv = new WorldEnvironment(Settings.NoTurns); // derived from ActressMas.EnvironmentMas
            var world    = worldEnv.Memory["World"];

            int noCells = Settings.GridSize * Settings.GridSize;

            int[] randVect = RandomPermutation(noCells);

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

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

            worldEnv.Start();
        }
Ejemplo n.º 3
0
        public void Eat(DoodlebugAgent da, int newLine, int newColumn)
        {
            // removing the ant

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

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

            if (Utils.Verbose)
            {
                Console.WriteLine("Removing " + ant.Name);
            }

            // moving the doodlebug

            if (Utils.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;
        }
Ejemplo n.º 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 (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();
        }
Ejemplo n.º 5
0
        public AntAgent Eat(DoodlebugAgent da, int newLine, int newColumn)
        {
            AntAgent ant = (AntAgent)_map[newLine, newColumn].AgentInCell;

            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;

            return(ant);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        public void Die(DoodlebugAgent da)
        {
            _activeDoodlebugs.Remove(da.Name);
            this.Remove(da); // from ActressMas.Environment

            _map[da.Line, da.Column].State       = CellState.Empty;
            _map[da.Line, da.Column].AgentInCell = null;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Eat
        /// </summary>
        /// <param name="da">Doodle agent</param>
        /// <param name="newLine">Line</param>
        /// <param name="newColumn">Column</param>
        public void Eat(DoodlebugAgent da, int newLine, int newColumn)
        {
            // Get ant
            AntAgent ant = (AntAgent)Map[newLine, newColumn].AgentInCell;

            // Delete game object
            Map[newLine, newColumn].SetState(null);
            // Remove agent
            _environment.Remove(ant);
            // Move doodlebug to the new location
            Move(da, newLine, newColumn);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Agent breed
        /// </summary>
        /// <param name="a">Agent</param>
        /// <param name="newLine">Line</param>
        /// <param name="newColumn">Column</param>
        /// <returns>New agent</returns>
        public InsectAgent Breed(InsectAgent a, int newLine, int newColumn)
        {
            InsectAgent offspring = null;

            if (a.GetInsectType() == InsectType.Ant)
            {
                offspring = new AntAgent();
            }
            else if (a.GetInsectType() == InsectType.Doodlebug)
            {
                offspring = new DoodlebugAgent();
            }

            string name = CreateName(offspring);

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

            return(offspring);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Init agents in the world
        /// </summary>
        /// <param name="environment"></param>
        public void InitAgents(World world)
        {
            int noCells = Settings.GridSize * Settings.GridSize;

            int[] randVect = RandomPermutation(noCells);

            // Create agents Doodle bugs
            for (int i = 0; i < Settings.NoDoodlebugs; i++)
            {
                var a = new DoodlebugAgent();
                Add(a, world.CreateName(a)); // Unique name
                world.AddAgentToMap(a, randVect[i]);
            }

            // Create agents Ants
            for (int i = Settings.NoDoodlebugs; i < Settings.NoDoodlebugs + Settings.NoAnts; i++)
            {
                var a = new AntAgent();
                Add(a, world.CreateName(a));
                world.AddAgentToMap(a, randVect[i]);
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Kill doodle agent
 /// </summary>
 /// <param name="da">Doodle agent</param>
 public void Die(DoodlebugAgent da)
 {
     da.CurrentCell.SetState(null);
     da.CurrentCell = null;
 }
Ejemplo n.º 12
0
 public void Die(DoodlebugAgent da)
 {
     _map[da.Line, da.Column].State       = CellState.Empty;
     _map[da.Line, da.Column].AgentInCell = null;
 }