It is currently Wed Jun 19, 2013 3:05 am Advanced search

Tell us your secrets, unleash your bot's code!

Share and discuss ideas for your entries here.

Re: Unleash your code - learn from eachother

Postby smiley1983 » Sun Nov 28, 2010 1:50 pm

botname: smiley1983
unofficial rank: 50 - 150
language: Objective Caml
Source: smiley1983-s32.zip

The code is a mess. It has plenty of errors. :)
Here's a brief description of its algorithm, errors omitted:

Each turn:
- For each planet:
- - Build a table of future ship counts and fleet arrivals based on fleets currently in the air.
- - Build some tables of possible future ship arrivals, based on the predicted ownerships of other planets from table 1.
- - - Cases include what happens when we fight over the planet with appropriate leeching delay, and what happens if only one pours fleets in.
- generate requests for fleets to prevent planet losses (this includes Neutrals becoming enemy)
- call fill_requests with few safety constraints, but requiring that the fleets get there on time.
- add requests to capture enemy planets
- call fill_requests with strict safety constraints
- call fill_requests with slightly relaxed safety constraints (two steps ensuring safer attacks are given priority over more dangerous ones)
- add Neutral capture requests
- call fill_requests with appropriate safety constraints
- redistribute fleets toward frontline planets if they meet criteria
- redistribute fleets between frontline planets if they meet criteria
- submit orders.

The fill_requests function can draw fleets from multiple source planets.

Thankyou to everyone who participated in the contest, it has been lots of fun!
smiley1983
Colonel
 
Posts: 52
Joined: Tue Oct 05, 2010 6:28 pm

Re: Unleash your code - learn from eachother

Postby iouri_ » Sun Nov 28, 2010 2:41 pm

Bot name: _iouri_
Unoficial rank: Somewhere in top 20-30
Language: C++
Source: https://github.com/ikhramts/planet_wars/tree/simplified

I'll probably make a more detailed post lated, with a cleaned up code. For now though, I think I actually do a lot of what smloh1 writes about above. What I do is:

(1) Calculate the state for every planet given existing fleets and planet states. The calculations are done from current turn to about 30-38 turns ahead (up to horizon), depending on the planet size.

(2) Given data from (1), for every planet, for every turn t = 1, ..., horizon, and for every radius d = 1, ..., t, I calculate:
  • defense potential, which roughly answers the question "if the enemy were to send an all out attack on this planet at turn t - d, would I be able to respond on the following turn and still keep the planet?" More precisely, it's the sum of my ships that can be sent from distance d - 1 from the planet to arrive at turn t (including those on the planet), minus the sum of enemy ships, including those on the planet, that can be sent from at most d distance from the planet to arrive at turn t. If the defense potential is negative, then there's a risk of losing the planet, and I'd need to pre-emptively send some supporting fleets. The specific pattern of ships to send will be dictated by the distribution of the defense potentials for the turn t; e.g. if defense potential at t = 5 and d = 3 is negative, there's little point in sending support ships from a planet 2 turns away. Sending the fleets will happen later though; for now we're just calculating. From the defense potentials we also derive:
    • minimum defense potential at t, which is the smallest defense potential on the planet at turn t for any distance d. This is used to quickly determine whether a planet of mine is in danger.
  • support potential, which is the same as defense potential, except it's sum of all my ships minus all enemy ships within distance d from the planet that can arrive at turn t. The support potentials themselves aren't as interesting; however, these are used to calculate
    • full support potential at t, which is the balance total of ships that both of us can send to the planet t, from any distance. This will indicate whether the planet can theoretically be held/conquered.
    • maximum support potential at t, which is the maximum of support potentials at t for all d = 1, ..., t. If this number is positive for an enemy planet at turn t, then the planet will be likely vulnerable and we should start planning for the attack.

(3) Given data from (1) and (2), for each planet, I calculate:
  • total ships gained from the planet, which is the number of ships I would likely earn from the planet minus the number of ships the opponent would likely earn. If the planet is mine, and the minimum defense potential at a given turn is negative, then I assume that the planet will be lost.
  • potential total ship gain from the planet, which makes a rough guess as to how much each one of us can hold the planet based on the full potentials.

Phew, that's out of the way, now we can start actually thinking about which moves to make. Move picking works as follows, roughly:

(4) For every planet, and for every arrival turn t, check:
  • Is it my planet with a negative min defense potential?
  • Is it an enemy or neutral planet with a positive max support potential?

If the answer to any of the above is yes, then compose an invasion plan, basing the number of ships to send mostly from the defense potentials (yes, for attacking enemy too; "defense" is a misnomer here). The ships are coordinated to arrive at turn t; they are first picked from the unreserved ships on closest planets, and if that's not enough, more are recruited from the planets farther out. If there are not enough ships available to take over the planet (or prevent it from being taken over), then the whole plan is dropped. The strategy for picking which planets will send which fleets is not the best, but it worked decently enough so it wasn't at the top of my list of things to fix.

(5) Calculate the potential return on the move. This is done more or less by adding the invasion fleet to the game timeline, and recalculating (1) - (3) above, though being smart about updating only the effects of values that have changed. Once that's done, I see how the potential values have changed on all of planets that are mine at any point in time (not enemy planets though, or neutrals; I didn't manage to make that part work properly). Then I take the total potential ships gained from my planets, minus potential ships gained before applying the invasion plan to the timeline, and that gives me potential ships gained.

Once done that, I calculate the potential return on the move by dividing the increase in potential ships gained by the total ships to send (with some adjustments).

(6) I select the plan that gives me the highest return per ships sent. The plan is added to the timeline, the ships are reserved.

------------
The steps (1) to (6) are repeated until we're either out of time, there are no more ships to send, or there are no more available invasion plans with positive returns.

A few more things:

- Send simple support without excessive calculations: after step (3) and before step (4), to speed things up, I figure out which planets need support (based on defense potentials). If sending the support will not disadvantage any other planets, then the supporting fleet will be sent without calculating the potential returns. Otherwise the bot will be cripplingly slow, as step (2) takes forever to calculate, esp if it's done over many move picking rounds..

- Limit small supporting actions many turns ahead: for the same reason as just mentioned, I do not evaluate (and skip altogether) supporting fleets that would depart more than a few turns from now.

- I add constraints on which planets may be supported. If any of the calculations between steps (1) and (6) make it so that a planet will become vulnerable to the opponent, then it's judged that it's for the best of the nation and I prohibit other planets from sending support fleets to that planet. Otherwise, there are too many ships flying back and forth.

- Sending ships to front: after all invasion plans have been established, I feed the remaining unused fleets from the rear planets to the front planets. I check for every planet whether there is another planet closer to the enemy, and if the defense potentials allow it, send the remaining unreserved ships to that front planet. This is actually not the smartest algorithm, as sometimes the fleets end up where they're not that useful, but I didn't get around to finding a better one.

I prohibit rear planets from attacking enemy's planets (as we don't want the enemy seeing the attack coming from 22 turns away). This is reflected in all potential calculations as well.

- Keeping enough ships on planet to fight off enemy arrivals: I do not do this. I used to do this, and it used to give me advantage, but after implementing the potentials my tests have suggested that not forcing the planet to keep enough ships to hold the planet was a better approach. This way the lower growth planet would have to problem sending all of its ships away to capture a higher growth planet.
Last edited by iouri_ on Mon Nov 29, 2010 7:57 pm, edited 3 times in total.
iouri_
Brigadier-General
 
Posts: 105
Joined: Thu Feb 11, 2010 4:16 pm
Location: Toronto, Canada

Re: Unleash your code - learn from eachother

Postby bhasker » Sun Nov 28, 2010 3:07 pm

https://code.google.com/p/malazan-bot/source/checkout
https://code.google.com/p/malazan-bot/s ... trunk/0.23 (0.23 version)
My bot is mostly a pure heuristic bot and I don't even look at enemy moves. The code is kind of messy with lots of comments
hanging around, i will clean it up and upload a cleaner version later. This bot was holding to about 40-50 rank on official. I will
upload 0.23 version of this bot as well which was holding 40-50 as well but is slightly different in how it does things.

The basic logic of the code is somewhat like this
a) at Turn 1 do a knapsack based solution to decide planets to capture
b) 2-200 purely heuristic based and a lot of checks on when to attack neutrals, it will always attack an enemy planet
if it has enough ships to take it.

At start of every turn it calculates state of the game upto maxDistance*2+1 turns. It then uses this state object to evaluate
moves and score each move. It also uses this object to decide how many ships can be sent from a planet safely and how
many it will have available in the future etc ( this part is a bit buggy). It also uses this to decide how many ships need
to be sent to capture an enemy planet ( without considering other enemy planets ). This piece of code is a bit of a mess
because earlier I only used to calculate state upto the distance of the fleet furthest out. This lead to lot of hacky code,which
is now dead code.

The main bot logic goes like

doTurn
updateStateObj
buildShipAvailabilityQ
for each planet p:
generateMoves
optimizemoves
executeOptimizedOrder
updateStateObj
doRemainingShips # all staging/routing code at end of turn
Last edited by bhasker on Sun Nov 28, 2010 3:36 pm, edited 1 time in total.
bhasker
Lieutenant
 
Posts: 11
Joined: Tue Sep 14, 2010 2:17 am

Re: Tell us your secrets

Postby amstan » Sun Nov 28, 2010 3:14 pm

I'm merging this thread with the other. Please don't make new ones.
Alexandru M. Stan
Contest Organizer
User avatar
amstan
Contest Organizer
 
Posts: 692
Joined: Sun Jan 31, 2010 4:02 am
Location: Stoney Creek, Ontario

Re: Tell us your secrets, unleash your bot's code!

Postby murrayr » Sun Nov 28, 2010 3:46 pm

Bot name: murrayr
Unoficial rank: Top 20
Final rank: 67=
Language: C++
Source: attached

Greedy algorithm: Given the a state of the game, I calculate the future for each planet and its spare firepower above that required to hold the planet. Then I simulate a full firepower attack by both sides against each planet, with the enemy holding back one step when attacking neutrals to simulate sniping. These are scored from the gains (holding a planet for a turn) and losses (attacking neutrals), with a penalty of 10% per turn that it will take to capture the planet. The best scoring attack is selected with enough force to capture the planet for at least 3 turns. Then the calculations are redone until there are no more good planets to attack.

Now I want to guess out what the enemy is actually going to do this turn, so I can try to avoid silly moves and take advantage of things it might do. So I run the greedy algorithm for it, add its moves to the current state, then recalculate my moves. But that might give problems when the enemy does something else. So, for 0.5 seconds, I iterate between the enemy generating moves and me generating moves, each time running the greedy algorithm against all generated (relative)enemy moves, believing the worst score and highest number of ships required.

My bot still has problems with giving away planets too cheaply for a small gain, because it uses per-planet scoring. So during the start of a game with close first planets, it calculates firepower that has to be held for full defense.

If I was to do this again, I would like to try using iteration and simulated annealing to improve sets of missions with global scoring, and possibly with probabalistic modeling of enemy moves.
Attachments
galconPlayer.zip
(14.82 KiB) Downloaded 105 times
Last edited by murrayr on Thu Dec 02, 2010 7:17 pm, edited 1 time in total.
murrayr
Cadet
 
Posts: 1
Joined: Sun Nov 28, 2010 2:51 pm

Re: Tell us your secrets, unleash your bot's code!

Postby medrimonia » Sun Nov 28, 2010 7:13 pm

Bot name: Medrimonia
Unofficial Rank : Between 10 and 30
Language : Python
Source : Attached

My bot has a high priority to avoid the possibility of the enemy to take my planets: It's supposed to calcul the numbers of free_ships I have on each planet (ships I can move without risking to loose my planets) and after with this number it manages to:
- snipe the enemies attacks on neutrals (if the score I give them is good enough.
- attack the enemies if it can (this part of the program is old and can send more than the free_ships, destroying my defence system)
- Attacking neutrals to increase my growth (I'm trying to avoid the expands which would allow my opponent to have a better expand)
- Redistribute ships from my useless planets and to my endangered planets.

There's still a lot of issues like a big problem to deals with multiple fronts.

My code is really very dirty...

tout_en_un_r91.tar.gz
(18.8 KiB) Downloaded 116 times
medrimonia
Lieutenant
 
Posts: 10
Joined: Fri Sep 17, 2010 6:13 pm

Re: Tell us your secrets, unleash your bot's code!

Postby lakeweb » Sun Nov 28, 2010 8:11 pm

I only got to basic infrastructure even in my second bot. Outline:
Create a set of attacks on planets and stat the future of the planet.
Find what 'my' planets now and in the future that can take other planets.
Same to defend my planets at risk.
(at this point I had no aggressive plan.)
Create a graph to stream ships from back planets to front.
(This was somewhat working but needed work.)

My TODO was to clean up DoTurn, use more of the objects instead of top down. And get an overlord strategy in place.

Here it is:
https://github.com/lakeweb/MyBot/

Best, Dan.
lakeweb
Cadet
 
Posts: 3
Joined: Mon Sep 20, 2010 5:58 pm


Re: Tell us your secrets, unleash your bot's code!

Postby Hippo » Sun Nov 28, 2010 11:52 pm

I was not planning to make serious attempts in the contest, but I have writen heuristic bot.
It mades roughly 6 actions ... defending mine, "defending neutrals", colonize neutrals, centralize, attack exposed enemy, flow attack (when leading).
All (defences) were based on ships on the air arrival calculations. Colonizing used minimum return turn for selecting the best planet to attack and the attacks were planned to arrive to the neutral at the same turn. All ships were send directly to the target.

I have looked at the actual score and expected performance around 500. I was surprisingly rated around 80.
This encourages me. I have started codding of more serious bot using BItsets for planets the the given distance making plans for the whole game (but only with small horizon filled) with time management, reading input only till all infomation is known... calculating planet influence as a dimension for colonizaction optimization but I got time for programming only occassionally so the project was never compiled.

Instead I have looked at the prerformance of my heuristic bot and tried to improve the heuristics a bit. I have changed centralizing not to use one skip, but rather centralize with shorter flights (minimum of some cost function). This was done when I felt to position around 120 and the improvement moved me to position 35, then I start drifting to positions around 80.

After chaniging the map generator I started losing, as simple centralizacion to planet nearest opponent does not work well on line symmetry maps. (I was losing mostly on maps with frontline consisting of several planets till that).

I never considered planet sizes for my defense heuristics. I never considered opponent's options. Instead I have tried to calculate the number of ships required for defense if opponent issues an attack (my bot used same calculation for determining targets). I have added "shared reserve" calculations. I hav eposted the third version of bot with that and it returned to positions around 80.

Early after posting I find the calculation was wrong and it actually does not calculate required defense. I have removed the bug, but the bot was absolutely passive and won around 10% maps against the posted "buggy one". The situation when the bot performed well due not doing what was intended made me nervous and I have tried to made better version of it.

I wanted to modify the bot not to be as eager as it was I have added global measure ... when having greater total growth planned ... not to invest to other neutrals losing due to small total number of ships. Meanwhile I have found several other "bugs" in the code ... when capturing opponent's planet, I was not supporting it until turn it becomed mine. When I have planned to attack neutral later, I have started centralization to that planet. ... I had about 5 candidate bots each improved some way. Seems I have not chosen the best, as now I am around 250, while not changed bot's skipped me (and a lot of crazy moves could be visible ... so letting the buggy one was probably the best option :) ).
I modified colonization in the way ships are moved closed to the neutral to let them available elsewhere if the attack would be canceled.
There were other paths leading nowhere as well ... sending troops in path optimised to "as short" skips as possible does not improve the ship availability.
I have added ... attack nearest planet mode for the case I am "winning" (was intended for the case higher number of ships but smaller growth rate, but rarely invoked in that case). This mode probably requires shortening the fleet skips. It works better on maps with distant players.

My heuristics bot started every turn almost from scratch without considering previous turns.
This is why sometimes the capturing neutral plan is abandoned even with 0 neutrals on the planet :(.
Having buggy eager version is better than having "defender" version with bugs in the main line ...

I like the iouri's method how to not went to passivity. Just consider several options and calculate their best "investment return".

So ... next time I would probably not participate at all ... participation without serious time plan ...
Hippo
Lieutenant-Colonel
 
Posts: 49
Joined: Wed Mar 03, 2010 6:42 pm

Re: Tell us your secrets, unleash your bot's code!

Postby aerique » Mon Nov 29, 2010 8:46 am

Hippo wrote:...

That sounds like the story of my bot. It turned into a big ball of heuristics that got the better of me. During the last week of the contest it was hugging the top 100 but some improvements I made (including one obvious bug) dropped it to 250th - 350th place on Friday and Saturday. Eventually I decided to upload the top 100 hugger but currently it's still ranked somewhere between 300 and 350th place. No idea what happened :-)
aerique
Brigadier-General
 
Posts: 131
Joined: Fri Feb 05, 2010 3:23 pm
Location: Netherlands

PreviousNext

Return to Strategy

Who is online

Users browsing this forum: No registered users and 1 guest