Thursday, September 16, 2010

09.CompetitiveRobot

Design 
  • Movement
    • Bubonic will immediately goto the closest side on the horizontal plane.
    • Once there, Bubonic will move forward in increments determined by (absolute difference between the its current Y coordinate and the enemy's previous Y coordinate + 75) units/(set of actions) creating a stutter effect. A normal tracking robot will have difficulty hitting Bubonic due this function creating dynamic movement.
    • This serves as a way to quickly catch up to a robot moving in the vertical plane. By doing so, Bubonic can catch up to a robot before it decides to move horizontally closer. Bubonic is confident in its long range shooting (more so than close combat).
    • Upon hitting a wall on the vertical plane, the robot will move backward in increments determined by (absolute difference between the its current Y coordinate and the enemy's previous Y coordinate + 75) units/(set of actions)
    • *Note: set of actions={targeting,firing}
    • The generalMovement() method also has proven to allow for quick escape as the distance function often provides large values. These large values cause for dramatic movement and make standard targeting of Bubonic difficult.
    • Also, upon the event of one of Bubonic's bullets hitting an enemy, bubonic will backtrack in the opposite direction from which it was heading. This often causes quite a few misses on the enemies part and can put Bubonic in a better shooting position. In close combat, sometimes a key dodge will prove the difference. However, Bubonic has walked into a few unnecessary bullets as well due to this feature. I still can't decide whether it's worth having it in or not as I have not done any statistical analysis, but it will still be left in for the ICS413 Roborumble.
  • Targeting
    • While on the side wall, Bubonic's radar will scan the 180 degree open field looking for targets.
    • Bubonic implements Non-Iterative Linear Targeting to track and lead its shots on moving enemy robots.
    • It effectively guesses where a target is heading under the assumption that its moving linearly.
    • I have incorporated the noniterative version of linear target tracking which can be found at: http://robowiki.net/wiki/Linear_Targeting
    • However, since Bubonic constantly pans its radar 180 degrees of the open field in a "car-windshield wiper" fashion, it will fire at the first robot it encounters. Since the onScannedRobot event contains the velocity, distance, and bearing, one can derive a guess at to where the enemy robot is heading. It should be noted that I had to modify the code as it had been made for an advanced robot. This involved changing setTurnGunRightRadians(radians) to the form of turnGunRight(degrees). A Math.toDegrees() function was necessary at this step.
    • It should be noted that Bubonic's targeting is best used in group skirmish, due to it not locking onto any particular target. But against one target, it still does fine.
    • If one were to improve Bubonic's targeting system for 1v1, the "car-windshield wiper" should take into account the last bearing and degree relative to where the gun is pointing and adjust the area of radar sweep to minimize the unnecessary scanning of the rest of the field.
  • Firing
    • Firing is heavily intertwined with targeting. 
    • The Linear Targeting allows for Bubonic to fire a leading shot on enemy robots moving in a straight line (linearly). 
    • In short, triangles are being made each time the onScannedRobot event gets triggered. The algorithm then uses the velocity, distance, and bearing to generate vectors/sides of these triangles and makes a probable guess to the next position of the robot. It will then take into account the desired bulletpower(most notably the speed of the bullet) to determine a proper trajectory to intercept the next position of the target robot. 
    • Thus, Bubonic will fire on the first robot that is scanned after interpreting various data associated with that enemy robot.
    • The last case the firing system handles is the event in which the target robot stops moving. When this happens, Bubonic will also stop moving and proceed to fire its most powerful bullet at the target until one of the robots is dead.
Results

Bubonic managed to win consistently over all the robots. I had the hardest time with SpinBot as my targeting algorithm works best against bots moving in constant linear fashion. If Spinbot spawned close to the middle of the map, Bubonic would have great difficulty in landing a shot. SpinBot was able to catch Bubonic either at odd angles (ie 180 degrees) or coming out of a corner. Bubonic is most vulnerable at the point when it switches directions at a corner. This allowed lagged shots to often hit Bubonic as it reverses directions.

Bubonic > Walls
Tracker can significantly get the jump on Bubonic which will allow it to start doing damage early. I believe this to be the cause for the single loss to tracker.

In the end, I believe that Bubonic's survivability is greatly determined by the linear targeting and the movement function. Even if Bubonic is having a hard time landing a bullet a robot, it will generally be very hard to hit.

If I were to try to improve upon my design, I would definitely try to implement some sort of pattern matching. This would be used to detect whether an enemy robot is moving in a circle, as apposed to linearly. Bubonic then could try to switch targeting algorithms on the fly to deal with this type of movement.

Lastly, I would have to clean up the way field scanning is done as it's inefficient in it's current state.

  • Here is a link to the Bubonic_1.0.jar file.

Lessons Learned
The 09.CompetitiveRobot exercise was very fun. I played around with many different type of targeting systems while trying to give Bubonic a small edge. The vast majority of targeting styles were developed for the Advanced Robot and it was hard trying to port some of this code into a regular Robot for which the assignment specified. Here are a few of the targeting methods I worked with:


I've managed to get all of these implemented in some form for Bubonic's targeting. The advanced targeting(Guess Factor & Wave) used some heavy statistical analysis. Even when I got it working, I realized that many of the assumptions the algorithm accounts for are impossible for a simple robot. If I had to rank these by simple Robot usability & effectiveness, predictive targeting was 3rd best of these five. Iterative Linear Targeting would be 2nd best, but it wasn't as accurate as the Non-Iterative Linear Targeting. Thus, the best overall was the Non-Iterative Linear Targeting which takes into account the dimensions of the battlefield.

The programming lessons I gained from this experience included mainly how I style my documentation. Most notably, I changed the use of certain types of comments entirely. I often would use "//" comments to redundantly explain what my code was doing. After going through Elements of Java Style, I am now using these comments to abstractly explain what the objective of the code is.

This project also required me to go out and actively learn something new(and review my Trigonometry). This process learning new things is something I am slowly getting better at. Learning a system quickly and being able to implement changes in rapid time is a skill that I'm sure all programmers wish to obtain. I was able to take in the robocode project and make my own unique changes with the system. Research & Development skill + 1! All in all, I enjoyed this open source experience.

One other lesson learned from doing this exercise was properly writing javadocs. I had a general clue as to how to use them and how to generate them, but I had no idea of the standard style to use when writing javadocs. Hopefully my documentation is now up to standard for the class, and it will be seen when reading my source code + generated javadocs.

Monday, September 13, 2010

07.Robocode

Robocode is an open source educational game that Professor Johnson has introduced us to in ICS413. It was originally developed by IBM to show the capabilities of Java in supporting a 2d game engine. However, since leaving the hands of IBM, it has evolved into a great utility for others to learn Java.

The objective of 07.Robocode, introduced by Professor Johnson, was to introduce the class to the experience of actively learning a new java system along with its respective API. We also had to get used to working with the Eclipse IDE along with refreshing our knowledge of intermediate Java.

The objectives of the 12 robot designs are as follows:
  • 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).
Each of the robots provided their own unique challenges, but none took too long to implement. The trickiest part of the whole experience was having to learn how the robots work with bearings and the trigonometry functions needed to navigate the map. Most notably, I had to remember which functions returned radians and which returned degrees.

During the development of the simple robots, I was able to effectively utilize the Eclipse IDE. It provided great interfacing with the javadocs associated with the Robocode project. The means to implement the methods were described by the respective javadocs.

I used the sample robots for general knowledge on how to use the Robocode methods to meet the criteria for the assignment. These could be found in the Robocode installation package. Sample robots, such as the Tracker robot, provided great insight in deciphering method usage as the names of the robots provided intuitive knowledge of what to expect in the source code. The tracker robot tracks, the spin robot spins, and so forth.

The whole process felt very smooth. Whatever errors I encountered were usually displayed/flagged by Eclipse. These could generally be quick-fixed by proper selection from the recommendations provided. Thus, I believe I was able to meet the criteria for all 12 robots. The compressed Java project for 07.Robocode can be found here:


Since developing these sample robots, I now have a decent idea of where to go when designing a competitive robot. I will most likely use the Tracker robot, provided in the Robocode samples, as a template. I am confident that I can now at least create a Robot that will defeat: Walls, RamFire, SpinBot, Crazy, Fire,  Corners, Tracker, & SittingDuck as required by 09.CompetitiveRobot.