identifying why the robot doesn't fire

In my previous post I am now issuing instructions to the robot, but I have some unexpected behaviour in that my assumptions about the way the battle would run must be incorrect.
The behaviour I'm seeing is that at the start of the battle the robot scans 360 degrees but never fires even though I have a Fire() command in my scanned event.

I've already posted about the fact that I have debugging limitations - my assembly is in the GAC and I therefore cannot debug into the robocode process as I used to. So it took me a while to find a way to debug this and here's where I conducted some temporary surgery to try and establish the cause: (only part of the robot code shown)

    public class SlayerRobot : Robot, ImARobot
    {
        public void LookForEnemies()
        {
            DebugProperty["lookForEnemies"] = "true";
            TurnRadarRight(360);
        }

        public override void OnScannedRobot(ScannedRobotEvent evnt)
        {
            DebugProperty["scanned"] = "true";
            Fire(1);
        }   
    }

By adding debug lines through robocode, I can watch the turn snapshot window in the robocode GUI (via the "Main battle log" button) as the turns progress and see these debugging messages appear at runtime. You have to be quick or have it paused and progress one turn turn at a time, because these debug properties appear only for the turn they were issued in.

lookForEnemiesDebug

In turn 1, I can see that my robot is indeed looking for enemies.

scannedDebug

In turn 11, my robot does recognise another robot, but my Fire() code obviously doesn't take effect.

I remember reading on the wiki that the "guns start hot" and after some searching I find in the games physics page:

GunHeat generated: 1 + firepower / 5. You cannot fire if gunHeat > 0.
All guns are hot at the start of each round.

So either wasn't paying enough attention for missing that or its not an obvious start of battle limitation. Either way I can verify that this is the cause of my robot's dormancy with some extra surgical code:

    public class SlayerRobot : Robot, ImARobot
    {
        public void LookForEnemies()
        {
            DebugProperty["lookForEnemies"] = "true";
            DebugProperty["gunheat"] = GunHeat.ToString();
            TurnRadarRight(360);
        }

        public override void OnScannedRobot(ScannedRobotEvent evnt)
        {
            DebugProperty["scanned"] = "true";
            DebugProperty["gunheat"] = GunHeat.ToString();
            Fire(1);
        }   
    }

I then get the following debug output:

lookForEnemiesDebug2

The gun heat is 2.9 at the start of turn 1.

scannedDebug2

The gun heat still hasn't cooled right down, its only down to 2 by turn 10.

Therefore I need to do a bit more work in keeping the state of the robot that was scanned until such time as I can fire.

As I look into this and think about new observables I would need, I make what I consider a massive leap forward in my thinking for this project so need to stop and re-assess what I've done so far.

Eric Evans called this a breakthrough when "refactoring toward deeper insight":

"Each refinement of code and model gives developers a clearer view. This clarity creates the potential for a breakthrough of insights"

In introducing these observables and through the debugging process above I've discovered some new insights into the layout of my code and want to introduce a different structure.
My next post will break from code and attempt to illustrate my new thought process behind my robot.



0 comments: