Menu

#366 receiving enemy's real name on HitByBulletEvent

1.9.1.0
closed
1
2014-03-22
2014-01-10
No

tested on Robocode 1.8.3.0 (and also seen on current beta version)

If rule "Hide Enemy Names" is activated there is one case in which one robot can see its own anonymous name and the original name of the enemy robot.
This is when the robot is getting hit by a bullet.

Looking at the source code shows that there is just one single bullet object which will be transfered to both victim and shooter:

in File "BulletPeer.java"
in Function "checkRobotCollision"

Bullet bullet = createBullet(false);
...
otherRobot.addEvent(new HitByBulletEvent(..., bullet));
...
owner.addEvent(new BulletHitEvent(..., bullet));

Discussion

  • Flemming N. Larsen

    Nice work. You found an error, and you even found the exact spot in the code where the error occurs. =)

     

    Last edit: Flemming N. Larsen 2014-01-10
  • Flemming N. Larsen

    I believe that this code

    Bullet bullet = createBullet(false);
    
    otherRobot.addEvent(new HitByBulletEvent(
        robocode.util.Utils.normalRelativeAngle(heading + Math.PI -
            otherRobot.getBodyHeading()), bullet));
    
    owner.addEvent(new BulletHitEvent(owner.getNameForEvent(otherRobot),
        otherRobot.getEnergy(), bullet));
    

    ... must be replaced with this code

    otherRobot.addEvent(new HitByBulletEvent(
        robocode.util.Utils.normalRelativeAngle(heading + Math.PI -
            otherRobot.getBodyHeading()), createBullet(true)));
    
    owner.addEvent(new BulletHitEvent(owner.getNameForEvent(otherRobot),
        otherRobot.getEnergy(), createBullet(false)));
    
     
  • Flemming N. Larsen

    This has now been fixed for the final version 1.9.0.0.

     
  • Anonymous

    Anonymous - 2014-01-18

    I had a look at the code changes. Function "checkRobotCollision" seems to be correct now, but I don't understand why function "createBullet" was also modified within this bugfix. I think the old version of "createBullet" was okay. See for example the call of "createBullet" in function "checkWallCollision".

     
  • Flemming N. Larsen

    I will definitely have an extra look on this one later (in a couple of days). The bug might have been fixed for this issue, but introduces bugs with the checkRobotCollision() etc. So I need a fullblown test taking all robot events into account regarding robot names. Perhaps the use of createBullet() is not good enough as it must act different in various situations. Perhaps two methods are required or something else. I will loon into this and make sure it is fixed properly before the final version of 1.9.0.0. :-)

     
  • Flemming N. Larsen

    I have now reworked the implementation (fix) for this issue. The method createBullet() now takes two parameters: hideOwnerName and hideVictimName that they can be specified individually without any form of indirect dependency. :-)

    I have tested all relevant event handler using this robot:

    package test;
    import robocode.*;
    
    public class Test extends Robot {
    
        public void run() {
            while(true) {
                ahead(100);
                turnGunRight(360);
                back(100);
                turnGunRight(360);
            }
        }
    
        public void onScannedRobot(ScannedRobotEvent e) {
            out.println("ScannedRobot: Enemy: " + e.getName());
            fire(1);
        }
    
        public void onHitByBullet(HitByBulletEvent e) {
            out.println("HitByBullet: Enemy: " + e.getName());
            back(10);
        }
    
        public void onBulletHitBullet(BulletHitBulletEvent e) {
            out.println("BulletHitBullet: Me: " + e.getBullet().getName() + ", Enemy: " + e.getHitBullet().getName());
        }
    
        public void onBulletMissed(BulletMissedEvent e) {
            out.println("BulletMissed: Me: " + e.getBullet().getName());
        }
    
        public void onBulletHit(BulletHitEvent e) {
            out.println("BulletHit: Me: " + e.getBullet().getName() + ", Enemy: " + e.getName());
        }
    
        public void onHitRobot(HitRobotEvent e) {
            out.println("HitRobot: Enemy: " + e.getName());
        }
    
        public void onRobotDeath(RobotDeathEvent e) {
            out.println("RobotDeath: " + e.getName());
        }
    
        public void onHitWall(HitWallEvent e) {
            back(20);
        }   
    }
    
     
  • Flemming N. Larsen

    Fixed with version 1.9.0.0 just released.

     
    • Anonymous

      Anonymous - 2014-02-23

      The problem is still not fixed correctly.

      For testing please print also the names within the bullet object, like this:

          public void onHitByBullet(HitByBulletEvent e) {
              out.println("HitByBullet: Enemy: " + e.getName());
      out.println("--> HitByBullet: Bullet.owner: " + e.getBullet().getName() + "  Bullet.vicitm: " + e.getBullet().getVictim());
              back(10);
          }
      
          public void onBulletHit(BulletHitEvent e) {
              out.println("BulletHit: Me: " + e.getBullet().getName() + ", Enemy: " + e.getName());
      out.println(" --> BulletHit: Bullet.owner: " + e.getBullet().getName() + ", Bullet.victim: " + e.getBullet().getVictim());
          }
      

      As I have seen in the source code, the following has to be changed to fix the problem:

      in BulletPeer.java, function "checkRobotCollision":

      replace

      createBullet(true, true)));
      

      with

      createBullet(true, false)));
      

      and

      replace

      createBullet(false, false)));
      

      with

      createBullet(false, true)));
      
       
  • Flemming N. Larsen

    Reopened as the issue does not seem to be fixed 100% after all.

    Thanks again for reviewing my work and checking if all had been fixed. Without your validation check, the remaining issue would not have been found so easily. :-)

     
  • Flemming N. Larsen

    • status: closed --> open
     
  • Flemming N. Larsen

    You are right again. I fixed it, and changed the to use this code again:

        private Bullet createBullet(boolean hideOwnerName) {
            String ownerName = (owner == null) ? null : (hideOwnerName ? getNameForEvent(owner) : owner.getName());
            String victimName = (victim == null) ? null : (hideOwnerName ? victim.getName() : getNameForEvent(victim));
    
            return new Bullet(heading, x, y, power, ownerName, victimName, isActive(), bulletId);
        }
    

    That is, now we only need one parameter, as the 2nd parameter introduced with the previous fix was always the opposite of the 1st parameter.

    The new test robot looks like this:

    package test;
    import robocode.*;
    
    public class Test extends Robot {
    
        public void run() {
            while(true) {
                ahead(100);
                turnGunRight(360);
                back(100);
                turnGunRight(360);
            }
        }
    
        public void onScannedRobot(ScannedRobotEvent e) {
            out.println("ScannedRobot: Enemy: " + e.getName());
            fire(1);
        }
    
        public void onHitByBullet(HitByBulletEvent e) {
            out.println("HitByBullet: Enemy: " + e.getName());
            out.println("--> HitByBullet: Bullet.owner: " + e.getBullet().getName() + "  Bullet.vicitm: " + e.getBullet().getVictim());
            back(10);
        }
    
        public void onBulletHitBullet(BulletHitBulletEvent e) {
            out.println("BulletHitBullet: Me: " + e.getBullet().getName() + ", Enemy: " + e.getHitBullet().getName());
        }
    
        public void onBulletMissed(BulletMissedEvent e) {
            out.println("BulletMissed: Me: " + e.getBullet().getName());
        }
    
        public void onBulletHit(BulletHitEvent e) {
            out.println("BulletHit: Me: " + e.getBullet().getName() + ", Enemy: " + e.getName());
            out.println(" --> BulletHit: Bullet.owner: " + e.getBullet().getName() + ", Bullet.victim: " + e.getBullet().getVictim());
        }
    
        public void onHitRobot(HitRobotEvent e) {
            out.println("HitRobot: Enemy: " + e.getName());
        }
    
        public void onRobotDeath(RobotDeathEvent e) {
            out.println("RobotDeath: " + e.getName());
        }
    
        public void onHitWall(HitWallEvent e) {
            back(20);
        }   
    }
    
     
  • Flemming N. Larsen

    The new fix has been commit to GitHub. :-)

     
  • Flemming N. Larsen

    • status: open --> closed
    • Group: 1.9.0.0 --> 1.9.1.0
     
  • Flemming N. Larsen

    Fixed in Robocode 1.9.1.0

     

Log in to post a comment.