The walls are defined by two points. That is point (0,0) and and point (battleFieldWidth, battleFieldHeight).
You can use the two methods getBattleFieldWidth() and getBattleFieldHeight() to get the battle field size.
Actually it is possible to create your own Condition for firing a Custom Event in Robocode. This way you are able to create your own event for detection the wall, and also tell which walls that have been detected.
Here I give you a complete robot showing how to do that:
packageexample;importrobocode.*;publicclassWallDetectionRobotextendsAdvancedRobot{publicvoidrun(){// Add our WallDetectedCondition as a custom eventaddCustomEvent(newWallDetectedCondition());while(true){ahead(100);turnGunRight(360);back(100);turnGunRight(360);}}publicvoidonScannedRobot(ScannedRobotEvente){fire(1);}publicvoidonCustomEvent(CustomEvente){WallDetectedConditionwdc=(WallDetectedCondition)e.getCondition();if(wdc.detectedLeftWall){out.println("Left wall detected");}if(wdc.detectedButtomWall){out.println("Buttom wall detected");}if(wdc.detectedRightWall){out.println("Right wall detected");}if(wdc.detectedTopWall){out.println("Top wall detected");}}classWallDetectedConditionextendsCondition{publicbooleandetectedLeftWall;publicbooleandetectedButtomWall;publicbooleandetectedRightWall;publicbooleandetectedTopWall;publicbooleantest(){detectedLeftWall=getX()<Rules.RADAR_SCAN_RADIUS;detectedButtomWall=getY()<Rules.RADAR_SCAN_RADIUS;detectedRightWall=(getBattleFieldWidth()-getX())<Rules.RADAR_SCAN_RADIUS;detectedTopWall=(getBattleFieldHeight()-getY())<Rules.RADAR_SCAN_RADIUS;returndetectedLeftWall||detectedButtomWall||detectedRightWall||detectedTopWall;}}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Why do you want such an event?
The walls are defined by two points. That is point (0,0) and and point (battleFieldWidth, battleFieldHeight).
You can use the two methods getBattleFieldWidth() and getBattleFieldHeight() to get the battle field size.
Actually it is possible to create your own Condition for firing a Custom Event in Robocode. This way you are able to create your own event for detection the wall, and also tell which walls that have been detected.
Here I give you a complete robot showing how to do that: