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 boolean existsCellOnOrientaion(Robot robot, Orientation ori, CellState state) { Boolean needExplore = null; if (robotOnArenaEdge(robot, ori)) return false; if (ori.equals(Orientation.NORTH)) needExplore = existsCellOnTheNorth(robot, state); if (ori.equals(Orientation.WEST)) needExplore = existsCellOnTheWest(robot, state); if (ori.equals(Orientation.SOUTH)) needExplore = existsCellOnTheSouth(robot, state); if (ori.equals(Orientation.EAST)) needExplore = existsCellOnTheEast(robot, state); return needExplore; }
@Override public JComponent createUI( DescriptionType inputOrOutput, Map<URI, Object> dataMap, Orientation orientation) { // Create the main panel JComponent component = new JPanel(new MigLayout("fill")); boolean isOptional = false; if (inputOrOutput instanceof InputDescriptionType) { isOptional = ((InputDescriptionType) inputOrOutput).getMinOccurs().equals(new BigInteger("0")); } // Display the SourceCA into a JTextField JTextField jtf = new JTextField(); jtf.setToolTipText(inputOrOutput.getAbstract().get(0).getValue()); // "Save" the CA inside the JTextField jtf.getDocument().putProperty(DATA_MAP_PROPERTY, dataMap); URI uri = URI.create(inputOrOutput.getIdentifier().getValue()); jtf.getDocument().putProperty(URI_PROPERTY, uri); // add the listener for the text changes in the JTextField jtf.getDocument() .addDocumentListener( EventHandler.create(DocumentListener.class, this, "saveDocumentText", "document")); if (isOptional) { if (dataMap.containsKey(uri)) { jtf.setText(dataMap.get(uri).toString()); } } GeometryData geometryData = null; if (inputOrOutput instanceof InputDescriptionType) { geometryData = (GeometryData) ((InputDescriptionType) inputOrOutput).getDataDescription().getValue(); } // If the DescriptionType is an output, there is nothing to show, so exit if (geometryData == null) { return null; } component.add(jtf, "growx"); if (orientation.equals(Orientation.VERTICAL)) { JPanel buttonPanel = new JPanel(new MigLayout()); // Create the button Browse JButton pasteButton = new JButton(ToolBoxIcon.getIcon(ToolBoxIcon.PASTE)); // "Save" the sourceCA and the JTextField in the button pasteButton.putClientProperty(TEXT_FIELD_PROPERTY, jtf); pasteButton.setBorderPainted(false); pasteButton.setContentAreaFilled(false); pasteButton.setMargin(new Insets(0, 0, 0, 0)); // Add the listener for the click on the button pasteButton.addActionListener(EventHandler.create(ActionListener.class, this, "onPaste", "")); buttonPanel.add(pasteButton); component.add(buttonPanel, "dock east"); } return component; }
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; }