Esempio 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);
        }
Esempio 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();
        }
Esempio n. 3
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();
        }
Esempio n. 4
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;
        }
Esempio n. 5
0
        private bool TryToEat()
        {
            var allowedDirections = new List <Direction>();
            int newLine, newColumn;

            for (int i = 0; i < 4; i++)
            {
                if (_world.ValidMovement(this, (Direction)i, CellState.Ant, out newLine, out newColumn))
                {
                    allowedDirections.Add((Direction)i);
                }
            }

            if (allowedDirections.Count == 0)
            {
                return(false);
            }

            int r = _rand.Next(allowedDirections.Count);

            _world.ValidMovement(this, allowedDirections[r], CellState.Ant, out newLine, out newColumn);

            AntAgent ant = _world.Eat(this, newLine, newColumn);

            this.Environment.Remove(ant);

            return(true);
        }
Esempio n. 6
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);
        }
Esempio n. 7
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);
        }
Esempio 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);
        }
Esempio 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);
        }
Esempio 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]);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Try to eat
        /// </summary>
        /// <returns>True is the action is valid</returns>
        private bool TryToEat()
        {
            List <Tuple <int, int> > positions = new List <Tuple <int, int> >();

            for (int i = 0; i < 4; i++)
            {
                if (_world.ValidMovement(this, (Direction)i, CellState.Ant, out int newLine, out int newColumn))
                {
                    positions.Add(new Tuple <int, int>(newLine, newColumn));
                }
            }

            if (positions.Count == 0)
            {
                return(false);
            }

            int      r   = Settings.Rand.Next(positions.Count);
            AntAgent ant = _world.Eat(this, positions[r].Item1, positions[r].Item2);

            Environment.Remove(ant);
            return(true);
        }