示例#1
0
        /// <summary>
        /// Add agent
        /// </summary>
        /// <param name="a">Agent</param>
        /// <param name="vectorPosition">Position in the grid</param>
        public void AddAgentToMap(InsectAgent a, int vectorPosition)
        {
            int line   = vectorPosition / Settings.GridSize;
            int column = vectorPosition % Settings.GridSize;

            AddAgentToMap(a, line, column);
        }
示例#2
0
 /// <summary>
 /// Move agent at new location
 /// </summary>
 /// <param name="a">Agent</param>
 /// <param name="newLine">New line</param>
 /// <param name="newColumn">New Column</param>
 public void Move(InsectAgent a, int newLine, int newColumn)
 {
     // Moving the agent
     _map[newLine, newColumn].SetState(a.CurrentCell.AgentInCell);
     a.CurrentCell.SetState(null);
     a.CurrentCell = _map[newLine, newColumn];
 }
示例#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();
        }
示例#4
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);
        }
示例#5
0
        /// <summary>
        /// Create agent name
        /// </summary>
        /// <param name="a">The agent</param>
        /// <returns>Name</returns>
        public string CreateName(InsectAgent a)
        {
            if (a.GetInsectType() == InsectType.Ant)
            {
                return($"a{_currentId++}");
            }
            else if (a.GetInsectType() == InsectType.Doodlebug)
            {
                return($"d{_currentId++}");
            }

            throw new Exception($"Unknown agent type: {a.GetType()}");
        }
示例#6
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());
        }
示例#7
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;
        }
示例#8
0
        /// <summary>
        /// Set state
        /// </summary>
        /// <param name="agent">New agent</param>
        public void SetState(InsectAgent agent)
        {
            AgentInCell = agent;
            string agentName = GetState().ToString();

            if (agentName != TextureName)
            {
                TextureName = agentName;
                if (_init)
                {
                    LoadContent();
                }
            }
        }
示例#9
0
        public void Move(InsectAgent a, int newLine, int newColumn)
        {
            // moving the agent

            _map[newLine, newColumn].State       = _map[a.Line, a.Column].State;
            _map[newLine, newColumn].AgentInCell = _map[a.Line, a.Column].AgentInCell;

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

            // updating agent position

            a.Line   = newLine;
            a.Column = newColumn;
        }
示例#10
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);
        }
示例#11
0
 /// <summary>
 /// Set cell state
 /// </summary>
 /// <param name="insect">Agent</param>
 public void SetState(InsectAgent insect)
 {
     AgentInCell = insect;
     _world.LoadGameObject(this);
 }
示例#12
0
 /// <summary>
 /// Add agent
 /// </summary>
 /// <param name="a">Agent</param>
 /// <param name="line">Line</param>
 /// <param name="column">Column</param>
 public void AddAgentToMap(InsectAgent a, int line, int column)
 {
     a.CurrentCell = _map[line, column];
     _map[line, column].SetState(a);
 }
示例#13
0
        /// <summary>
        /// Return true if the movement is valid
        /// </summary>
        /// <param name="a">Agent</param>
        /// <param name="direction">Direction</param>
        /// <param name="desiredState">Desired state</param>
        /// <param name="newLine">New line</param>
        /// <param name="newColumn">new Column</param>
        /// <returns>True if the movement is valid (and new line/column in out variables)</returns>
        public bool ValidMovement(InsectAgent a, Direction direction, CellState desiredState, out int newLine, out int newColumn)
        {
            int currentLine   = a.CurrentCell.Index.Item1;
            int currentColumn = a.CurrentCell.Index.Item2;

            newLine   = currentLine;
            newColumn = currentColumn;

            switch (direction)
            {
            case Direction.Up:
                if (currentLine == 0)
                {
                    return(false);
                }

                if (_map[currentLine - 1, currentColumn].GetState() != desiredState)
                {
                    return(false);
                }

                newLine = currentLine - 1;
                return(true);

            case Direction.Down:
                if (currentLine == Settings.GridSize - 1)
                {
                    return(false);
                }

                if (_map[currentLine + 1, currentColumn].GetState() != desiredState)
                {
                    return(false);
                }

                newLine = currentLine + 1;
                return(true);

            case Direction.Left:
                if (currentColumn == 0)
                {
                    return(false);
                }

                if (_map[currentLine, currentColumn - 1].GetState() != desiredState)
                {
                    return(false);
                }

                newColumn = currentColumn - 1;
                return(true);

            case Direction.Right:
                if (currentColumn == Settings.GridSize - 1)
                {
                    return(false);
                }

                if (_map[currentLine, currentColumn + 1].GetState() != desiredState)
                {
                    return(false);
                }

                newColumn = currentColumn + 1;
                return(true);

            default:
                break;
            }

            throw new Exception("Invalid direction");
        }
示例#14
0
 public Cell()
 {
     State       = CellState.Empty;
     AgentInCell = null;
 }
示例#15
0
 /// <summary>
 /// Kill doodle agent
 /// </summary>
 /// <param name="da">Insect agent</param>
 public void Die(InsectAgent insect)
 {
     insect.CurrentCell.SetState(null);
 }
示例#16
0
 /// <summary>
 /// Move agent at new location
 /// </summary>
 /// <param name="a">Agent</param>
 /// <param name="newLine">New line</param>
 /// <param name="newColumn">New Column</param>
 public void Move(InsectAgent a, int newLine, int newColumn)
 {
     a.CurrentCell.SetState(null);
     a.CurrentCell = Map[newLine, newColumn];
     a.CurrentCell.SetState(a);
 }