Menu

#52 Extra hit wall events

1.2.2
closed
5
2012-10-12
2006-11-27
Titus Chen
No

After running the following code 100000 times, I found that there is roughly a 17% probability that extra hit wall events will be generated:

public void run()
{
turnLeft(getHeading() - 180);
ahead(Double.POSITIVE_INFINITY);
turnRight(90);
ahead(Double.POSITIVE_INFINITY);
turnRightRadians(Math.random() * Math.PI / 2);
ahead(Double.POSITIVE_INFINITY);
}
public void onHitWall(HitWallEvent e)
{
System.out.println("Hit Wall");
}

The only effect of this problem is the generation of extra hit wall events due to trig rounding issues. Teleporting does NOT result; thus, I don't think this bug needs immediate attention. Also, very few (if any) robots are affected due to the nature of the problem.

The following code, if inserted at line 344, should solve the trig precision issue:

x = (HALF_WIDTH_OFFSET >= x) ? HALF_WIDTH_OFFSET : ((getBattleFieldWidth() - HALF_WIDTH_OFFSET < x) ? getBattleFieldWidth() - HALF_WIDTH_OFFSET : x);
y = (HALF_HEIGHT_OFFSET >= y) ? HALF_HEIGHT_OFFSET : ((getBattleFieldHeight() - HALF_HEIGHT_OFFSET < y) ? getBattleFieldHeight() - HALF_HEIGHT_OFFSET : y);

Discussion

  • Titus Chen

    Titus Chen - 2006-11-27

    Logged In: YES
    user_id=1653970
    Originator: YES

    Using a similar test in the upper left corner of a 5000 height battle field, I found that 49% of 100000 tries failed.

     
  • Titus Chen

    Titus Chen - 2006-12-07

    Logged In: YES
    user_id=1653970
    Originator: YES

    After figuring out how to download and compile the robocode source files using Eclipse, I experimented with this fix. As far my tests can tell, these two lines eliminate Wall collision problems.

     
  • Flemming N. Larsen

    Logged In: YES
    user_id=1249353
    Originator: NO

    This has been fixed in the current 1.2.2 Beta release

     

Log in to post a comment.