Advertisement
Guest User

poprandom

a guest
Jun 26th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. public class PopulateWorld {
  2.  
  3.  
  4. public static void addAllAgents(AgentWorld world) {
  5. addGroupedAgents(world, AgentType.PERSUER, 20, 1,-300,300);
  6. // addGroupedAgents(world, AgentType.EVADER, 10, 0, 0, 200);
  7. //addGroupedAgents(world, AgentType.PERSUER, 1, 1, 160, 160);
  8. //addGroupedAgents(world, AgentType.EVADER, 5, 0, 180, 180);
  9. // addGroupedAgents(world, AgentType.EVADER, 5, 0, 0, -125);
  10. addGroupedAgents(world, AgentType.EVADER, 20, 1, -300, 300);
  11. // addGroupedAgents(world, AgentType.PERSUER, 20, 0, -180, -180);
  12. }
  13.  
  14. private static void addGroupedAgents(AgentWorld world, AgentType type, int count,int numberOfGroups, int x, int y) {
  15. AgentFactory factory = new AgentFactory(world.getPhysicsWorld(), world.getIdMap());
  16. if (type.equals(type.EVADER)) {
  17. int randx = 0;
  18. int randy = 0;
  19. Random r = new Random();
  20. for (int i = 1; i <= count; i++) {
  21. randx = x + r.nextInt((y - x) + 1);
  22. randy = x + r.nextInt((y - x) + 1);
  23. AbstractAgent agent = factory.createAgent(new Vector2(randx, randy), type);
  24. world.addAgent(agent);
  25.  
  26. }
  27. }
  28.  
  29. else if (type.equals(type.PERSUER)){
  30. int agentGroup= 0;
  31. int randx = 0;
  32. int randy = 0;
  33. Random r = new Random();
  34. for (int i = 0; i <= count; i++) {
  35. randx = x + r.nextInt((y - x) + 1);
  36. randy = x + r.nextInt((y - x) + 1);
  37. AbstractAgent agent = factory.createAgent(new Vector2(randx, randy), type);
  38. world.addAgent(agent);
  39.  
  40. }
  41.  
  42. // for (int j=1; j<=numberOfGroups;j++){
  43. //
  44. // agentGroup++;
  45. //
  46. // for (int i=1; i<=count/numberOfGroups;i++){
  47. // AbstractAgent agent = factory.createAgent(new Vector2(x, y), type);
  48. // agent.setAgentGroup(agentGroup);
  49. // world.addAgent(agent);
  50. // //System.out.println(agent.getAgentGroup());
  51. // }
  52. // }
  53. }
  54.  
  55.  
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement