Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package roboti.sebastian;
- import robocode.AdvancedRobot;
- import robocode.HitRobotEvent;
- import robocode.Robot;
- import robocode.ScannedRobotEvent;
- public class SebastianBot2 extends AdvancedRobot {
- private byte scanDirection = 1;
- public void run() {
- while(true){
- if (getOthers() > 3){
- coshakMod();
- }
- //
- setAdjustRadarForRobotTurn(true);
- setTurnRadarRight(36000); // okrecemo
- // radar 10 puta u krug
- }
- }
- public void coshakMod(){
- final double M = 50;
- double maxX = getBattleFieldWidth();
- double maxY = getBattleFieldHeight();
- double x;
- double y;
- ahead(M);
- x = getX();
- y = getY();
- if ( (maxX - x) <= M + getHeight() ){
- turnRight(90);
- } else if ( (maxY - y) <= M + getHeight()){
- turnRight(90);
- } else if ( x <= M + getHeight()) {
- turnLeft(90);
- } else if ( y <= M + getHeight() ){
- turnRight (90);
- }
- }
- public void onHitRobot(HitRobotEvent event) {
- turnRight(180);
- ahead(100);
- }
- public void onScannedRobot(ScannedRobotEvent e) {
- // okrenimo se ka skeniranom protivniku
- if(getOthers() > 3){
- setTurnRight(e.getBearing());
- setFire(3);
- }
- else {
- // Lock on to our target (this time for sure)
- setTurnRight(e.getBearing());
- // move a little closer
- if (e.getDistance() > 200)
- setAhead(e.getDistance() / 2);
- // but not too close
- if (e.getDistance() < 100)
- setBack(e.getDistance());
- // shoot at him
- setFire(3);
- // wobble the radar to generate another scan event
- scanDirection *= -1;
- setTurnRadarRight(36000 * scanDirection);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement