[Home]History of BeerPoet

Robo Home | Changes | Preferences | AllPages


Revision 15 . . April 14, 2007 0:22 EST by AaronR
Revision 14 . . June 14, 2005 9:47 EST by PEZ [Updated some links and some facts]
  

Difference (from prior major revision) (no other diffs)

Added: 199a200,248

Here is my Sonnet beerbot:

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
}
}


It gets drunk and misses near the end of the bots. --AaronR

Robo Home | Changes | Preferences | AllPages
Search: