Menu

#90 Prevent JuniorRobot to be unresponsive

1.7.1.1
closed
Robot (1)
7
2012-10-08
2009-01-11
No

This is a request from Nutch Poovarawan sent by email for me:

Alright, let's look at this snippet.

void run() {
}

If a make a Junior Robot with this code, when it run, it will do
nothing, and send no command to Robocode, after some time, Robocode
will kill it. It's normal behavior. So if I want my robot to just
stand still like SittingDuck, I need to use this code.

void run() {
doNothing();
}

This is absolutely normal, and user should figure it out. However, if
the code get some more complicated, like this.

void run() {
if (scannedDistance <= 200)
fire();
}

In this case, the inexperience user will just assume that the robot
would do nothing when the enemy is out of range. And the robot will
wait until another robot come close enough, then fire.

However, this code will make the robot unresponsive, and Robocode will
terminate it after a few seconds. And the conditional statement will
stop working, robot will do nothing even the condition are met. And in
the end, user will just not understand why?

Of course, the very simple way to solve this is

void run() {
if (scannedDistance <= 200)
fire();
else
doNothing();
}

But in real world teaching experience, it's still too complex for new
students to understand the conditional branch. So I think the
JuniorRobot should do something like this.

while(true) {
int lastTurn = currentTurn;
run() //This is where JuniorRobot usually invoke it run() method.
if (lastTurn == currentTurn) //It's mean the robot do nothing in run.
doNothing(); //Then just simply skip a turn.
}

If you have any further question, please don't hesitate to ask me more about it.

Thanks!
Nutch

Discussion

  • Flemming N. Larsen

    Hi Nutch,

    I am finally working on improving the JuniorRobot, and there will be several
    improvements:

    1) Bugfix, so that event variables like scannedXXX and hitXXX will be set
    to -1 (or -99) when nothing is scanned or hit. No bug report has ever been
    made about this issue, but it now this bug has been fixed, so that the
    variables are reset probably.

    2) I am implementing your fix (see our mails below), so the JuniorRobots are
    not hanging in this situation:

    void run() {
    if (scannedDistance >= 0 && scannedDistance <= 200)
    fire();
    }

    You proposed this solution for it:

    while(true) {
    int lastTurn = currentTurn;
    run() //This is where JuniorRobot usually invoke it run() method.
    if (lastTurn == currentTurn) //It's mean the robot do nothing in run.
    doNothing(); //Then just simply skip a turn.
    }

    This is a good solution, but I have improved it a bit:

    while(true) {
    int lastTurn = currentTurn;
    run() //This is where JuniorRobot usually invoke it run() method.
    if (lastTurn == currentTurn) //It's mean the robot do nothing in run.
    rescan(); //Spend a turn on scanning enemies
    }

    This means that "if (scannedDistance >= 0 && scannedDistance <= 200)" will
    be able to detect enemies even when standing still. Normally a robot has to
    move it's body, turret, radar etc. in order to "see anything". This is not
    necessary with the JuniorRobot anymore. ;-)

    If you want to try it out, I will upload Robocode 1.7.2 Alpha version for
    you.

     
  • Flemming N. Larsen

    Fixed with the release of Robocode 1.7.1.1.

     
  • SourceForge Robot

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 14 days (the time period specified by
    the administrator of this Tracker).

     

Anonymous
Anonymous

Add attachments
Cancel





MongoDB Logo MongoDB