Example #1
0
        public void AddAgentToMap(InsectAgent a, int vectorPosition)
        {
            int line   = vectorPosition / Settings.GridSize;
            int column = vectorPosition % Settings.GridSize;

            AddAgentToMap(a, line, column);
        }
Example #2
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().Name}");
        }
Example #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());
        }
Example #4
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;
        }
Example #5
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;
        }
Example #6
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}");
            }
        }
Example #7
0
 public Cell()
 {
     State       = CellState.Empty;
     AgentInCell = null;
 }
Example #8
0
        public bool ValidMovement(InsectAgent a, Direction direction, CellState desiredState, out int newLine, out int newColumn)
        {
            int currentLine = a.Line; int currentColumn = a.Column;

            newLine = currentLine; newColumn = currentColumn;

            switch (direction)
            {
            case Direction.Up:
                if (currentLine == 0)
                {
                    return(false);
                }
                if (_map[currentLine - 1, currentColumn].State != desiredState)
                {
                    return(false);
                }
                newLine = currentLine - 1;
                return(true);

            case Direction.Down:
                if (currentLine == Settings.GridSize - 1)
                {
                    return(false);
                }
                if (_map[currentLine + 1, currentColumn].State != desiredState)
                {
                    return(false);
                }
                newLine = currentLine + 1;
                return(true);

            case Direction.Left:
                if (currentColumn == 0)
                {
                    return(false);
                }
                if (_map[currentLine, currentColumn - 1].State != desiredState)
                {
                    return(false);
                }
                newColumn = currentColumn - 1;
                return(true);

            case Direction.Right:
                if (currentColumn == Settings.GridSize - 1)
                {
                    return(false);
                }
                if (_map[currentLine, currentColumn + 1].State != desiredState)
                {
                    return(false);
                }
                newColumn = currentColumn + 1;
                return(true);

            default:
                break;
            }

            throw new Exception("Invalid direction");
        }