1

I am trying to compile the robot on the robocode, but It said that "static imports are only available if source level is 1.5 or greater"

I did not understand what it means. I saw in others forums that can be the update of Java, but my computer already have the last Java installed. What can I do?

This is the code that I tried to compile:

package blir.dev; 

import robocode.*;

import java.awt.Color;

import static robocode.util.Utils.*; 

/** 
* Blixi - a robot by Travis Bruce 
*/
public class Keen_Stalker extends AdvancedRobot { 

//the direction we're moving 
private int dir = 1; 
//are we close to a wall? : are we close to a robot?
private boolean wall = false, rbt = false; 
//enemy's energy 
private double en = 100D; 

/** 
 * run: Blixi's default behavior 
 */
public void run() { 
    setColors(Color.BLACK, Color.DARK_GRAY, Color.DARK_GRAY); 
    setAdjustRadarForRobotTurn(true); 
    setAdjustGunForRobotTurn(true); 
    setAdjustRadarForGunTurn(true); 
    //if (bshot1 != 0) out.println("Main Gun Accuracy: " + (double) bhit1 / bshot1);
    for (;;) { 
        if (getRadarTurnRemaining() == 0) { 
            //should only happen if we lose track of them, which should never happen 
            setTurnRadarRight(Double.POSITIVE_INFINITY); 
        } 
        //check if we're too close to the wall (50 pixels) 
        wall = cw(50, true); 
        execute(); 
    } 
} 

/** 
 * onScannedRobot: What to do when you see another robot 
 */
public void onScannedRobot(ScannedRobotEvent e) { 

    //check if we're too close to the other robot (150 pixels) 
    rbt = d(e.getDistance()); 

    //absolute bearing
    double absBear = getHeadingRadians() + e.getBearingRadians(); 

    //track them with our radar 
    double radarTurn = normalRelativeAngle(absBear - getRadarHeadingRadians()); 
    radarTurn += (radarTurn < 0 ? -1 : 1) * Math.atan(36.0 / e.getDistance()); 
    setTurnRadarRightRadians(radarTurn); 

    //fire power the enemy used
    double enemyPower = en - e.getEnergy();

    if (enemyPower <= 3 && enemyPower > 0 && !cw(75, false)) { 
        //they seem to have fired
        cd(); 
    } 

    //record new energy 
    en = e.getEnergy(); 

    //circle around them if we're close enough, move away if we're too close
    setTurnRightRadians(normalRelativeAngle(e.getBearingRadians() + Math.PI / 2D)); 

    setTurnGunRightRadians(normalRelativeAngle(absBear - getGunHeadingRadians() -
            Math.asin(e.getVelocity() * Math.sin(Math.PI - absBear + e.getHeadingRadians()) / Rules.getBulletSpeed(Rules.MAX_BULLET_POWER)))); 

    //fire! 
    setFire(Rules.MAX_BULLET_POWER); 

    //all power ahead! 
    setAhead(dir * 32);
} 

public void onHitWall(HitWallEvent e) { 
    //out.println("Ahh! A wall!"); 
    cd(); 
}  

private boolean d(double d) { 
    if (d < 150) { 
        //we're close to the robot (within 150 pixels) 
        if (!rbt) { 
            //we're not already escaping the robot, so let's change direction 
            cd(); 
        } 
        return true; 
    } 
    return false; 
} 

private boolean cw(int d, boolean cw) { 
    if (getX() < d || getY() < d || getBattleFieldWidth() - getX() < d || getBattleFieldHeight() - getY() < d) { 
        //we're close to the wall 
        if (!wall && cw) { 
            //we're not already escaping the wall, so let's change direction 
            cd(); 
        } 
        return true; 
    } 
    return false; 
} 

private void cd() { 
    dir = -dir; 
}                                                                                          
luator
  • 4,769
  • 3
  • 30
  • 51

3 Answers3

1

A quick fix is to remove import static robocode.util.Utils.* (the construct import static was introduced in Java 1.5 see here: https://docs.oracle.com/javase/1.5.0/docs/guide/language/static-import.html) and use Utils.normalRelativeAngle etc...

A proper fix is to find out why do you have source level set to something less then 1.5

David Soroko
  • 8,521
  • 2
  • 39
  • 51
0

I am not sure that you checked other answers or not, but please check following link.

eclipse magic: ... Syntax error, varargs are only available if source level is 1.5 or greater

There are bunch of things that you can try.

Hope this help.

harry
  • 240
  • 3
  • 10
0

Add this remark in the Robocode compiler options: -source 1.5

->Compiler Options [-deprecation -g -source 1.5 -encoding UTF-8]

Patrick Schocke
  • 1,493
  • 2
  • 13
  • 25
raaa
  • 1
  • 1