User:Chase-san/DelegatingRobot
Jump to navigation
Jump to search
In case anyone ever has the need for this kind of delegating robot framework. No license, you can use this however you want.
Delegator
package cs.bot;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.util.ArrayList;
import robocode.BattleEndedEvent;
import robocode.BulletHitBulletEvent;
import robocode.BulletHitEvent;
import robocode.BulletMissedEvent;
import robocode.CustomEvent;
import robocode.DeathEvent;
import robocode.HitByBulletEvent;
import robocode.HitRobotEvent;
import robocode.HitWallEvent;
import robocode.MessageEvent;
import robocode.RateControlRobot;
import robocode.RobotDeathEvent;
import robocode.RoundEndedEvent;
import robocode.ScannedRobotEvent;
import robocode.SkippedTurnEvent;
import robocode.StatusEvent;
import robocode.WinEvent;
public abstract class DelegatingRobot extends RateControlRobot {
protected ArrayList<Delegate> wrappers = new ArrayList<Delegate>();
public void addWrapper(Delegate wrap) {
wrappers.add(wrap);
wrap.setBase(this);
}
@Override
public void onMessageReceived(MessageEvent event) {
for(Delegate w : wrappers)
w.onMessageReceived(event);
}
@Override
public void onCustomEvent(CustomEvent event) {
for(Delegate w : wrappers)
w.onCustomEvent(event);
}
@Override
public void onDeath(DeathEvent event) {
for(Delegate w : wrappers)
w.onDeath(event);
}
@Override
public void onSkippedTurn(SkippedTurnEvent event) {
for(Delegate w : wrappers)
w.onSkippedTurn(event);
}
@Override
public void onBattleEnded(BattleEndedEvent event) {
for(Delegate w : wrappers)
w.onBattleEnded(event);
}
@Override
public void onBulletHit(BulletHitEvent event) {
for(Delegate w : wrappers)
w.onBulletHit(event);
}
@Override
public void onBulletHitBullet(BulletHitBulletEvent event) {
for(Delegate w : wrappers)
w.onBulletHitBullet(event);
}
@Override
public void onBulletMissed(BulletMissedEvent event) {
for(Delegate w : wrappers)
w.onBulletMissed(event);
}
@Override
public void onHitByBullet(HitByBulletEvent event) {
for(Delegate w : wrappers)
w.onHitByBullet(event);
}
@Override
public void onHitRobot(HitRobotEvent event) {
for(Delegate w : wrappers)
w.onHitRobot(event);
}
@Override
public void onHitWall(HitWallEvent event) {
for(Delegate w : wrappers)
w.onHitWall(event);
}
@Override
public void onKeyPressed(KeyEvent e) {
for(Delegate w : wrappers)
w.onKeyPressed(e);
}
@Override
public void onKeyReleased(KeyEvent e) {
for(Delegate w : wrappers)
w.onKeyReleased(e);
}
@Override
public void onKeyTyped(KeyEvent e) {
for(Delegate w : wrappers)
w.onKeyTyped(e);
}
@Override
public void onMouseClicked(MouseEvent e) {
for(Delegate w : wrappers)
w.onMouseClicked(e);
}
@Override
public void onMouseDragged(MouseEvent e) {
for(Delegate w : wrappers)
w.onMouseDragged(e);
}
@Override
public void onMouseEntered(MouseEvent e) {
for(Delegate w : wrappers)
w.onMouseEntered(e);
}
@Override
public void onMouseExited(MouseEvent e) {
for(Delegate w : wrappers)
w.onMouseExited(e);
}
@Override
public void onMouseMoved(MouseEvent e) {
for(Delegate w : wrappers)
w.onMouseMoved(e);
}
@Override
public void onMousePressed(MouseEvent e) {
for(Delegate w : wrappers)
w.onMousePressed(e);
}
@Override
public void onMouseReleased(MouseEvent e) {
for(Delegate w : wrappers)
w.onMouseReleased(e);
}
@Override
public void onMouseWheelMoved(MouseWheelEvent e) {
for(Delegate w : wrappers)
w.onMouseWheelMoved(e);
}
@Override
public void onPaint(Graphics2D g) {
for(Delegate w : wrappers)
w.onPaint(g);
}
@Override
public void onRobotDeath(RobotDeathEvent event) {
for(Delegate w : wrappers)
w.onRobotDeath(event);
}
@Override
public void onRoundEnded(RoundEndedEvent event) {
for(Delegate w : wrappers)
w.onRoundEnded(event);
}
@Override
public void onScannedRobot(ScannedRobotEvent event) {
for(Delegate w : wrappers)
w.onScannedRobot(event);
}
@Override
public void onStatus(StatusEvent e) {
for(Delegate w : wrappers)
w.onStatus(e);
}
@Override
public void onWin(WinEvent event) {
for(Delegate w : wrappers)
w.onWin(event);
}
}
Delegate
package cs.bot;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.Vector;
import robocode.BattleEndedEvent;
import robocode.Bullet;
import robocode.BulletHitBulletEvent;
import robocode.BulletHitEvent;
import robocode.BulletMissedEvent;
import robocode.Condition;
import robocode.CustomEvent;
import robocode.DeathEvent;
import robocode.Event;
import robocode.HitByBulletEvent;
import robocode.HitRobotEvent;
import robocode.HitWallEvent;
import robocode.MessageEvent;
import robocode.RobotDeathEvent;
import robocode.RoundEndedEvent;
import robocode.ScannedRobotEvent;
import robocode.SkippedTurnEvent;
import robocode.StatusEvent;
import robocode.WinEvent;
public abstract class Delegate {
protected DelegatingRobot base;
protected void setBase(DelegatingRobot base) {
this.base = base;
}
public void execute() {
base.execute();
}
public double getGunRotationRate() {
return base.getGunRotationRate();
}
public double getGunRotationRateRadians() {
return base.getGunRotationRateRadians();
}
public double getRadarRotationRate() {
return base.getRadarRotationRate();
}
public double getRadarRotationRateRadians() {
return base.getRadarRotationRateRadians();
}
public double getTurnRate() {
return base.getTurnRate();
}
public double getTurnRateRadians() {
return base.getTurnRateRadians();
}
public double getVelocityRate() {
return base.getVelocityRate();
}
public void setGunRotationRate(double gunRotationRate) {
base.setGunRotationRate(gunRotationRate);
}
public void setGunRotationRateRadians(double gunRotationRate) {
base.setGunRotationRateRadians(gunRotationRate);
}
public void setRadarRotationRate(double radarRotationRate) {
base.setRadarRotationRate(radarRotationRate);
}
public void setRadarRotationRateRadians(double radarRotationRate) {
base.setRadarRotationRateRadians(radarRotationRate);
}
public void setTurnRate(double turnRate) {
base.setTurnRate(turnRate);
}
public void setTurnRateRadians(double turnRate) {
base.setTurnRateRadians(turnRate);
}
public void setVelocityRate(double velocityRate) {
base.setVelocityRate(velocityRate);
}
public void broadcastMessage(Serializable message) throws IOException {
base.broadcastMessage(message);
}
public Vector<MessageEvent> getMessageEvents() {
return base.getMessageEvents();
}
public String[] getTeammates() {
return base.getTeammates();
}
public boolean isTeammate(String name) {
return base.isTeammate(name);
}
public void sendMessage(String name, Serializable message) throws IOException {
base.sendMessage(name, message);
}
public void addCustomEvent(Condition condition) {
base.addCustomEvent(condition);
}
public void clearAllEvents() {
base.clearAllEvents();
}
public Vector<Event> getAllEvents() {
return base.getAllEvents();
}
public Vector<BulletHitBulletEvent> getBulletHitBulletEvents() {
return base.getBulletHitBulletEvents();
}
public Vector<BulletHitEvent> getBulletHitEvents() {
return base.getBulletHitEvents();
}
public Vector<BulletMissedEvent> getBulletMissedEvents() {
return base.getBulletMissedEvents();
}
public File getDataDirectory() {
return base.getDataDirectory();
}
public File getDataFile(String filename) {
return base.getDataFile(filename);
}
public long getDataQuotaAvailable() {
return base.getDataQuotaAvailable();
}
public double getDistanceRemaining() {
return base.getDistanceRemaining();
}
public int getEventPriority(String eventClass) {
return base.getEventPriority(eventClass);
}
public double getGunHeadingRadians() {
return base.getGunHeadingRadians();
}
public double getGunTurnRemaining() {
return base.getGunTurnRemaining();
}
public double getGunTurnRemainingRadians() {
return base.getGunTurnRemainingRadians();
}
public double getHeadingRadians() {
return base.getHeadingRadians();
}
public Vector<HitByBulletEvent> getHitByBulletEvents() {
return base.getHitByBulletEvents();
}
public Vector<HitRobotEvent> getHitRobotEvents() {
return base.getHitRobotEvents();
}
public Vector<HitWallEvent> getHitWallEvents() {
return base.getHitWallEvents();
}
public double getRadarHeadingRadians() {
return base.getRadarHeadingRadians();
}
public double getRadarTurnRemaining() {
return base.getRadarTurnRemaining();
}
public double getRadarTurnRemainingRadians() {
return base.getRadarTurnRemainingRadians();
}
public Vector<RobotDeathEvent> getRobotDeathEvents() {
return base.getRobotDeathEvents();
}
public Vector<ScannedRobotEvent> getScannedRobotEvents() {
return base.getScannedRobotEvents();
}
public Vector<StatusEvent> getStatusEvents() {
return base.getStatusEvents();
}
public double getTurnRemaining() {
return base.getTurnRemaining();
}
public double getTurnRemainingRadians() {
return base.getTurnRemainingRadians();
}
public boolean isAdjustGunForRobotTurn() {
return base.isAdjustGunForRobotTurn();
}
public boolean isAdjustRadarForGunTurn() {
return base.isAdjustRadarForGunTurn();
}
public boolean isAdjustRadarForRobotTurn() {
return base.isAdjustRadarForRobotTurn();
}
public void removeCustomEvent(Condition condition) {
base.removeCustomEvent(condition);
}
public void setAhead(double distance) {
base.setAhead(distance);
}
public void setBack(double distance) {
base.setBack(distance);
}
public void setEventPriority(String eventClass, int priority) {
base.setEventPriority(eventClass, priority);
}
public void setFire(double power) {
base.setFire(power);
}
public Bullet setFireBullet(double power) {
return base.setFireBullet(power);
}
public void setInterruptible(boolean interruptible) {
base.setInterruptible(interruptible);
}
public void setMaxTurnRate(double newMaxTurnRate) {
base.setMaxTurnRate(newMaxTurnRate);
}
public void setMaxVelocity(double newMaxVelocity) {
base.setMaxVelocity(newMaxVelocity);
}
public void setResume() {
base.setResume();
}
public void setStop() {
base.setStop();
}
public void setStop(boolean overwrite) {
base.setStop(overwrite);
}
public void setTurnGunLeft(double degrees) {
base.setTurnGunLeft(degrees);
}
public void setTurnGunLeftRadians(double radians) {
base.setTurnGunLeftRadians(radians);
}
public void setTurnGunRight(double degrees) {
base.setTurnGunRight(degrees);
}
public void setTurnGunRightRadians(double radians) {
base.setTurnGunRightRadians(radians);
}
public void setTurnLeft(double degrees) {
base.setTurnLeft(degrees);
}
public void setTurnLeftRadians(double radians) {
base.setTurnLeftRadians(radians);
}
public void setTurnRadarLeft(double degrees) {
base.setTurnRadarLeft(degrees);
}
public void setTurnRadarLeftRadians(double radians) {
base.setTurnRadarLeftRadians(radians);
}
public void setTurnRadarRight(double degrees) {
base.setTurnRadarRight(degrees);
}
public void setTurnRadarRightRadians(double radians) {
base.setTurnRadarRightRadians(radians);
}
public void setTurnRight(double degrees) {
base.setTurnRight(degrees);
}
public void setTurnRightRadians(double radians) {
base.setTurnRightRadians(radians);
}
public void turnGunLeftRadians(double radians) {
base.turnGunLeftRadians(radians);
}
public void turnGunRightRadians(double radians) {
base.turnGunRightRadians(radians);
}
public void turnLeftRadians(double radians) {
base.turnLeftRadians(radians);
}
public void turnRadarLeftRadians(double radians) {
base.turnRadarLeftRadians(radians);
}
public void turnRadarRightRadians(double radians) {
base.turnRadarRightRadians(radians);
}
public void turnRightRadians(double radians) {
base.turnRightRadians(radians);
}
public void waitFor(Condition condition) {
base.waitFor(condition);
}
public void ahead(double distance) {
base.ahead(distance);
}
public void back(double distance) {
base.back(distance);
}
public void doNothing() {
base.doNothing();
}
public void fire(double power) {
base.fire(power);
}
public Bullet fireBullet(double power) {
return base.fireBullet(power);
}
public double getBattleFieldHeight() {
return base.getBattleFieldHeight();
}
public double getBattleFieldWidth() {
return base.getBattleFieldWidth();
}
public double getEnergy() {
return base.getEnergy();
}
public Graphics2D getGraphics() {
return base.getGraphics();
}
public double getGunCoolingRate() {
return base.getGunCoolingRate();
}
public double getGunHeading() {
return base.getGunHeading();
}
public double getGunHeat() {
return base.getGunHeat();
}
public double getHeading() {
return base.getHeading();
}
public double getHeight() {
return base.getHeight();
}
public String getName() {
return base.getName();
}
public int getNumRounds() {
return base.getNumRounds();
}
public int getOthers() {
return base.getOthers();
}
public double getRadarHeading() {
return base.getRadarHeading();
}
public int getRoundNum() {
return base.getRoundNum();
}
public long getTime() {
return base.getTime();
}
public double getVelocity() {
return base.getVelocity();
}
public double getWidth() {
return base.getWidth();
}
public double getX() {
return base.getX();
}
public double getY() {
return base.getY();
}
public void resume() {
base.resume();
}
public void scan() {
base.scan();
}
public void setAdjustGunForRobotTurn(boolean independent) {
base.setAdjustGunForRobotTurn(independent);
}
public void setAdjustRadarForGunTurn(boolean independent) {
base.setAdjustRadarForGunTurn(independent);
}
public void setAdjustRadarForRobotTurn(boolean independent) {
base.setAdjustRadarForRobotTurn(independent);
}
public void setAllColors(Color color) {
base.setAllColors(color);
}
public void setBodyColor(Color color) {
base.setBodyColor(color);
}
public void setBulletColor(Color color) {
base.setBulletColor(color);
}
public void setColors(Color bodyColor, Color gunColor, Color radarColor) {
base.setColors(bodyColor, gunColor, radarColor);
}
public void setColors(Color bodyColor, Color gunColor, Color radarColor, Color bulletColor, Color scanArcColor) {
base.setColors(bodyColor, gunColor, radarColor, bulletColor, scanArcColor);
}
public void setDebugProperty(String key, String value) {
base.setDebugProperty(key, value);
}
public void setGunColor(Color color) {
base.setGunColor(color);
}
public void setRadarColor(Color color) {
base.setRadarColor(color);
}
public void setScanColor(Color color) {
base.setScanColor(color);
}
public void stop() {
base.stop();
}
public void stop(boolean overwrite) {
base.stop(overwrite);
}
public void turnGunLeft(double degrees) {
base.turnGunLeft(degrees);
}
public void turnGunRight(double degrees) {
base.turnGunRight(degrees);
}
public void turnLeft(double degrees) {
base.turnLeft(degrees);
}
public void turnRadarLeft(double degrees) {
base.turnRadarLeft(degrees);
}
public void turnRadarRight(double degrees) {
base.turnRadarRight(degrees);
}
public void turnRight(double degrees) {
base.turnRight(degrees);
}
public void onMessageReceived(MessageEvent event) {}
public void onCustomEvent(CustomEvent event) {}
public void onDeath(DeathEvent event) {}
public void onSkippedTurn(SkippedTurnEvent event) {}
public void onBattleEnded(BattleEndedEvent event) {}
public void onBulletHit(BulletHitEvent event) {}
public void onBulletHitBullet(BulletHitBulletEvent event) {}
public void onBulletMissed(BulletMissedEvent event) {}
public void onHitByBullet(HitByBulletEvent event) {}
public void onHitRobot(HitRobotEvent event) {}
public void onHitWall(HitWallEvent event) {}
public void onKeyPressed(KeyEvent e) {}
public void onKeyReleased(KeyEvent e) {}
public void onKeyTyped(KeyEvent e) {}
public void onMouseClicked(MouseEvent e) {}
public void onMouseDragged(MouseEvent e) {}
public void onMouseEntered(MouseEvent e) {}
public void onMouseExited(MouseEvent e) {}
public void onMouseMoved(MouseEvent e) {}
public void onMousePressed(MouseEvent e) {}
public void onMouseReleased(MouseEvent e) {}
public void onMouseWheelMoved(MouseWheelEvent e) {}
public void onPaint(Graphics2D g) {}
public void onRobotDeath(RobotDeathEvent event) {}
public void onRoundEnded(RoundEndedEvent event) {}
public void onScannedRobot(ScannedRobotEvent event) {}
public void onStatus(StatusEvent e) {}
public void onWin(WinEvent event) {}
}