Interface IBot

  • All Superinterfaces:
    IBaseBot
    All Known Implementing Classes:
    Bot

    public interface IBot
    extends IBaseBot
    Interface for a bot that extends the core API with convenient methods for movement, turning, and firing the gun.
    • Method Detail

      • run

        default void run()
        The run() method is used for running a program for the bot like:
        
         public void run() {
           while (isRunning()) {
             forward(100);
             turnGunLeft(360);
             back(100);
             turnGunRight(360);
           }
         }
         

        Note that the program runs in a loop in this example (as long as the bot is running), meaning that it will start moving forward as soon as turnGunRight(double) has executed.

        When running a loop that could potentially run forever. The best practice is to check if the bot is still running to stop and exit the loop. This gives the game a chance of stopping the thread running the loop in the code behind. If the thread is not stopped correctly, the bot may behave strangely in new rounds.

        See Also:
        isRunning()
      • isRunning

        boolean isRunning()
        Checks if this bot is running.
        Returns:
        true when the bot is running, false otherwise.
      • setForward

        void setForward​(double distance)
        Set the bot to move forward until it has traveled a specific distance from its current position, or it is moving into an obstacle. The speed is limited by IBaseBot.setMaxSpeed(double).

        When the bot is moving forward, the Constants.ACCELERATION determines the acceleration of the bot that adds 1 additional unit to the speed per turn while accelerating. However, the bot is faster at braking. The Constants.DECELERATION determines the deceleration of the bot that subtracts 2 units from the speed per turn.

        This method will first be executed when IBaseBot.go() is called making it possible to call other set methods before execution. This makes it possible to set the bot to move, turn the body, radar, gun, and also fire the gun in parallel in a single turn when calling IBaseBot.go(). But notice that this is only possible to execute multiple methods in parallel by using setter methods only prior to calling IBaseBot.go().

        If this method is called multiple times, the last call before IBaseBot.go() is executed, counts.

        This method will cancel the effect of prior calls to IBaseBot.setTargetSpeed(double) as the setForward and setBack(double) methods calls the IBaseBot.setTargetSpeed(double) for each turn until getDistanceRemaining() reaches 0.

        Parameters:
        distance - is the distance to move forward. If negative, the bot will move backward. If Double.POSITIVE_INFINITY the bot will move forward infinitely. If Double.NEGATIVE_INFINITY the bot will move backward infinitely.
        See Also:
        forward(double), setBack(double), back(double), getDistanceRemaining(), IBaseBot.setTargetSpeed(double)
      • forward

        void forward​(double distance)
        Moves the bot forward until it has traveled a specific distance from its current position, or it is moving into an obstacle. The speed is limited by IBaseBot.setMaxSpeed(double).

        When the bot is moving forward, the Constants.ACCELERATION determine the acceleration of the bot that adds 1 additional unit to the speed per turn while accelerating. However, the bot is faster at braking. The Constants.DECELERATION determines the deceleration of the bot that subtracts 2 units from the speed per turn.

        This call is executed immediately by calling IBaseBot.go() in the code behind. This method will block until it has been completed, which can take one to several turns. New commands will first take place after this method is completed. If you need to execute multiple commands in parallel, use setter methods instead of this blocking method.

        This method will cancel the effect of prior calls to IBaseBot.setTargetSpeed(double), setForward(double), and setBack(double) methods.

        Parameters:
        distance - is the distance to move forward. If negative, the bot will move backward. If Double.POSITIVE_INFINITY the bot will move forward infinitely. If Double.NEGATIVE_INFINITY the bot will move backward infinitely.
        See Also:
        setForward(double), setBack(double), back(double), getDistanceRemaining(), IBaseBot.setTargetSpeed(double)
      • setBack

        void setBack​(double distance)
        Set the bot to move backward until it has traveled a specific distance from its current position, or it is moving into an obstacle. The speed is limited by IBaseBot.setMaxSpeed(double).

        When the bot is moving forward, the Constants.ACCELERATION determines the acceleration of the bot that adds 1 additional unit to the speed per turn while accelerating. However, the bot is faster at braking. The Constants.DECELERATION determines the deceleration of the bot that subtracts 2 units from the speed per turn.

        This method will first be executed when IBaseBot.go() is called making it possible to call other set methods after execution. This makes it possible to set the bot to move, turn the body, radar, gun, and also fire the gun in parallel in a single turn when calling IBaseBot.go(). But notice that this is only possible to execute multiple methods in parallel by using setter methods only prior to calling IBaseBot.go().

        If this method is called multiple times, the last call before IBaseBot.go() is executed, counts.

        This method will cancel the effect of prior calls to IBaseBot.setTargetSpeed(double) as the setForward(double) and setBack methods calls the IBaseBot.setTargetSpeed(double) for each turn until getDistanceRemaining() reaches 0.

        Parameters:
        distance - is the distance to move backward. If negative, the bot will move forward. If Double.POSITIVE_INFINITY the bot will move backward infinitely. If Double.NEGATIVE_INFINITY the bot will move forward infinitely.
        See Also:
        back(double), setForward(double), forward(double), getDistanceRemaining(), IBaseBot.setTargetSpeed(double)
      • back

        void back​(double distance)
        Moves the bot backward until it has traveled a specific distance from its current position, or it is moving into an obstacle. The speed is limited by IBaseBot.setMaxSpeed(double).

        When the bot is moving forward, the Constants.ACCELERATION determine the acceleration of the bot that adds 1 additional unit to the speed per turn while accelerating. However, the bot is faster at braking. The Constants.DECELERATION determine the deceleration of the bot that subtracts 2 units from the speed per turn.

        This call is executed immediately by calling IBaseBot.go() in the code behind. This method will block until it has been completed, which can take one to several turns. New commands will first take place after this method is completed. If you need to execute multiple commands in parallel, use setter methods instead of this blocking method.

        This method will cancel the effect of prior calls to IBaseBot.setTargetSpeed(double), setForward(double), and setBack(double) methods.

        Parameters:
        distance - is the distance to move backward. If negative, the bot will move forward. If Double.POSITIVE_INFINITY the bot will move backward infinitely. If Double.NEGATIVE_INFINITY the bot will move forward infinitely.
        See Also:
        setForward(double), setBack(double), forward(double), getDistanceRemaining(), IBaseBot.setTargetSpeed(double)
      • getDistanceRemaining

        double getDistanceRemaining()
        Returns the distance remaining till the bot has finished moving after having called setForward(double), setBack(double), forward(double), or back(double). When the distance remaining has reached 0, the bot has finished its current move.

        When the distance remaining is positive, the bot is moving forward. When the distance remaining is negative, the bot is moving backward.

        Returns:
        The remaining distance to move before its current movement is completed. If Double.POSITIVE_INFINITY the bot will move forward infinitely. If Double.NEGATIVE_INFINITY the bot will move backward infinitely.
        See Also:
        setForward(double), setBack(double), forward(double), back(double)
      • setTurnLeft

        void setTurnLeft​(double degrees)
        Set the bot to turn to the left (following the increasing degrees of the unit circle) until it turned the specified amount of degrees. That is, when getTurnRemaining() is 0. The amount of degrees to turn each turn is limited by IBaseBot.setMaxTurnRate(double).

        This method will first be executed when IBaseBot.go() is called making it possible to call other set methods after execution. This makes it possible to set the bot to move, turn the body, radar, gun, and also fire the gun in parallel in a single turn when calling IBaseBot.go(). But notice that this is only possible to execute multiple methods in parallel by using setter methods only prior to calling IBaseBot.go().

        If this method is called multiple times, the last call before IBaseBot.go() is executed, counts.

        This method will cancel the effect of prior calls to setTurnRight(double).

        Parameters:
        degrees - is the amount of degrees to turn left. If negative, the bot will turn right. If Double.POSITIVE_INFINITY the bot will turn left infinitely. If Double.NEGATIVE_INFINITY the bot will turn right infinitely.
        See Also:
        Unit circle, setTurnRight(double), turnRight(double), turnLeft(double), getTurnRemaining(), IBaseBot.setTurnRate(double)
      • setTurnRight

        void setTurnRight​(double degrees)
        Set the bot to turn to the right (following the decreasing degrees of the unit circle) until it turned the specified amount of degrees. That is, when getTurnRemaining() is 0. The amount of degrees to turn each turn is limited by IBaseBot.setMaxTurnRate(double).

        This method will first be executed when IBaseBot.go() is called making it possible to call other set methods after execution. This makes it possible to set the bot to move, turn the body, radar, gun, and also fire the gun in parallel in a single turn when calling IBaseBot.go(). But notice that this is only possible to execute multiple methods in parallel by using setter methods only prior to calling IBaseBot.go().

        If this method is called multiple times, the last call before IBaseBot.go() is executed, counts.

        This method will cancel the effect of prior calls to setTurnLeft(double).

        Parameters:
        degrees - is the amount of degrees to turn right. If negative, the bot will turn left. If Double.POSITIVE_INFINITY the bot will turn right infinitely. If Double.NEGATIVE_INFINITY the bot will turn left infinitely.
        See Also:
        setTurnLeft(double), turnRight(double), turnLeft(double), getTurnRemaining(), IBaseBot.setTurnRate(double)
      • getTurnRemaining

        double getTurnRemaining()
        Returns the remaining turn in degrees till the bot has finished turning after having called setTurnLeft(double), setTurnRight(double), turnLeft(double), or turnRight(double). When the turn remaining has reached 0, the bot has finished turning.

        When the turn remaining is positive, the bot is turning to the left (along the unit circle). When the turn remaining is negative, the bot is turning to the right.

        Returns:
        The remaining degrees to turn before its current turning is completed. If Double.POSITIVE_INFINITY the bot will turn left infinitely. If Double.NEGATIVE_INFINITY the bot will turn right infinitely.
        See Also:
        setTurnLeft(double), setTurnRight(double), turnLeft(double), turnRight(double)
      • fire

        void fire​(double firepower)
        Fire the gun in the direction as the gun is pointing.

        Note that your bot is spending energy when firing a bullet, the amount of energy used for firing the bullet is taken from the bot. The amount of energy loss is equal to firepower.

        If the bullet hits an opponent bot, you will gain energy from the bullet hit. When hitting another bot, your bot will be rewarded and retrieve an energy boost of 3x firepower.

        The gun will only fire when the firepower is at Constants.MIN_FIREPOWER or higher. If the firepower is more than Constants.MAX_FIREPOWER, the power will be truncated to the max firepower.

        Whenever the gun is fired, the gun is heated and needs to cool down before it can fire again. The gun heat must be zero before the gun can fire (see IBaseBot.getGunHeat(). The gun heat generated by firing the gun is 1 + (firepower / 5). Hence, the more firepower used the longer it takes to cool down the gun. The gun cooling rate can be read by calling IBaseBot.getGunCoolingRate().

        The amount of energy used for firing the gun is subtracted from the bots total energy. The amount of damage dealt by a bullet hitting another bot is 4x firepower, and if the firepower is greater than 1 it will do an additional 2 x (firepower - 1) damage.

        The firepower is truncated to Constants.MIN_FIREPOWER and Constants.MAX_FIREPOWER if the firepower exceeds these values.

        This call is executed immediately by calling IBaseBot.go() in the code behind. This method will block until it has been completed, which can take one to several turns. New commands will first take place after this method is completed. If you need to execute multiple commands in parallel, use setter methods instead of this blocking method.

        This method will cancel the effect of prior calls to IBaseBot.setFire(double).

        Parameters:
        firepower - is the amount of energy spent on firing the gun. You cannot spend more energy than available from the bot. The bullet power must be greater than Constants.MIN_FIREPOWER.
        See Also:
        IBaseBot.onBulletFired(dev.robocode.tankroyale.botapi.events.BulletFiredEvent), IBaseBot.setFire(double), IBaseBot.getGunHeat(), IBaseBot.getGunCoolingRate()
      • stop

        void stop()
        Stop all movement including turning the gun and radar. The remaining movement is saved for a call to IBaseBot.setResume() or resume(). This method has no effect, if it has already been called.

        This call is executed immediately by calling IBaseBot.go() in the code behind. This method will block until it has been completed, which can take one to several turns. New commands will first take place after this method is completed. If you need to execute multiple commands in parallel, use setter methods instead of this blocking method.

        See Also:
        resume(), IBaseBot.setResume(), IBaseBot.setStop()
      • stop

        void stop​(boolean overwrite)
        Stop all movement including turning the gun and radar. The remaining movement is saved for a call to IBaseBot.setResume() or resume().

        This call is executed immediately by calling IBaseBot.go() in the code behind. This method will block until it has been completed, which can take one to several turns. New commands will first take place after this method is completed. If you need to execute multiple commands in parallel, use setter methods instead of this blocking method.

        Parameters:
        overwrite - is set to true if the movement saved by a previous call to this method or IBaseBot.setStop() must be overridden with the current movement. When set to false this method is identical to IBaseBot.setStop().
        See Also:
        resume(), IBaseBot.setResume(), IBaseBot.setStop()
      • resume

        void resume()
        Resume the movement prior to calling the IBaseBot.setStop() or stop() method. This method has no effect, if it has already been called.

        This call is executed immediately by calling IBaseBot.go() in the code behind. This method will block until it has been completed, which can take one to several turns. New commands will first take place after this method is completed. If you need to execute multiple commands in parallel, use setter methods instead of this blocking method.

        See Also:
        stop(), IBaseBot.setStop(), IBaseBot.setResume()
      • rescan

        void rescan()
        Scan (again) with the radar. This method is useful if the radar has not been turning and thereby will not be able to automatically scan bots. This method is useful when the bot movement has stopped, e.g. when stop() has been called. The last radar direction and sweep angle will be used for rescanning for bots.
        See Also:
        stop()