[Home]BeerSonnet

Robo Home | Changes | Preferences | AllPages

AaronR's version of BeerPoet, implemented as a Sonnet. It gets drunk and starts missing near the end of the bots.

public class BeerSonnet extends AdvancedRobot {
	public void run() {
		setAdjustRadarForGunTurn(true); // 1

		setTurnRadarRight(Double.POSITIVE_INFINITY); // 2
		printBottles(); // 3
	}

	public void onScannedRobot(ScannedRobotEvent e) {
		setTurnRadarLeft(getRadarTurnRemaining()); // 4

		double absoluteBearing = getHeadingRadians() + e.getBearingRadians()
				+ (Math.random() < 0.5 ? 1 : -1)
				* (Math.random() / getOthers()); // 5
		turnGunRightRadians(Util.normalRelativeAngle(absoluteBearing
				- getGunHeadingRadians())); // 6
		fire(3); // 7
	}

	public void onRobotDeath(RobotDeathEvent e) {
		printBottles(); // 8
	}

	private void printBottles() {
		out.println(bottles()); // 9
		if (getOthers() > 0) {
			out.println("Take " + (getOthers() == 1 ? "it" : "one")
					+ " down, and pass it around"); // 10
		} else {
			out.println("Now they are all gone"); // 11
		}
	}

	private String bottles() {
		String bottleCount = bottles(getOthers()); // 12
		return bottleCount + " on the wall, " + bottleCount; // 13
	}

	private String bottles(int bottles) {
		return (bottles == 0 ? "No" : "" + bottles) + " bottle"
				+ (bottles == 1 ? "" : "s") + " of beer"; // 14
	}
}

Robo Home | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited April 13, 2007 22:35 EST by AaronR (diff)
Search: