This is the first time I have ever worked with Robocode and I actually find it to be really fun. Doing to tasks that involve planning the movement of the robot are really refreshing my memory on Trigonometry. I also haven't worked too much with Java lately so working on this assignment is really helpful.
Here is my checklist for the assignment:
-
Position01: The minimal robot. Does absolutely nothing at all.
Creating this robot was beyond simple; all I had to do was create an empty class. -
Position02: Move forward a total of 100 pixels per turn. When you hit a wall, reverse direction.
This robot was also relatively simple, though it required me to look in the API for the onHitWall() event. -
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.
The one was still pretty easy, just took some very simple incrementing. -
Position04: Move to the center of the playing field, spin around in a circle, and stop.
I decided to have a little fun with this one. I saw that a lot of people were making the robot face north then move up on the y-axis till it was centered and then move along the x-axis till it was in the center of the map. I wanted to give myself a bit of a challenge and make the robot make one diagonal move to the center as opposed to two moves along the y and x axis. It took me about ten minutes to work it out on pencil and paper. I took the following approach:
- I check the quadrant the bot is in
- I face the bot north
- If the bot is in the upper two quadrants I rotate it to face south
- I calculate the angle using the following formula: angle = arctan(opposite/adjacent)
- Rotate toward center using angle found in previous step
- I calculate the distance needed to travel using the Pythagorean Theorem: c = sqrt(a^2+b^2)
- I move ahead the distance calculated in the previous step
-
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.
This used similar mechanics as Position04 so this was still very basic as far as the programming went. -
Position06: Move to the center, then move in a circle with a radius of approximately 100 pixels, ending up where you started.
Again, this was a build off Position04. The only semi-difficult part was getting the robot to follow a path with a radius of 100 pixels. -
Follow01: Pick one enemy and follow them.
At first I was lost on this but I was able to look at the Tracker robot, which was provided with Robocode, as inspiration. After reviewing the Tracker robot which did something similar I was able to piece together which events and methods I needed to make this robot work. -
Follow02: Pick one enemy and follow them, but stop if your robot gets within 50 pixels of them.
This was just a build off of Follow01; it was just a matter of adding an if statement which check if the robot was within 50 pixels. -
Follow03: Each turn, Find the closest enemy, and move in the opposite direction by 100 pixels, then stop.
At first I was a bit stressed about this one, because I couldn't figure out how to detect the closest enemy. After researching a bit I discovered that the onScannedRobot method actually returns the closest robot. This made things a lot easier; all I had to do was rotate towards the detected robot and back away 100 pixels. I also decided to check when a wall was hit, because the bot would repeatedly smash into the wall when I didnt. -
Boom01: Sit still. Rotate gun. When it is pointing at an enemy, fire.
This was one of the simpler robots to code; it just took a little research. All this one does is spin its radar to detect an enemy, when it does it fires its gun. -
Boom02: Sit still. Pick one enemy. Only fire your gun when it is pointing at the chosen enemy.
This robot is nearly the same as Boom01 except it picks one enemy and only shoots at that enemy. I had to add a variable which stores the name of the enemy, and every time an enemy is scanned it just compares the name to make sure it's the same 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).
This robot posed a slight challenge. I decided to calculate the max distance obtainable in the arena and then detect how far the enemy was relative to the max distance. Based on that information I have the robot fire with power relative to the distance of the enemy. -
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).
This was a pretty simple task, all I had to do was rotate the radar continuously to scan for the target robot. When the target robot is detected I just have my robot turn its gun towards it. This is updated every time the enemy is scanned so it is updated constantly.
No comments:
Post a Comment