Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. package rescueagents;
  2.  
  3. import rescueframework.AbstractRobotControl;
  4. import world.*;
  5.  
  6. import java.util.ArrayList;
  7.  
  8. /**
  9. * RobotControl class to implement custom robot control strategies
  10. */
  11. public class RobotControl extends AbstractRobotControl{
  12. private double UnkownCellsSizeStart;
  13. /**
  14. * Default constructor saving world robot object and percepcion
  15. *
  16. * @param robot The robot object in the world
  17. * @param percepcion Percepcion of all robots
  18. */
  19. public RobotControl(Robot robot, RobotPercepcion percepcion) {
  20. super(robot, percepcion);
  21. UnkownCellsSizeStart = percepcion.getUnknownCells().size();
  22. }
  23.  
  24.  
  25. /**
  26. * Custom step strategy of the robot, implement your robot control here!
  27. *
  28. * @return Return NULL for staying in place, 0 = step up, 1 = step right,
  29. * 2 = step down, 3 = step left
  30. */
  31. public Integer step() {
  32. if(robot.hasInjured()) {
  33. return percepcion.getShortestExitPath(robot.getLocation()).getFirstCell().directionFrom(robot.getLocation());
  34. }
  35. while (percepcion.getUnknownCells().size() >= 0.25 * UnkownCellsSizeStart && getMinHealtDInjured() >= 25) {
  36. return percepcion.getShortestUnknownPath(robot.getLocation()).getFirstCell().directionFrom(robot.getLocation());
  37. }
  38. if(getMinHealtDInjured() < 25) {
  39. return getPathToMinHealthDInjured().getFirstCell().directionFrom(robot.getLocation());
  40. } else {
  41. Path path = percepcion.getShortestUnknownPath(robot.getLocation());
  42. if (path != null) {
  43. return path.getFirstCell().directionFrom(robot.getLocation());
  44. } else {
  45. Path path2 = getPathToMinHealthDInjured();
  46. if (path2 == null) {
  47. return percepcion.getShortestExitPath(robot.getLocation()).getFirstCell().directionFrom(robot.getLocation());
  48. } else {
  49. return path2.getFirstCell().directionFrom(robot.getLocation());
  50. }
  51. }
  52. }
  53. }
  54.  
  55. public int getMinHealtDInjured() {
  56. int minHealth = 10000;
  57. ArrayList<Injured> mDiscoveredInjureds = percepcion.getDiscoveredInjureds();
  58. for(int i = 0; i < mDiscoveredInjureds.size(); ++i) {
  59. if (mDiscoveredInjureds.get(i).getHealth() < minHealth && mDiscoveredInjureds.get(i).getHealth() > 0) {
  60. if (mDiscoveredInjureds.get(i).getLocation() != null && AStarSearch.search(robot.getLocation(), mDiscoveredInjureds.get(i).getLocation(), -1) != null) {
  61. minHealth = mDiscoveredInjureds.get(i).getHealth();
  62. }
  63. }
  64. }
  65. return minHealth;
  66. }
  67.  
  68. public Path getPathToMinHealthDInjured() {
  69. int minHealth = 10000;
  70. ArrayList<Injured> mDiscoveredInjureds = percepcion.getDiscoveredInjureds();
  71. for(int i = 0; i < mDiscoveredInjureds.size(); ++i) {
  72. if (mDiscoveredInjureds.get(i).getHealth() < minHealth && mDiscoveredInjureds.get(i).getHealth() > 0) {
  73. if (mDiscoveredInjureds.get(i).getLocation() != null && AStarSearch.search(robot.getLocation(), mDiscoveredInjureds.get(i).getLocation(), -1) != null) {
  74. minHealth = mDiscoveredInjureds.get(i).getHealth();
  75. }
  76. }
  77. }
  78. for(int i = 0; i < mDiscoveredInjureds.size(); ++i) {
  79. if (mDiscoveredInjureds.get(i).getHealth() == minHealth && mDiscoveredInjureds.get(i).getLocation() != null) {
  80. return AStarSearch.search(robot.getLocation(), mDiscoveredInjureds.get(i).getLocation(), -1);
  81. }
  82. }
  83. return null;
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement