Пример #1
0
 public bool setAgent(Agent agent)
 {
     if (!occupied)
     {
         this.agent = agent;
         occupied = true;
         return true;
     }
     return false;
 }
Пример #2
0
 public bool AddAgent(Agent newAgent, int parrentID, int ageParrent)
 {
     if (world.addAgent(newAgent)) // if the agent is succesfully added to the world then also add it to a list for easy referencing
     {
         if(KeepTrackOfTree) branchingList.Add(new int[] { newAgent.ID, parrentID, ageParrent }); // the heratige tree is still being implemented
         agents.Add(newAgent);
         return true;
     }
     return false;
 }
Пример #3
0
 public bool removeAgent()
 {
     if (occupied)
     {
         this.agent = null;
         occupied = false;
         return true;
     }
     return false;
 }
Пример #4
0
 public bool addAgent(Agent agent)
 {
     if (world[agent.X, agent.Y].setAgent(agent)) // if the agent is succesfully added to the cell
     {
         // add food that was in the cell to the new agent according to its carnivor percentage
         float food = world[agent.X, agent.Y].food * ((100 - (float)world[agent.X, agent.Y].getAgent().CarnivorePercentage) / 100);
         world[agent.X, agent.Y].getAgent().Food += (int)food;
         world[agent.X, agent.Y].food = 0;
         return true;
     }
     return false;
 }
Пример #5
0
        // convert the orientation of the agent to the location of the cell it is facing
        public int[] directionToAbsolute(Agent agent, int direction)
        {
            int[] output = new int[2];
            int x = agent.X;
            int y = agent.Y;

            if (direction == 1)
            {
                output[0] = x; output[1] = y - 1;
            }
            else if (direction == 2)
            {
                output[0] = x + 1; output[1] = y - 1;
            }
            else if (direction == 3)
            {
                output[0] = x + 1; output[1] = y;
            }
            else if (direction == 4)
            {
                output[0] = x + 1; output[1] = y + 1;
            }
            else if (direction == 5)
            {
                output[0] = x; output[1] = y + 1;
            }
            else if (direction == 6)
            {
                output[0] = x - 1; output[1] = y + 1;
            }
            else if (direction == 7)
            {
                output[0] = x - 1; output[1] = y;
            }
            else if (direction == 8)
            {
                output[0] = x - 1; output[1] = y - 1;
            }
            else
            {
                throw new System.ArgumentException("Invalid movement direction");
            }

            if (output[0] >= world.worldWidth)
            {
                output[0] = 0;
            }
            else if (output[0] < 0)
            {
                output[0] = world.worldWidth - 1;
            }

            if (output[1] >= world.worldHeight)
            {
                output[1] = 0;
            }
            else if (output[1] < 0)
            {
                output[1] = world.worldHeight - 1;
            }

            return output;
        }
Пример #6
0
 // get the values for the input nodes of an agent
 public int[] CalculateSurrounding(Agent agent)
 {
     int[] surrounding = new int[10];
     int[] location = directionToAbsolute(agent, agent.ValidateDirection(agent.Direction - 2));
     surrounding[0] = world.GetFood(location[0], location[1]);
     surrounding[5] = 0;
     if (world.occupied(location[0], location[1]))
     {
         surrounding[5] = 1;
     }
     location = directionToAbsolute(agent, agent.ValidateDirection(agent.Direction - 1));
     surrounding[1] = world.GetFood(location[0], location[1]);
     surrounding[6] = 0;
     if (world.occupied(location[0], location[1]))
     {
         surrounding[6] = 1;
     }
     location = directionToAbsolute(agent, agent.ValidateDirection(agent.Direction));
     surrounding[2] = world.GetFood(location[0], location[1]);
     surrounding[7] = 0;
     if (world.occupied(location[0], location[1]))
     {
         surrounding[7] = 1;
     }
     location = directionToAbsolute(agent, agent.ValidateDirection(agent.Direction + 1));
     surrounding[3] = world.GetFood(location[0], location[1]);
     surrounding[8] = 0;
     if (world.occupied(location[0], location[1]))
     {
         surrounding[8] = 1;
     }
     location = directionToAbsolute(agent, agent.ValidateDirection(agent.Direction + 2));
     surrounding[4] = world.GetFood(location[0], location[1]);
     surrounding[9] = 0;
     if (world.occupied(location[0], location[1]))
     {
         surrounding[9] = 1;
     }
     return surrounding; // [foodleft, foodleftahead, foodahead, foodrightahead, foodright, agentleft, agentleftahead, agenthead, agentrightahead, agentright]
 }
Пример #7
0
        // creates a mutated copy of itself
        public Agent CreateMutantCopy()
        {
            // mutate the carnivor percentage by adding or substracting with a certain chance
            int MutatedCarnivorePercentage = CarnivorePercentage;
            if (random.Next(0, 100) < 2 & CarnivorPercentageEnabled)
            {
                MutatedCarnivorePercentage += random.Next(0, 7) - 3;
                if (MutatedCarnivorePercentage > 100) MutatedCarnivorePercentage = 100;
                else if (MutatedCarnivorePercentage < 0) MutatedCarnivorePercentage = 0;
            }

            // create new agent (child)
            Agent newAgent = new Agent(CopyNodes(), X, Y, random.Next(1, 9), 5, ID, MutateTableChance, MutateAddNodeConnectionChance, MutateRemoveNodeConnectionChance, MutateSwitchNodeChance, Red, Green, Blue, random, MutatedCarnivorePercentage, StrictK, CarnivorPercentageEnabled);

            // mutate each node with a certain chance
            for (int i = 0; i < newAgent.nodes.Length; i++)
            {
                if (!StrictK)
                {
                    nodes[i].MutateRemoveIncommingNode(MutateRemoveNodeConnectionChance);
                    nodes[i].MutateAddIncommingNode(nodes.Length, MutateAddNodeConnectionChance);
                }
                else
                {
                    nodes[i].SwitchIncommingNode(nodes.Length, MutateSwitchNodeChance);
                }
                newAgent.nodes[i].MutateTable(newAgent.MutateTableChance);
            }
            //PercentageOfNonNeutralConnectoins();
            return newAgent;
        }
Пример #8
0
 public void removeAgent(Agent agent)
 {
     removeAgent(agent.X, agent.Y);
 }
Пример #9
0
 public bool moveAgent(Agent agent, int newX, int newY)
 {
     return moveAgent(agent.X, agent.Y, newX, newY);
 }