import rebelsky.fun.balloons.Balloon; import rebelsky.fun.balloons.Strategist; import rebelsky.fun.balloons.Wind; /** * A more complex strategy for winning balloon races. If you're on the * ground, drop a sandbag. If you're over * 2/3 of the way up, deflate * the balloon. If you're anywhere else check the wind speed ten feet * above and ten feet below. If it's faster above, increase the inflation. * If it's faster below, decrease the inflation. */ public class Windy extends Strategist { /** * Decide what to do based on knowledge of the balloon status. * Ignore the wind. */ public void decide(Balloon b, int maxheight, Wind w) { // The height of the balloon int height = b.getHeight(); // If the balloon popped, do nothing. if (b.popped()) return; // If we're still on the ground, drop a sandbag if (height == 0) { if (b.getSandbags() > 0) { b.drop(); } else { b.inflate(); } } // If we're more than two thirds of the way up, deflate the balloon else if (height > ((2 * maxheight) / 3)) { b.deflate(); } // Otherwise, compare higher speeds and lower speeds else { if (w.getSpeed(height + 10) > w.getSpeed(height - 10)) { b.inflate(); } else { b.deflate(); } } } // decide() } // Windy