Help understanding a bot!!

View: New views
2 Messages — Rating Filter:   Alert me  

Help understanding a bot!!

by swarner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Im very new to robocode and need a bit of help understanding what exactally a specific bot is doing and why its doing it!!

could some kind person please take a look at the following bot and try to explain in plain english what the bot will do, tactics, responses to events etc. sorry im very new!!

..............................................................................................................................................
package sw;
import robocode.*;
import java.awt.Color;

/**
 * robo - simple bot, but very effective against sample bots.
 */
public class robo extends AdvancedRobot
{
        int turnDirection = 1; //clockwise or not]
        int direction = 1; //forward or backward
       
        /**
         * run: robo's default behavior
         */
        public void run() {
                setAdjustRadarForRobotTurn(true);
                setAdjustGunForRobotTurn(true);
                       
            setBodyColor(Color.black);
                setGunColor(Color.orange);
                setRadarColor(Color.black);
                setBulletColor(Color.red);
                setScanColor(Color.green);
                                while(true) {
                        setTurnRadarRight(360);
                        setAhead(150 * direction);
                        if(direction == 1) {
                                direction = -1;
                        } else {
                                direction = 1;
                        }
                       
                        waitFor(new TurnCompleteCondition(this));
                }
        }

        /**
         * onScannedRobot: What to do when you see another robot
         */
        public void onScannedRobot(ScannedRobotEvent e) {
                setTurnRadarRight(getHeading() - getRadarHeading() + e.getBearing());
               
                if ((getHeading() - getGunHeading() + e.getBearing()) < 180) {
                          turnGunRight(getHeading() - getGunHeading() + e.getBearing());
                } else { turnGunRight(getHeading() - getGunHeading() + e.getBearing() - 360);
                }
               
                if (getEnergy() < 8) {
                        fire(1.5);
                } else {
                        fire(3);
                }
               
        scan();
               
               
        }

        /**
         * onHitByBullet: What to do when you're hit by a bullet
         */
        public void onHitByBullet(HitByBulletEvent e) {
                //turn
                setTurnRight(e.getBearing() + ( 45 * turnDirection));
                waitFor(new TurnCompleteCondition(this));
                //turn further and drive away
                setTurnRight( 45 * turnDirection);
                setAhead(150);
                waitFor(new TurnCompleteCondition(this));
                //switch direction for next time
                if (turnDirection == 1) {
                        turnDirection = -1;
                } else {
                        turnDirection = 1;
                }
               
               
               
        }
       
}
..............................................................................................................................................


thanks in advance for any help!!

for example if you could tell me what this if statement meant:
if ((getHeading() - getGunHeading() + e.getBearing()) < 180) {
                          turnGunRight(getHeading() - getGunHeading() + e.getBearing());

Re: Help understanding a bot!!

by Eggplant :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


if ((getHeading() - getGunHeading() + e.getBearing()) < 180) {
                          turnGunRight(getHeading() - getGunHeading() + e.getBearing())
}

That basically means if when the event (which shortens to e) happens, if the direction of your bot - the directon of your gun + the direction of the event is less than 180, than the bot will turn its turret right an equivalent amount to the direction of the bot - the direction of the gun + the direction of the event, which would point the gun in the direction of the event.