private Action moveToOrientation( Robot robot, Orientation firstOrientation, Orientation secondOrientation) { Direction preferedDirection = getPreferedDirection(firstOrientation, secondOrientation); Orientation currentOrientation = robot.getCurrentOrientation(); // System.out.println("Current Orientation = " + currentOrientation.toString()); // System.out.println("First Orientation = " + firstOrientation.toString()); // System.out.println("Second Orientation = " + secondOrientation.toString()); if (currentOrientation.equals(firstOrientation)) { return moveTowardsDirectionInOrder( Direction.AHEAD, preferedDirection, oppoDirection(preferedDirection), robot); } else if (currentOrientation.equals(secondOrientation)) { return moveTowardsDirectionInOrder( oppoDirection(preferedDirection), Direction.AHEAD, preferedDirection, robot); } else if (currentOrientation.toOppsite().equals(firstOrientation)) { return moveTowardsDirectionInOrder( oppoDirection(preferedDirection), Direction.AHEAD, preferedDirection, robot); } else if (currentOrientation.toOppsite().equals(secondOrientation)) { return moveTowardsDirectionInOrder( preferedDirection, Direction.AHEAD, oppoDirection(preferedDirection), robot); } assert (false) : "Should not reach here. No other circumstance"; return null; }
private Action scanArenaColByCol(Robot robot) { Action actionForTentativeTurn = actionForTentiveTurn(robot); if (actionForTentativeTurn != null) return actionForTentativeTurn; if (robotOnArenaEdge(robot, headingOrientation)) { Orientation current = robot.getCurrentOrientation(); if (!current.toOppsite().equals(headingOrientation)) { return Action.TURN_LEFT; } else { headingOrientation = headingOrientation.toOppsite(); trackColID += robot.getDiameterInCellNum(); // Whole arena has been explored if (trackColID >= this.exploredMap.getColumnCount()) return null; } } int currentSouthWestColID = robot.getSouthWestBlock().getColID(); if (currentSouthWestColID < trackColID) { return moveToOrientation(robot, Orientation.EAST, headingOrientation); } else if (currentSouthWestColID == trackColID) { return moveToOrientation(robot, headingOrientation, Orientation.EAST); } else { // currentSouthWestColID > trackColID return moveToOrientation(robot, Orientation.WEST, headingOrientation); } }
private Action actionForTentiveTurn(Robot robot) { if (preTentativeTurn != null) { if (robotSurroundingStatus(robot, robot.getCurrentOrientation()) == 1) { Action newTurn = reverseTurn(preTentativeTurn); preTentativeTurn = null; return newTurn; } else if (robotSurroundingStatus(robot, robot.getCurrentOrientation()) == 0) { preTentativeTurn = null; return Action.MOVE_FORWARD; } else { assert (false) : "The front cell must be explored..."; } } return null; }
private Action moveTowardsDirection(Robot robot, Direction direction) { Action next = null; Orientation currentOrientation = robot.getCurrentOrientation(); Orientation orientationOnDirection = orientationOnDirection(currentOrientation, direction); int statusOnOrientation = robotSurroundingStatus(robot, orientationOnDirection); if (statusOnOrientation <= 0) { next = directionToAction(direction); // if(next.equals(Action.TURN_LEFT) || // next.equals(Action.TURN_RIGHT)){ // // preTentativeTurn = next; // }else{ // preTentativeTurn = null; // } if (statusOnOrientation == -1) { assert (next.equals(Action.TURN_LEFT) || next.equals(Action.TURN_RIGHT)); preTentativeTurn = next; } else { preTentativeTurn = null; } } return next; }