コード例 #1
0
ファイル: WorldMap.cs プロジェクト: florinleon/ActressMas
        public void AddAgentToMap(InsectAgent a, int vectorPosition)
        {
            int line   = vectorPosition / Settings.GridSize;
            int column = vectorPosition % Settings.GridSize;

            AddAgentToMap(a, line, column);
        }
コード例 #2
0
ファイル: WorldMap.cs プロジェクト: florinleon/ActressMas
        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}");
        }
コード例 #3
0
ファイル: WorldMap.cs プロジェクト: jferdelyi/ActressMas
        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
ファイル: WorldMap.cs プロジェクト: florinleon/ActressMas
        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;
        }
コード例 #5
0
ファイル: WorldMap.cs プロジェクト: florinleon/ActressMas
        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;
        }
コード例 #6
0
ファイル: WorldMap.cs プロジェクト: florinleon/ActressMas
        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}");
            }
        }
コード例 #7
0
ファイル: WorldMap.cs プロジェクト: florinleon/ActressMas
 public Cell()
 {
     State       = CellState.Empty;
     AgentInCell = null;
 }
コード例 #8
0
ファイル: WorldMap.cs プロジェクト: florinleon/ActressMas
        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");
        }