// Sample code for PS5 problem 4 public class PS5_problem4 implements Bidder { private double budget = 500; private double utility = 500; private final double[] RATES = {0.5, 0.15, 0.1, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05}; private double lastValue = 0; private int roundsLeft = 1000; private double lastAverage = 0; // given your value for the day, determine an action public double bid(double v) { lastValue = v; roundsLeft--; // first round: bid half my value if (roundsLeft == 999) { return Math.min(v/2, budget); } // last round: bid my budget if (roundsLeft == 0) { return budget; } // later: bid halfway between v/2 and average bid, with a max of 0.99v return Math.min(Math.min(v/4 + lastAverage/2, 0.99 * v), budget); } // callback function with results public void results(int k, double price, double[] bids) { // record my utility and budget if (k != -1) { utility += lastValue * RATES[k-1]; utility -= price; budget -= price; } // compute average bid double bidSum = 0; for (int i = 0; i < bids.length; i++) { bidSum += bids[i]; } lastAverage = bidSum / bids.length; } }