First part of this post described how I missed the actual competition but still managed to have loads of fun and come up with my own bot thanks to nice people who have published their bots and made it possible for me to conduct a local tournament. Those who wondering what the Planet Wars is and what the big deal behind this so called AI competition, you can get up to date with all that from here.
In this post, I will mainly discuss the strategies and path I took when designing my bot and the lessons learned.
One of main lessons I learned from this experience is that the precious calculations are always way better than heuristic guesses. Sometimes when the problem is complicated, we tend to invent an obvious looking heuristic ("if my planet's ships are greater than enemy planet ships, attack the enemy with 50% of my strength" for instance) even though it may be the easier option, in the long run, investing our time on preciously calculating and picking our choice is always superior. It was particularly interested to note how heuristics disappeared from my algorithm and replaced by calculations as it was evolving.
Mainly I had 5 steps in my code :
1) Attack : if one or more of my planets can send ships to capture another planet even temporarily, do so. After considering all incoming fleets for the enemy planet, enemy growth over the attacking distance and possible reinforcements enemy can receive from it friends, (if those friends are nearer than my attacking planet that is), if it seems like I can capture the planet, I usually did so. My Planet will not hesitate to even attack with full strength if the enemy planet has a higher growth than itself, Otherwise it will use just the excess ships.
2) Defense : if one of my planets has incoming enemy fleets, I would assemble ships from my nearby planets and reinforce the planet which is under threat. Again all the incoming fleets, my own growth over the enemy attacking distance and reinforcements I can find were included in calculations. Nearby planets were given priority when selecting defenders.
3) Sniping : If an enemy is moving towards a neutral planet, I would try to reach there just after enemy has landed. That way enemy will do all the hard work of destroying the neutral defenders while I will have to fight only with it's depleted remaining forces.
4) Neutral planet hunting : if there are unoccupied planets which are nearer to me than to the enemy and if it is desirable (hear I used a heuristic) to take them, do so.
5) reinforcements : far away planets sending their ships to planets which are nearer to enemy planets.
Beside above, I tried to maintain a minimum force on planets which are nearby to enemy. Amount of that force was calculated by the attacking strength of the nearest enemy and defensive strength of my planets which were nearer to me than the enemy. Any excess above this limit was used in attacks. In defense, defenders trying their best to send enough ships to defend a planet by using their excess forces only.
Some bots were passing there chance on very first turn hoping for sniping chances on their second turn or in fear of being sniped themselves, I guess. I never liked that strategy. In initial moves, I took only the planets which are nearer to me than the enemy. In case of planets which fell in the middle, I chose not to attack them on the very first turn and to leave them for the enemy take, then I tried sniping on 2nd turn. This strategy gave me mixed results. When attacking a neutral planet or when doing a sniping, I did try to calculate the impact of "future planets" on them. That is planets which are not being claimed by either party but very soon will belong to one side. This could be easily deduced by the fleets in motion. Code would explain how this is done. I got few extra rating points after implementing this feature.
Another gray area for me was to decide whether I should change my behavior according to the game status. That is, should I attack less when I'm ahead in growth, should I attack more when I'm behind etc. Experiments on those always gave me mixed results. I eventually concluded that attack whenever it can be done with accuracy is best in most situations. This increased my score against stronger bots.
Few things I haven't implemented : Ideally the bot should compare advantages and disadvantages between an attack and defense. Should I let my planet fall and try to take that enemy planet etc... If I saw a sure attack I always took it and then tried to defend planets with available ships. It would have been cool to have a comparison though.
I gave lowest priority to attacking neutrals at the later stages of the game.
my functions to determine what is the minimum force to take an enemy planet and the minimum force required to defend an own planet was the same. It considered all fleets bound towards that planet, growth and reinforcements from friends. However I did not have any game tree and a mechanism to decide what if I do this, he do that and then I do this etc... I thought that sort of a min max tree approach is not so suitable for something like Planet Wars where problem space was huge and we had to come up with a move within a second. However, I have noted others talking about this any apparently getting some good results as well. I never tried that approach. If we are sensibly reinforced, well defended and always on the look for weaknesses of the enemy while being aggressive at the early stages on neutral hunting, I thought that will be good enough to be within first 100. may be I was correct in that, but then again that may also explain why my bot couldn't reach first 60, for instance.
One very interesting thing I noted was that even some of the stronger bots were not defending themselves properly at times. For instance, when in the opening where both parties have only one planet each, I managed to take the enemy by directly attacking it while it was busy sending fleets for neutrals. This was an easy check to do and guard against, yet most haven't done it and I scored few quick victories with that.
There are lot of finer details I like to discuss but that will grow this post to insane levels. Anyway the shared code should explain lot of things adequately. If anyone has questions/criticisms/suggestions, I would be glad to reply.
Showing posts with label google ai contest. Show all posts
Showing posts with label google ai contest. Show all posts
Sunday, February 20, 2011
Planet Wars - My First AI Contest (part 1)
I can't believe I wasted 2 months on this. I can't believe I comprehensively wasted 2 moths on this at all! (those who have red the blog of the winner, Bocsimacko The Brilliant, will find that phrase little familiar :-) )
It was late when I got to know about Google's AI contest. I have missed the first contest as well, I got to know about the second contest, "Planet Wars" just few days before it ended. Considering the competition was running for over 2 months, that didn't give me much chance to compete effectively. To make the matters even worse, I was to find out (foolishness of me, should have checked that out before everything else!) about the submission deadline just a day before it!
So I ended ended up hurriedly submitting not even the best code I have written in those few days. And the competition was of course a disaster for my Bot. May be I should have satisfied with the results (1200 out of 6000 competitors) of what was made in just 4 days, but something else happened during the final competition.....
I really began to get carried away by the beauty of the game, and the challenge it offered. I just continued development of my bot hoping that the competition server will keep running even after the official competition so that I could still evaluate my bot by playing it against others. Unfortunately, official server was never started after the actual competition. Can't blame the organizers for that. They have provided a wonderful experience and organized a hugely successful competition. What's more, they have made the server software open source. Few people were already running their own TCP servers where others could compete. However, after the competition, even the players seemed they are tired after a competition which ran for over 2 months, and no one was so keen on playing on TCP servers. Even the servers were not available after few days. At least all my attempts to connect to one was ended in failure.
My only remaining option was to download the bots published by others after the competition and play my bot against them in locally arranged tournaments. By this time my bot was improving fast and I was in a hurry to implement all my ideas and see how they would fair up against other bots. So I didn't look into downloaded code as that would influence my thoughts and I wouldn't be able to test my bot in a fair manner. A big big thank for those who published their code. I downloaded the java bots I came across, so my special thanks goes to GreenTea(ZerlingRush), Smloh, Manwe56, Deccan, Exaide, Eburnette, Ludakris, zvold(krokokrusa), InvaderZim. Without you guys it won't be possible for me to test my bot at all and you helped me to improve myself a lot. Looking forward to compete with you in a real tournament soon.
GreenTea was always a tough opponent for my bot, so was Smloh1. At initial stages almost all bots were very difficult to beat. I implemented features one after other, attack first, defense, neutral planet hunting etc and things improved dramatically. specially after proper defense and optimized neutral hunting. As for attacking, less attacking the better it was top bots were very quick to punish incorrect attacks. I thought Ludakris was a better bot than it's rating suggested, specially in close quarter battles. Manwe56 was little slower than other bots for some reason but was stronger than my one in most cases. Exaide has a random behavior as it was getting different results against the same bot on same map! it was a mysterious bot for me in the beginning. I felt I was bit luckier against Mkemp, zvold and eburnette and may be bit unlucky against Deccan whom I couldn't reach on ratings even though individual matches against that bot went close. Smloh1 was slow initially until I had to investigate and eliminate system.outs from the code :-)
It took about 2 months before this craziness ended and I had enough improving my very first AI bot. If the competitions I locally arranged is to be trusted and ELO tables do a good job in measuring performances and translating them into ratings, then I think I could be somewhat satisfied with my efforts. My final bot performed around 3280, (it got very close ratings in 2 different sets of maps against same opponents, so I guess the performance rating calculation is fairly accurate) which would mean had it managed to compete in the real competition, it may (arguably) have ranked somewhere between 60 - 70. I may have got an advantage since I have few good bots at hand to test my bot against with, but then again in the real tournament preparation, competitors may have had the privilege of playing against others on TCP servers as well as in the live server.
I didn't do fine tunings targeting the final tournament maps since my interest in the game dried down after solving the challenge of implementing all my game strategies and getting them to work. Some fine tuning would have helped to snatch up few more rating points... but my main interest was to get the algorithms right.
Now that the initial goal is achieved (to build a decent bot on my own), I can now go visit others code and analysis, learn something new and have a laugh at clumsier ways I may have achieved certain things in my code.
Source code of the final bot can be found in here. Excel with all tournament statistics and rating calculations along with ELO tables used is also there. I'm planning to explain my code, strategies and lessons learned in a future article if the time permits. Meanwhile, apologies if the code lacks enough comments.
All the best for all contestants in the upcoming contest! those who haven't get involved in this fun, do sign up!! trust me, you won't be regretting this. (specially if you like AI programming and/or problem solving in general)
Part 2
It was late when I got to know about Google's AI contest. I have missed the first contest as well, I got to know about the second contest, "Planet Wars" just few days before it ended. Considering the competition was running for over 2 months, that didn't give me much chance to compete effectively. To make the matters even worse, I was to find out (foolishness of me, should have checked that out before everything else!) about the submission deadline just a day before it!
So I ended ended up hurriedly submitting not even the best code I have written in those few days. And the competition was of course a disaster for my Bot. May be I should have satisfied with the results (1200 out of 6000 competitors) of what was made in just 4 days, but something else happened during the final competition.....
I really began to get carried away by the beauty of the game, and the challenge it offered. I just continued development of my bot hoping that the competition server will keep running even after the official competition so that I could still evaluate my bot by playing it against others. Unfortunately, official server was never started after the actual competition. Can't blame the organizers for that. They have provided a wonderful experience and organized a hugely successful competition. What's more, they have made the server software open source. Few people were already running their own TCP servers where others could compete. However, after the competition, even the players seemed they are tired after a competition which ran for over 2 months, and no one was so keen on playing on TCP servers. Even the servers were not available after few days. At least all my attempts to connect to one was ended in failure.
My only remaining option was to download the bots published by others after the competition and play my bot against them in locally arranged tournaments. By this time my bot was improving fast and I was in a hurry to implement all my ideas and see how they would fair up against other bots. So I didn't look into downloaded code as that would influence my thoughts and I wouldn't be able to test my bot in a fair manner. A big big thank for those who published their code. I downloaded the java bots I came across, so my special thanks goes to GreenTea(ZerlingRush), Smloh, Manwe56, Deccan, Exaide, Eburnette, Ludakris, zvold(krokokrusa), InvaderZim. Without you guys it won't be possible for me to test my bot at all and you helped me to improve myself a lot. Looking forward to compete with you in a real tournament soon.
GreenTea was always a tough opponent for my bot, so was Smloh1. At initial stages almost all bots were very difficult to beat. I implemented features one after other, attack first, defense, neutral planet hunting etc and things improved dramatically. specially after proper defense and optimized neutral hunting. As for attacking, less attacking the better it was top bots were very quick to punish incorrect attacks. I thought Ludakris was a better bot than it's rating suggested, specially in close quarter battles. Manwe56 was little slower than other bots for some reason but was stronger than my one in most cases. Exaide has a random behavior as it was getting different results against the same bot on same map! it was a mysterious bot for me in the beginning. I felt I was bit luckier against Mkemp, zvold and eburnette and may be bit unlucky against Deccan whom I couldn't reach on ratings even though individual matches against that bot went close. Smloh1 was slow initially until I had to investigate and eliminate system.outs from the code :-)
It took about 2 months before this craziness ended and I had enough improving my very first AI bot. If the competitions I locally arranged is to be trusted and ELO tables do a good job in measuring performances and translating them into ratings, then I think I could be somewhat satisfied with my efforts. My final bot performed around 3280, (it got very close ratings in 2 different sets of maps against same opponents, so I guess the performance rating calculation is fairly accurate) which would mean had it managed to compete in the real competition, it may (arguably) have ranked somewhere between 60 - 70. I may have got an advantage since I have few good bots at hand to test my bot against with, but then again in the real tournament preparation, competitors may have had the privilege of playing against others on TCP servers as well as in the live server.
I didn't do fine tunings targeting the final tournament maps since my interest in the game dried down after solving the challenge of implementing all my game strategies and getting them to work. Some fine tuning would have helped to snatch up few more rating points... but my main interest was to get the algorithms right.
Now that the initial goal is achieved (to build a decent bot on my own), I can now go visit others code and analysis, learn something new and have a laugh at clumsier ways I may have achieved certain things in my code.
Source code of the final bot can be found in here. Excel with all tournament statistics and rating calculations along with ELO tables used is also there. I'm planning to explain my code, strategies and lessons learned in a future article if the time permits. Meanwhile, apologies if the code lacks enough comments.
All the best for all contestants in the upcoming contest! those who haven't get involved in this fun, do sign up!! trust me, you won't be regretting this. (specially if you like AI programming and/or problem solving in general)
Part 2
Subscribe to:
Posts (Atom)