Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package rescueagents;
- import rescueframework.AbstractRobotControl;
- import world.*;
- import java.util.ArrayList;
- /**
- * RobotControl class to implement custom robot control strategies
- */
- public class RobotControl extends AbstractRobotControl{
- private double UnkownCellsSizeStart;
- /**
- * Default constructor saving world robot object and percepcion
- *
- * @param robot The robot object in the world
- * @param percepcion Percepcion of all robots
- */
- public RobotControl(Robot robot, RobotPercepcion percepcion) {
- super(robot, percepcion);
- UnkownCellsSizeStart = percepcion.getUnknownCells().size();
- }
- /**
- * Custom step strategy of the robot, implement your robot control here!
- *
- * @return Return NULL for staying in place, 0 = step up, 1 = step right,
- * 2 = step down, 3 = step left
- */
- public Integer step() {
- if(robot.hasInjured()) {
- return percepcion.getShortestExitPath(robot.getLocation()).getFirstCell().directionFrom(robot.getLocation());
- }
- while (percepcion.getUnknownCells().size() >= 0.25 * UnkownCellsSizeStart && getMinHealtDInjured() >= 25) {
- return percepcion.getShortestUnknownPath(robot.getLocation()).getFirstCell().directionFrom(robot.getLocation());
- }
- if(getMinHealtDInjured() < 25) {
- return getPathToMinHealthDInjured().getFirstCell().directionFrom(robot.getLocation());
- } else {
- Path path = percepcion.getShortestUnknownPath(robot.getLocation());
- if (path != null) {
- return path.getFirstCell().directionFrom(robot.getLocation());
- } else {
- Path path2 = getPathToMinHealthDInjured();
- if (path2 == null) {
- return percepcion.getShortestExitPath(robot.getLocation()).getFirstCell().directionFrom(robot.getLocation());
- } else {
- return path2.getFirstCell().directionFrom(robot.getLocation());
- }
- }
- }
- }
- public int getMinHealtDInjured() {
- int minHealth = 10000;
- ArrayList<Injured> mDiscoveredInjureds = percepcion.getDiscoveredInjureds();
- for(int i = 0; i < mDiscoveredInjureds.size(); ++i) {
- if (mDiscoveredInjureds.get(i).getHealth() < minHealth && mDiscoveredInjureds.get(i).getHealth() > 0) {
- if (mDiscoveredInjureds.get(i).getLocation() != null && AStarSearch.search(robot.getLocation(), mDiscoveredInjureds.get(i).getLocation(), -1) != null) {
- minHealth = mDiscoveredInjureds.get(i).getHealth();
- }
- }
- }
- return minHealth;
- }
- public Path getPathToMinHealthDInjured() {
- int minHealth = 10000;
- ArrayList<Injured> mDiscoveredInjureds = percepcion.getDiscoveredInjureds();
- for(int i = 0; i < mDiscoveredInjureds.size(); ++i) {
- if (mDiscoveredInjureds.get(i).getHealth() < minHealth && mDiscoveredInjureds.get(i).getHealth() > 0) {
- if (mDiscoveredInjureds.get(i).getLocation() != null && AStarSearch.search(robot.getLocation(), mDiscoveredInjureds.get(i).getLocation(), -1) != null) {
- minHealth = mDiscoveredInjureds.get(i).getHealth();
- }
- }
- }
- for(int i = 0; i < mDiscoveredInjureds.size(); ++i) {
- if (mDiscoveredInjureds.get(i).getHealth() == minHealth && mDiscoveredInjureds.get(i).getLocation() != null) {
- return AStarSearch.search(robot.getLocation(), mDiscoveredInjureds.get(i).getLocation(), -1);
- }
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement