EDITED BECAUSE I SUDDENLY HAD SOME TIME TO PUT MORE WORK INTO ROBO
So I finally moved on from Robo Katas to actual robots who fight other robots. It was pretty enjoyable watching them go at it, even if my robot did stupid things sometimes. I realized that what often seem like pretty simple concepts come out to be not so easy. Especially, my inability to use trigonometry was astounding. Anyway, I tried to make a robot that could defeat a couple of the sample ones that come with the standard Robocode: Walls, RamFire, SpinBot, Crazy, Fire, Corners, Tracker, and SittingDuck.
So I finally moved on from Robo Katas to actual robots who fight other robots. It was pretty enjoyable watching them go at it, even if my robot did stupid things sometimes. I realized that what often seem like pretty simple concepts come out to be not so easy. Especially, my inability to use trigonometry was astounding. Anyway, I tried to make a robot that could defeat a couple of the sample ones that come with the standard Robocode: Walls, RamFire, SpinBot, Crazy, Fire, Corners, Tracker, and SittingDuck.
As for movement, I tried to do a couple of things, some of which worked better than others. When hit, my robot is supposed to move perpendicularly to the bullet (in an attempt to dodge the next wave of bullets) This worked out pretty well, and all the robots that sat around firing had a lot more trouble connecting. But later I realized that if I'm too close to an enemy robot, it won't matter if I move because the bullet will hit me anyway. So i checked to see if dodging was feasible before making the attempt and wasting attack time. Next, I tried to monitor what the other robot was doing with its energy. If it suddenly dropped where 0 < x < 3 I assumed it was shooting a bullet at me and tried to dodge out of the way. This worked a couple times, but because I had trouble tracking, sometimes it didn't work out.
Targetting was my most complex task, and the one that I wish I had put a little more time in to. For the stationary targets, hitting them was not a problem, but for the moving ones like WALLS, I had to try and predict where it would be. This involves knowing where it is, how fast it's going, how fast your bullets go, and how long it takes you to turn. Everything has to be calculated almost exactly or you'll whiff.
UPDATE:The problem I had when I first wrote this blog was finding the time that my bullet would connect at, I felt that you needed to know the time to find the future location and you needed the future location to determine the time! So in the end I picked an estimated time, calculated the point a robot could linearly get to in that period and then checked to see if my bullet would reach it at the same time. If it didn't, I modified my time and tried again. This way, I was able to find the time that my robot's bullet and the enemy would coincide at. So linear targetting I mostly have down except I don't count for gun turn delay which matters sometimes when the robot is really close and can get past the predicted spot quickly.
When it comes to circular targetting, I know it has something to do with the velocity and radius with some trigonometry to figure out where it's going to be, but I ended up getting my equations wrong or something because the robot just shoots in the general direction.
When it comes to circular targetting, I know it has something to do with the velocity and radius with some trigonometry to figure out where it's going to be, but I ended up getting my equations wrong or something because the robot just shoots in the general direction.
For firing, I noticed that when I fought the stationary robots who often used weaker bullets, if I just used the strongest, I could damage race them until they died. Certainly not the most elegant but it worked out in that case. I should've changed how I shot trickier targets in an effort to save energy.
UPDATE: In the end, I decided to continue risking it all with full power shots as much as possible, with the hopes that I would heal up all my misses from earlier (shooting makes you lose energy and hitting your target makes you gain). It started to do that more because of my linear targetting, but it still means I lose a lot against spinning robots.
UPDATE: In the end, I decided to continue risking it all with full power shots as much as possible, with the hopes that I would heal up all my misses from earlier (shooting makes you lose energy and hitting your target makes you gain). It started to do that more because of my linear targetting, but it still means I lose a lot against spinning robots.
Out of all the robots, I had trouble with Crazy, Walls, and Spinbot. The rest were either stationary or came straight at me, in which case my targeting and power shots were able to easily handle them. I feel that out of all of them, crazy was the hardest to predict because of the inconsistent ways it moved. But my win rate against it was usually a little better than half, probably because it's crazy and doesn't aim very well... for the other two that methodically moved and attacked me, I had more trouble. Both had recognizable patterns and I'm sure I could've worked it to the point where I could hit them every time, but for some reason I had a bug that I didn't have time to work out. Walls just went around the edge of the arena shooting inwards but i still had trouble! Because my predictive measures are off, I spend most of the fight missing and wasting precious energy. The other thing about prediction is knowing what kind of movement you're looking for. If i used the linear style from Walls on Spinbot, everything would miss because I'd end up shooting around the circle that it takes. Another alternative would be to "metagame." Knowing I might be facing Spinbot I could develop a specialized strategy for him. Mainly, if I back up far enough from it and don't use any prediction, many times the bot will circle right into my bullets. But I felt that it would be better to make a robot robust in all situations as I'm not competing for money or anything against a specialized crowd.
UPDATE: Walls was mostly taken care of with predictive targetting and I started on Spinbot but wasn't able to get it down perfectly.
UPDATE: Walls was mostly taken care of with predictive targetting and I started on Spinbot but wasn't able to get it down perfectly.
UPDATE: After putting a little more complexity into my robot, I decided that it would be useful to have some test cases. I was thinking about what kind of cases to make, I could look at certain behaviors but my robot was mostly point and shoot, move occassionally. He didn't really have any major strategy that I could easily check for. But because I started separating methods and helper methods, I was able to test those to make sure they are working as they're supposed to. And it turned out to be pretty useful! In one spot I subtracted instead of added which caused my robot to shoot in the opposite direciton occassionally. I noticed it, but wasn't too interested in looking through all the code to find it, but after testing the methods one by one, I was able to easily spot it. Testing is great! Although sometimes it causes problems on its own. Coming up with tests and writing them took more work than I would have liked.
If I ever decided to take up some more Robocode, I would definitely give myself more time. How often I forget how easy it is to lose yourself in a project and end up with no sleep! Also, my code started getting a little messy part way through so I think next time I should plan everything out instead of haphazardly adding features to the robot as I think of them. Or at least rather than plan everything, have everything neatly packed away in methods and objects.
UPDATE: This hasn't changed at all. I always want more time :P
Overall, Robocode is something I think is quite enjoyable and many students or software designers would probably get a kick out of battling their robots against each other. The level of sophistication possible and the sheer addiction of building a better robot are what keeps this project going.
No comments:
Post a Comment