import java.awt.Point; /** * Strategy that picks add locations at random. * @author Jeff Raab */ public class RandomStrategy extends ACraneStrategy { /** Constructs a random strategy. */ public RandomStrategy() {} /** Returns the name of this. */ public String getName() { return "Randomosity v1.0"; } /////////////////////// // Protected methods // /////////////////////// /** * Returns a random location at which * to try to add the given parcel. * @param aParcel parcel to be added (ignored) */ protected Point getAddLocation(Parcel aParcel) { int row = (int)(Math.random() * warehouse.getRowCount()); int col = (int)(Math.random() * warehouse.getColumnCount()); while (orderNumberAt(row, col) != -1) { row = (int)(Math.random() * warehouse.getRowCount()); col = (int)(Math.random() * warehouse.getColumnCount()); } return new Point(row, col); } /** * Returns a location from which * to remove a parcel in the given order. * @param anOrder order to be removed */ protected Point getRemoveLocation(Order anOrder) { for (int i = 0; i < warehouse.getRowCount(); i++) { for (int j = 0; j < warehouse.getColumnCount(); j++) { if (orderNumberAt(i, j) == anOrder.number) { return new Point(i, j); } } } return null; } }