/** Plot bars from (0, a[i]) to (i, a[i]) to standard draw. */ public static void plotBars(double[] a) { final int N = a.length; StdDraw.setXscale(0, N - 1); for (int i = 0; i < N; i++) { StdDraw.filledRectangle(i, a[i] / 2, .25, a[i] / 2); } }
/** * Draws the state of the model, including instructions. * * @param source If non-null, drawing highlights all legal moves from source. */ public void draw(String instructions, Location source) { StdDraw.clear(); for (int r = 0; r < FocusModel.BOARD_WIDTH; r++) { for (int c = 0; c < FocusModel.BOARD_WIDTH; c++) { Location destination = new Location(r, c); drawSquare( model.getPile(destination), 1.5 + c, 9.5 - r, source != null && model.isLegalMove(source, destination)); } } StdDraw.setPenColor(LIGHT_BLUE); StdDraw.filledRectangle(2, 0.5, 2, 0.45); StdDraw.filledRectangle(8, 0.5, 2, 0.45); StdDraw.setPenColor(); StdDraw.text(2, 0.5, "Black reserves: " + model.getReserves(FocusModel.BLACK)); StdDraw.text(8, 0.5, "White reserves: " + model.getReserves(FocusModel.WHITE)); StdDraw.text(5, 1.5, instructions); StdDraw.show(0); }