The first step that I did to create Ver. 1.1 of the BlackMagic robot was to use a build system (Ant) to run tests and error check it. I used the following commands to ensure my code was up to date and error free:
ant -f checkstyle.build.xml
ant -f pmd.build.xml
ant -f findbugs.build.xml
CheckStyle:
During my first run of CheckStyle I ran into the following errors:
Got an exception - java.lang.IllegalArgumentException: the name [date] is not a valid Javadoc tag name
Missing package-info.java file.
The 2nd error was easily fixed by copying and modifying the package.html into /src/smw from the DaCruzer package.
After fixing that error I ran CheckStyle again and encountered the following errors on multiple occasions:
'{' is not preceded with whitespace.
Missing a Javadoc comment.
'while' is not followed by whitespace.
First sentence should end with a period.
Unused @param tag for 'a'.
Expected @param tag for 'e'.
The spacing error and the Javadoc comment errors were easily taken care of. The @param errors were taken care of by adding in the input variable name to the @param comment. For example a method takes (onHitWall e) so the comment is too look like this @param e .... but my comments were formatted in the following way @param .... with out the variable name.
After fixing these errors I ran CheckStyle again and had the following error remaining:
Missing package-info.java file.
This was easily fixed by adding in the overview.html file to /src.
Upon running CheckStyle again I encountered no errors.
PMD:
Luckily PDM built with no errors.
FindBugs:
Just like PMD this target built with no errors.
Improved Performance:
After loosing in the 2nd round of the Robocode tournament to a walls based robot and seeing how many robots were based on the walls model, I realized that I needed to integrate an anti-walls section to my robot. However this was extremely hard to implement given BlackMagic's current movement scheme, so instead I added a method which increased my victory percentage against walls, but I was still unable to consistently beat walls. My hope is that BlackMagic Ver. 1.1 will be able to beat other non-wall based robots more effectively.
Distribution:
The latest version of BlackMagic can be found here.
Monday, September 28, 2009
Monday, September 21, 2009
Competition Robot
Design:
The design for this robot's movement is stemmed from a math error that I made while attempting another design. At first I hoped the have the robot move to the top middle, then move down in a 45 degrees, turn around go back up and then go down the other side at a 45 degree angle, repeating this movement pattern until the end of the match. However due to a math error, I found that I could make the robot's movement erratic, so I decided to keep this design. The downside is that the robot will sometimes follow it's previous path, thus making it susceptible to being hit from shots that were fired behind it.
The shooting design of this robot is meant to hit moving targets. It seems that this robot is most accurate while making turns, however it does have an ability to hit targets on the run due to a change in turret's position. When up close with the enemy, this robot will fire, move back, turn and fire again then continue moving around the battlefield.
My robot named BlackMagic can be found here.
Victory:
This robot can effectively beat the following sample robots: Corners, Fire, SittingDuck, Crazy, SpinBot and Tracker. This is due to the fact that many of these are stationary, or the fact that the movement pattern of my robot is able to evade most of the shots fired and it was able to return fire with a high rate of success.
Defeat:
My robot is unable to reliably beat the following robots: Walls and RamFire. It seems that walls moves too fast for my distance shots to be effective and also the when my robot repeats it's movements it literally runs into bullets fired by walls. As for RamFire, my robot does not have an effective way to get out of being cornered by RamFire. If the battle is kept in the middle of the field my robot usually can win. However when the battle moves to the sides it usually gets trapped and RamFire is able to take advantage of that and finish off my robot.
Lessons Learned:
After analyzing the battles, I realized that I need a more effective strategy to deal with robots that corner or force my robot to the edges, where they can do huge amounts of damage. Also I learned that an inconsistent movement really works in evading fire from the enemy, however retracing the route that the robot just executed could have disastrous results as it may run into bullets that were previously fired by an enemy robot.
The design for this robot's movement is stemmed from a math error that I made while attempting another design. At first I hoped the have the robot move to the top middle, then move down in a 45 degrees, turn around go back up and then go down the other side at a 45 degree angle, repeating this movement pattern until the end of the match. However due to a math error, I found that I could make the robot's movement erratic, so I decided to keep this design. The downside is that the robot will sometimes follow it's previous path, thus making it susceptible to being hit from shots that were fired behind it.
The shooting design of this robot is meant to hit moving targets. It seems that this robot is most accurate while making turns, however it does have an ability to hit targets on the run due to a change in turret's position. When up close with the enemy, this robot will fire, move back, turn and fire again then continue moving around the battlefield.
My robot named BlackMagic can be found here.
Victory:
This robot can effectively beat the following sample robots: Corners, Fire, SittingDuck, Crazy, SpinBot and Tracker. This is due to the fact that many of these are stationary, or the fact that the movement pattern of my robot is able to evade most of the shots fired and it was able to return fire with a high rate of success.
Defeat:
My robot is unable to reliably beat the following robots: Walls and RamFire. It seems that walls moves too fast for my distance shots to be effective and also the when my robot repeats it's movements it literally runs into bullets fired by walls. As for RamFire, my robot does not have an effective way to get out of being cornered by RamFire. If the battle is kept in the middle of the field my robot usually can win. However when the battle moves to the sides it usually gets trapped and RamFire is able to take advantage of that and finish off my robot.
Lessons Learned:
After analyzing the battles, I realized that I need a more effective strategy to deal with robots that corner or force my robot to the edges, where they can do huge amounts of damage. Also I learned that an inconsistent movement really works in evading fire from the enemy, however retracing the route that the robot just executed could have disastrous results as it may run into bullets that were previously fired by an enemy robot.
Wednesday, September 16, 2009
Sample Code Analysis
To better understand the samples provided with the Robocode package, I will be analyzing 8 sample robots in the areas of movement, tracking and firing.
Walls:
Movement: Regardless of starting position this robot will always face the the nearest wall with the least angle movement to face the wall. The robot will then head to that wall and move to the closest corner. From there the robot will move clockwise around the walls of the arena. If this robot hits another it will reverse, do a left turn then head to the nearest wall, move to the corner and continue moving along the walls.
Targeting: There is no targeting algorithm for this robot. Simply if a robot is scanned this robot will open fire on it.
Firing: The only criteria for firing is when a robot is scanned.
RamFire:
Movement: Movement is determined by the enemy robot's position. Once an enemy is scanned the RamFire will then move up to it and ram into it. In the case that the robot has moved, RamFire will follow it.
Targeting: The tank moves until it scans a robot then the gun is pointed at the enemy.
Firing: Firing is initiated once the RamFire has rammed into the robot it is targeting. Firing continues until the enemy moves.
SpinBot:
Movement: SpinBot moves in circles continuously in one spot.
Targeting: There is no targeting algorithm besides scanning.
Firing: SpinBot fires when a enemy robot is scanned.
Crazy:
Movement: This robot will move forward and turn right, but keep moving while making the right turn, then it will turn 180 degrees to the left while still moving, after that the robot makes a 180 degree right turn while moving. This process is repeated forever. When it hits a wall the direction is reversed.
Targeting: There is no targeting algorithm besides scanning.
Firing: Crazy fires when an enemy robot is scanned.
Fire:
Movement: This robot only moves when it is hit in which case it makes a right turn and moves 50 pixels the first time. With each hit the amount moved decreases by 1 pixel.
Targeting: There is no targeting algorithm besides scanning.
Firing: If Fire has more than 50 energy and the enemy is less than 50 pixels away, the robot will fire at power 3, else it only fires at power 1.
Sitting Duck:
Movement: This robot doesn't move.
Targeting: This robot doesn't target other robots.
Firing: This robot doesn't fire on enemy robots.
Corners:
Movement: Regardless of the robots position, it will turn to face the north wall, go to the wall and make a left turn and move all the way to the top left corner.
Targeting: There is no targeting algorithm besides scanning.
Firing: Corners fires proportional to the distance of the enemy or current energy level. In the first case if the enemy's distance is less than 200 or the energy level is greater than 15, the robot will fire at power one. If the enemy robot's distance is less than 50 Corners will fire at power 2. Otherwise the robot will fire at power 3.
Tracker:
Movement: Tracker's movement rate is determined by the enemy that it is tracking. Once Tracker finds an enemy, it will move to 140 pixels of its position and either wait or fire on the enemy robot. Also if the enemy is too close (within 100 pixels) Tracker will move back in the enemy has a position of less than -90 degrees and equal or less than 90 degrees. Else it moves ahead 40 pixels.
Targeting: Once the enemy is scanned the gun will move to face the enemy. It will re-rotate every time Tracker is tracking an enemy.
Firing: The gun will always fire at the power of 3.
Conclusion:
I think that a lot of basic structures for movement and tracking can be learned from these sample robots. I know while designing my robots I would often look to these sample robots to gain inspiration or to review and adapt algorithms that were used.
Walls:
Movement: Regardless of starting position this robot will always face the the nearest wall with the least angle movement to face the wall. The robot will then head to that wall and move to the closest corner. From there the robot will move clockwise around the walls of the arena. If this robot hits another it will reverse, do a left turn then head to the nearest wall, move to the corner and continue moving along the walls.
Targeting: There is no targeting algorithm for this robot. Simply if a robot is scanned this robot will open fire on it.
Firing: The only criteria for firing is when a robot is scanned.
RamFire:
Movement: Movement is determined by the enemy robot's position. Once an enemy is scanned the RamFire will then move up to it and ram into it. In the case that the robot has moved, RamFire will follow it.
Targeting: The tank moves until it scans a robot then the gun is pointed at the enemy.
Firing: Firing is initiated once the RamFire has rammed into the robot it is targeting. Firing continues until the enemy moves.
SpinBot:
Movement: SpinBot moves in circles continuously in one spot.
Targeting: There is no targeting algorithm besides scanning.
Firing: SpinBot fires when a enemy robot is scanned.
Crazy:
Movement: This robot will move forward and turn right, but keep moving while making the right turn, then it will turn 180 degrees to the left while still moving, after that the robot makes a 180 degree right turn while moving. This process is repeated forever. When it hits a wall the direction is reversed.
Targeting: There is no targeting algorithm besides scanning.
Firing: Crazy fires when an enemy robot is scanned.
Fire:
Movement: This robot only moves when it is hit in which case it makes a right turn and moves 50 pixels the first time. With each hit the amount moved decreases by 1 pixel.
Targeting: There is no targeting algorithm besides scanning.
Firing: If Fire has more than 50 energy and the enemy is less than 50 pixels away, the robot will fire at power 3, else it only fires at power 1.
Sitting Duck:
Movement: This robot doesn't move.
Targeting: This robot doesn't target other robots.
Firing: This robot doesn't fire on enemy robots.
Corners:
Movement: Regardless of the robots position, it will turn to face the north wall, go to the wall and make a left turn and move all the way to the top left corner.
Targeting: There is no targeting algorithm besides scanning.
Firing: Corners fires proportional to the distance of the enemy or current energy level. In the first case if the enemy's distance is less than 200 or the energy level is greater than 15, the robot will fire at power one. If the enemy robot's distance is less than 50 Corners will fire at power 2. Otherwise the robot will fire at power 3.
Tracker:
Movement: Tracker's movement rate is determined by the enemy that it is tracking. Once Tracker finds an enemy, it will move to 140 pixels of its position and either wait or fire on the enemy robot. Also if the enemy is too close (within 100 pixels) Tracker will move back in the enemy has a position of less than -90 degrees and equal or less than 90 degrees. Else it moves ahead 40 pixels.
Targeting: Once the enemy is scanned the gun will move to face the enemy. It will re-rotate every time Tracker is tracking an enemy.
Firing: The gun will always fire at the power of 3.
Conclusion:
I think that a lot of basic structures for movement and tracking can be learned from these sample robots. I know while designing my robots I would often look to these sample robots to gain inspiration or to review and adapt algorithms that were used.
Saturday, September 12, 2009
Robo Revisions
Revisions:
Reviewing other student's code allowed me to adapt more effective solutions to my robots especially the robot that needed to move to the center. Now instead of going to the corner and then half way down the height and moving half way across the width, I now have a solution to move to the middle from any point. As I suspected the Pythagorean Theory was the key, however I was unable to implement it correctly in my first try. My modified robots jar file can be downloaded here.
Coding Standards:
Until now I only thought of coding standards as ways for me to better organize my own code for my own reference. However now that we are reviewing other students code I realized that coding standards play a key role. Without these standards understanding others code could have the potential to be a daunting task. Also coding standards requires comments which further allows others to understand your methods and the coding in the main method.
Reviewing other student's code allowed me to adapt more effective solutions to my robots especially the robot that needed to move to the center. Now instead of going to the corner and then half way down the height and moving half way across the width, I now have a solution to move to the middle from any point. As I suspected the Pythagorean Theory was the key, however I was unable to implement it correctly in my first try. My modified robots jar file can be downloaded here.
Coding Standards:
Until now I only thought of coding standards as ways for me to better organize my own code for my own reference. However now that we are reviewing other students code I realized that coding standards play a key role. Without these standards understanding others code could have the potential to be a daunting task. Also coding standards requires comments which further allows others to understand your methods and the coding in the main method.
Wednesday, September 9, 2009
Robowars!
In preparation for an all out robowar I have successfully created a series of 13 basic robots that outlined basic functions a serious robot should have such as tracking enemies, firing on enemies as well as basic movement behavior. The coding for my robots can be found here.
The requirements for designing sample robots is as follows:
Movement:
I had no problems coding the first 3 movement robots and the onHitWall even made it really easy to program the second robot. However the trouble came when I had to have the robot move to the center of the field (the 4th movement). Immediately I suspected that some sort of triangulation via the Pythagorean Theorem however after numerous tries I was unable to figure out how to consistently triangulate the center so instead I had the robot move to the left top corner, move half way down the move half way in. The next problem was with the 6th movement. Using the previously mentioned I was able to get the robot to the center, however I had problems moving in a circle without using the AdvancedRobot methods, so instead I used a for loop and created a slow moving circle.
Tracking:
I was kind of lost when it came to the tracking methods, so I borrowed and modified code from the tracking.java sample robot from the Robocode files. After reviewing and analyzing the code in order to understand it, tracking became easier to understand and it was easier to modify the code that I had borrowed.
Firing:
Again like the tracking methods I was unsure of how to use the firing methods so I borrowed some code from the fire.java sample robot to get me started. Just like the tracking robot I analyzed the code to understand it, then began to modify the coding appropriately. The hardest part about the firing section robots was the Firing03 robot which required fire power proportional to the distance of the enemy. The further away the less power was to be used. In order to do this I took the max fire power for the robot (which happens to be 3) and then took 3% of the distance to the enemy and subtracted it from three thus creating the desired fire rates.
Conclusion:
It took a while for me to understand the coding for tracking however once I got the hang of it things were a lot easier to code. At first I thought there was a tracking method call, but I realized that robots automatically scan and that in order to track I needed to use the onScannedRobot method call. Also I realized that geometry will play a huge part in creating a successful robot as geometry influences movement, firing and even tracking an enemy robot. With that said I think its time for me to hit the books to review my geometry.
The requirements for designing sample robots is as follows:
- Movement01: The minimal robot. Does absolutely nothing at all.
- Movement02: Move forward a total of 50 pixels per turn. If you hit a wall, reverse direction.
- Movement03: Each turn, move forward a total of N pixels per turn, then turn left. N is initialized to 10, and increases by 10 per turn.
- Movement04: Move to the center of the playing field and stop.
- Movement05: Move to the upper left corner. Then move to the lower right corner. Then move to the upper right corner. Then move to the lower left corner.
- Movement06: Move to the center, then move in a circle, ending up where you started.
- Tracking01: Pick one enemy and follow them.
- Tracking02: Pick one enemy and follow them, but stop if your robot gets within 20 pixels of them.
- Tracking03: Each turn, Find the closest enemy, and move in the opposite direction by 100 pixels, then stop.
- Firing01: Sit still. Rotate gun. When it is pointing at an enemy, fire.
- Firing02: Sit still. Pick one enemy. Only fire your gun when it is pointing at the chosen enemy.
- Firing03: 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).
- Firing04: 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).
Movement:
I had no problems coding the first 3 movement robots and the onHitWall even made it really easy to program the second robot. However the trouble came when I had to have the robot move to the center of the field (the 4th movement). Immediately I suspected that some sort of triangulation via the Pythagorean Theorem however after numerous tries I was unable to figure out how to consistently triangulate the center so instead I had the robot move to the left top corner, move half way down the move half way in. The next problem was with the 6th movement. Using the previously mentioned I was able to get the robot to the center, however I had problems moving in a circle without using the AdvancedRobot methods, so instead I used a for loop and created a slow moving circle.
Tracking:
I was kind of lost when it came to the tracking methods, so I borrowed and modified code from the tracking.java sample robot from the Robocode files. After reviewing and analyzing the code in order to understand it, tracking became easier to understand and it was easier to modify the code that I had borrowed.
Firing:
Again like the tracking methods I was unsure of how to use the firing methods so I borrowed some code from the fire.java sample robot to get me started. Just like the tracking robot I analyzed the code to understand it, then began to modify the coding appropriately. The hardest part about the firing section robots was the Firing03 robot which required fire power proportional to the distance of the enemy. The further away the less power was to be used. In order to do this I took the max fire power for the robot (which happens to be 3) and then took 3% of the distance to the enemy and subtracted it from three thus creating the desired fire rates.
Conclusion:
It took a while for me to understand the coding for tracking however once I got the hang of it things were a lot easier to code. At first I thought there was a tracking method call, but I realized that robots automatically scan and that in order to track I needed to use the onScannedRobot method call. Also I realized that geometry will play a huge part in creating a successful robot as geometry influences movement, firing and even tracking an enemy robot. With that said I think its time for me to hit the books to review my geometry.
Subscribe to:
Posts (Atom)