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 Boolean existsCellOnTheSouth(Robot robot, CellState cell) { int robotDiamterInCellNum = robot.getDiameterInCellNum(); int rowID = robot.getSouthWestBlock().getRowID() + 1; for (int colOffset = 0; colOffset < robotDiamterInCellNum; colOffset++) { int colID = robot.getSouthWestBlock().getColID() + colOffset; if (this.exploredMap.getCell(rowID, colID) == cell) return true; } return false; }
private boolean robotOnArenaEdge(Robot robot, Orientation ori) { if (ori.equals(Orientation.NORTH)) { return robot.getSouthWestBlock().getRowID() == robot.getDiameterInCellNum() - 1; } if (ori.equals(Orientation.EAST)) { return robot.getSouthWestBlock().getColID() == this.exploredMap.getColumnCount() - robot.getDiameterInCellNum(); } if (ori.equals(Orientation.SOUTH)) { return robot.getSouthWestBlock().getRowID() == this.exploredMap.getRowCount() - 1; } if (ori.equals(Orientation.WEST)) { return robot.getSouthWestBlock().getColID() == 0; } assert (false) : "No other direction..."; return false; }