Пример #1
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]
 }