1

Do you know, how can I get a RobotState of my robot in Robocode? I would like to get an information for example, if my robot is active, alive, dead etc. In debug mode is it possible to see that information, but how can I get this in my code?

enter image description here

Kris
  • 1,538
  • 2
  • 16
  • 27
  • 1
    Post your code? You can use the methods listed in the link you gave. You can just call isAlive() to see if it's alive and so on... if rossRobot.isAlive() { doSomethingHere } – RossC Sep 04 '13 at 09:38
  • 1
    currentRobot.getState() ? – Danny. Sep 04 '13 at 09:41

1 Answers1

0

The enum RobotState is only used in the core of RoboCode. There is no getState() method for your robot. (i digged through the source code)

However: you can get all theses state in other ways:

If your robot is hitting a wall, a HitWall event is fired. you can handle those events by overriding a method in your robot class:

@Override
public void onHitWall(HitWallEvent e)
{
    //your code
}

same with hitting a robot:

@Override
public void onHitRobot(HitRobotEvent e)
{
    //your code
}

if your robot dies:

@Override
public void onRobotDeath(RobotDeathEvent event) 
{
    //salute your warrior
    //your code
}

and if it's alive it should still loop in your runs method:

@Override
public void run() {
    do {
         //here you do the normal stuff a robot does
    } while(true);
}

You can look at even more event methods in this interfaces:

Philipp Sander
  • 10,139
  • 6
  • 45
  • 78