Thursday, September 16, 2010

Competitive Robot: RiceMusubi

Overview
          After learning basics movements, targeting and strategies on previous Robocode assignments,  I created my own robot that will hopefully outlast the sample robots (Walls, RamFire, SpinBot, Crazy, Fire,  Corners, Tracker, SittingDuck) in the Robocode. This would help my robot to prepare in the coming competition in class. Below is the summary of my robot's design strategy.

Design  

Movement  
          The basic strategy for movement is just to keep on moving. It is evident from the sample robot, specifically the sample Walls robot that not staying on one place and moving in a certain distance would be very effective in dodging enemy bullets. When my robot finds and enemy, it moves its body parallel to the enemy and will 150 pixels forward but will try to maintain its position parallel to the other robot. This movement sometimes results to my robot circling around the other robot and effectively dodging the enemy's fire. In an event that my robot hits the wall, it will run towards the center of the battlefield to avoid getting cornered. And will then do its original movement.

Targeting
          For the targeting strategy, I adapted my previous robot's behavior- Boom04. It scans the nearest enemy robot and it uses its gun to keep track of that robot. The idea is to keep the gun pointing towards the enemy at all times. To be able to do this, I need to make sure that the gun and the body of my robot are able to move independently.

Firing
For the fire power, I adapted the behavior of my previous robot (Boom03), which uses its distance from the enemy to figure out how much fire power the bullets should have. The nearest the enemy, the highest the fire power will be use. As soon as my robot found another robot, it'll start shooting and will keep shooting.
    Results

              To be able to test my robot against other robots, I used the sample robots that are available in the Robocode program. Below are the results of the test.

    vs SittingDuck:
              This is a no competition, as this robot doesn't do anything. Any robot that can target and fire would win against this robot. My robot won 100% of the time.

    vs Fire:
              This robot is a pretty hard opponent against my robot. Although my robot moves a lot, the Fire robot was able to hit it a couple times before it could get away because of the number of bullets this robot fires at a time. My robots has a big disadvantage because it can only fire after it moves while this robot just sits and can keep firing. It only moves when it gets hit which makes it a hard target since my robot fires on its opponents previous position. My robot won 41% of the time.

    vs Corner:
              This robot is similar to Fire, the only difference is  this just stays in the corner and never moves. It is much easier target. My robot won 58% of the time.

    vs Crazy:
              This robot is a very hard target for my robot. That only weakness of this robot is it doesn't fire as much. It is also worth mentioning that this robot extends AdvancedRobot. My robot won 48% of the time.

    vs Tracker:
               This is a perfect opponent to show off my robots agility. My robot pretty much dodge every bullet the this thing throws. My robot won 64% of the time

    vs Spinbot:
               Similar to Tracker, my robot just pretty much dodge every bullet this thing fires. Its only advantage is it uses the maximum amount of fire power every time it fires. This is also another advanced robot. My robot won 60% of the time.

    vs RamFire:
              This is very hard to beat for my robot. My robot lost only because of the damage it cost when it rams and is pretty much dead when cornered. My robot won 35% of the time.

    vs Walls:
              My robot never had a chance on this robot. This is the robot to beat, that's why most of the other students based their robot from this. It's a very hard target. My robot never won a round.

    Conclusion
              Robocode is easiest and best way to learn programming. It not only teaches me but it also showed me that programming could be fun too. This experience thought how to be really a better programmer. It thought me read and understand APIs which. It made realize that programming takes time and I better start doing it earlier to be able to create and develop a better program. All in all, this assignment is really fun, ans I might actually like programming now. 

    Download:
     RiceMusubi Eclipse Package
     RiceMusubi robot jar file

    Tuesday, September 14, 2010

    Robocode

    For the third programming assignment in ICS 413, we were asked to write codes for 13  different robots all having different behaviors. We used an open source programming game called Robocode. Its main goal is to create a robot/tank using java and battle against other creators and developers. It is more than a programming game since it also teaches users java programming.

    The installation of the program is pretty straight forward. It has tutorials on how to develop robots using Eclipse, which helped a lot since we're already familiar with it. The program itself can be found at http://robocode.sourceforge.net/ and tutorials  in this comprehensive wiki among many others available online.

    Here are the following robots that we have to develop:
    • Position01: The minimal robot.  Does absolutely nothing at all.
    • Position02: Move forward a total of 100 pixels per turn.  When you hit a wall, reverse direction.
    • Position03: Each turn, move forward a total of N pixels per turn, then turn right.  N is initialized to 15, and increases by 15 per turn.
    • Position04: Move to the center of the playing field, spin around in a circle,  and stop.
    • Position05: Move to the upper right corner.  Then move to the lower left corner.  Then move to the upper left corner. Then move to the lower right corner.
    • Position06: Move to the center, then move in a circle with a radius of approximately 100 pixels, ending up where you started.
    • Follow01: Pick one enemy and follow them.
    • Follow02: Pick one enemy and follow them, but stop if your robot gets within 50 pixels of them.
    • Follow03: Each turn, Find the closest enemy, and move in the opposite direction by 100 pixels, then stop.
    • Boom01: Sit still.  Rotate gun.  When it is pointing at an enemy, fire.
    • Boom02: Sit still.  Pick one enemy.  Only fire your gun when it is pointing at the chosen enemy.
    • Boom03:  Sit still. Rotate gun.  When it is pointing at an enemy, use bullet power proportional to the distance of the enemy from you. The farther away the enemy, the less power your bullet should use (since far targets increase the odds that the bullet will miss). 
    • Boom04: Sit still.  Pick one enemy and attempt to track it with your gun. In other words, try to have your gun always pointing at that enemy.  Don't fire (you don't want to kill it). 
     I expected these assignment to be programming intensive but I didn't expect math to play a role in this. I never had trigonometry for more than a decade so I had to brush up on it before I even touch the keyboard. Position04 is the first challenging robot to develop. I had to relearned Pyhtagorean theorem. Here are the pseudocode for this robot:
     
            1. Get the coordinates of the center of the battlefield
                 -this requires to get the width and length of the battlefield and divide each by two.
            2. Get the position of the robot and subtract from the given x & y coordinates
            3. Use Pythagorean theorem to find the angle to the destination the robot should turn.
           4. The use Pythagorean theorem again to compute the distance to the destination.

    But wait there's more.......

    I also need to figure out which quadrant the robot is at to be able to compute how much it need to turn the robot to face the center and then go forward. 

    The Boom01 trough 04 are probably the easiest set of robots to develop. This are also the most fun part, because I get to fire at the other robots. The whole Eclipse package of my work can be download here.

    All in all, this assignment reminded me on how fun and frustrating programming is. It's fun when you were able to see the finish program, but it's guaranteed that you will have lots of frustrations to get there and see your creations comes alive. It also reminded me that robots are very cool, but useless without humans. With the help of these robots, now I can get started with my competitive robot and test its ability with others.....