.com.unity Forums

.com.unity Forums (http://forum.shrapnelgames.com/index.php)
-   Dominions 2: The Ascension Wars (http://forum.shrapnelgames.com/forumdisplay.php?f=55)
-   -   SUGGESTION: AI castle building algorithm (http://forum.shrapnelgames.com/showthread.php?t=18776)

Arralen April 16th, 2004 07:40 AM

SUGGESTION: AI castle building algorithm
 
This is a part of the troop building suggestion
------------------------------------------------
Build castle
IF money=1.2*(castle cost) OR desirabilty>7
CHOOSE prov with highest "desirability points"


a) has indie troop with (ress. cost)>14 2pts

b) will give (combinedress)>66 [BASE w/o scales]
AND isn't next to another castle 1 pt
OR (combinedress)>99 2 pts

c) has site with allows special troops 1pt
has site with allows special commanders 2pts

d) has 4 land neighbours, of which 2 are not owned AND not neighbouring owned provinces 1pt

f) would have 2 castle neighbours -2 pts
------------------------------------------------

I'm not shure if a-d wouldn't need a nation-specific weighting, but I tried to get along without anything such. This would keep the code compatible not only with any nation/themes but any thinkable mod, too. (At least most of them, admittedly)

[ April 16, 2004, 06:52: Message edited by: Arralen ]

Norfleet April 16th, 2004 09:43 AM

Re: SUGGESTION: AI castle building algorithm
 
Your castle building policy may also be dictated by your castle choice: If you bought something like a Wizard tower, or just kept the default watch tower, as I often do, the castle building decision quickly becomes simpler:

IF PROVINCE DOES NOT HAVE CASTLE
BUILD CASTLE

Combined with a solid defense plan, it will render the life of any invader into a living hell of urban warfare.

tinkthank April 16th, 2004 10:09 AM

Re: SUGGESTION: AI castle building algorithm
 
Wow, I dont understand a damn thing about programming and whatnot, but you definately are the man.
(Um hoping you are male, here.)
Um: wow, thanks. That sounds great. Imagine, real AI enemies!
yum....

Arralen April 16th, 2004 10:45 AM

Re: SUGGESTION: AI castle building algorithm
 
Quote:

Originally posted by Norfleet:
Your castle building policy may also be dictated by your castle choice:..
If ... Wizard tower,...becomes simpler:

IF PROVINCE DOES NOT HAVE CASTLE
BUILD CASTLE

<font size="2" face="sans-serif, arial, verdana">I think
Build castle IF money=1.2*(castle cost)
will take care of this very well, but only testing in a "real life" will show. Any takers?

Can't do much testing myself, as time is limited and there's so much to do ... http://forum.shrapnelgames.com/images/icons/icon12.gif

Norfleet April 16th, 2004 10:50 AM

Re: SUGGESTION: AI castle building algorithm
 
Quote:

Originally posted by Arralen:
Build castle IF money=1.2*(castle cost)
will take care of this very well, but only testing in a "real life" will show. Any takers?

<font size="2" face="sans-serif, arial, verdana">I think the underlying problem is that the AI never has any money because it has blown all of its cash hiring garbage. Your troop hiring formulas might improve that, although it still wouldn't stop the AI from squandering most of its money on troops it wastes in futile attacks. For instance, human players tend to win attacks on provinces, unless the attack is anticipated by the defender: In contrast, the AI will often lose attacks even when you did not specifically anticipate it.

Arralen April 16th, 2004 10:53 AM

Re: SUGGESTION: AI castle building algorithm
 
I can't do a thing about how the AI fights, but I did put in a "moneysaving turn" now and than so the AI will have the money available from time to time to build a castle. Check out.

Gandalf Parker April 16th, 2004 03:08 PM

Re: SUGGESTION: AI castle building algorithm
 
Sounds good. I like the logic so far. Seems to take into account everyones favorite tactics (except chokepoints but the logic on that would be difficult)


I wonder how much "thinking" this would take. I usually comment that it doesnt matter how long it takes a turn to process because its a "pass turn file to host" type game. But AI improvements mostly affect solo players and improving the AI would do any good if it changes the game to something too slow to hold their attention.

Arralen April 16th, 2004 03:24 PM

Re: SUGGESTION: AI castle building algorithm
 
"thinking costs":
I'm concerned about the needed cpu time to re-calculate the "desirability" for each province each turn.

Maybe I can come up with a simple solution that generalizes most cases when you can barely build a castle but prefer to do so over building troops.


choke points
d) has 4 land neighbours, of which 2 are not owned AND not neighbouring owned provinces

.. doesn't this qualify?

[ April 16, 2004, 14:35: Message edited by: Arralen ]

Daynarr April 16th, 2004 04:21 PM

Re: SUGGESTION: AI castle building algorithm
 
Quote:

Originally posted by Arralen:
Build castle
IF money=1.2*(castle cost) OR desirabilty>7
CHOOSE prov with highest "desirability points"

<font size="2" face="sans-serif, arial, verdana">It's not bad idea, but I was thinking about something a little different here.

1) Limit amount of gold spent on non-castle provinces (relative value, maybe 30% or even less). That way if AI has enough gold income and too few castles he will generate surplus in gold and wont spent it all on weak easy-to-lose units (Militia, LI). That will allow him to build as much national units as he can and still be able to generate some surplus to build new castles. If AI spends all money on national troops and can�t afford new castle, then he doesn't build new one anyway at least with his current income.

I believe Jasper proposed something like this in LI thread and I like this idea better simply because it will maximize production of national troops without going too deep into unit production scripting.

2) When AI has enough gold to build castle he should decide where to do it. Your proposal is quite good, so I would add only 1 thing there. When deciding for where to build castle AI should take into account ALL neighbors, not only the ones he controls. That way he will be building forts on bordering provinces if they are good, without need for special algorithms.

As for slowdowns, I don't think they should be significant since AI revalue his provinces only when he has enough gold to build castle, not every turn.

[ April 16, 2004, 15:23: Message edited by: Daynarr ]

LintMan April 16th, 2004 05:56 PM

Re: SUGGESTION: AI castle building algorithm
 
Quote:

Originally posted by Arralen:
This is a part of the troop building suggestion
------------------------------------------------
Build castle
IF money=1.2*(castle cost) OR desirabilty>7
CHOOSE prov with highest "desirability points"


a) has indie troop with (ress. cost)>14 2pts

b) will give (combinedress)>66 [BASE w/o scales]
AND isn't next to another castle 1 pt
OR (combinedress)>99 2 pts

c) has site with allows special troops 1pt
has site with allows special commanders 2pts

d) has 4 land neighbours, of which 2 are not owned AND not neighbouring owned provinces 1pt

f) would have 2 castle neighbours -2 pts
------------------------------------------------

<font size="2" face="sans-serif, arial, verdana">A few comments:
- For a, are you counting commander units? *Many* standard indy commanders have a res cost > 14. Even aside from that, 2 pts seems to place a lot of desirability on having high-resource indep troops. I think this should probably be more nation-dependent. Ie: An indy province that produces heavy cav may not be much of a benefit for a nation that already has some good heavy cav units.
- I think that b above has a potential hole where it could build new castles that share provinces with one or more other castles, thereby reducing *those* castles resources to unfortunate levels even though the new castle meets the criteria. Perhaps a check that all bordering provinces of the prospective castle site should have <= 100% admin after factoring in the new castle, or -2 pt desirability rating
- I tend to emphasize putting castles at/near stable enemy borders. In d, I'm not sure what you mean by "... AND not neighboring owned provinces" ... neighboring what - enemies? I don't know if I'm missing the point, but I think I'd scratch that part so it could put castles on its borders.
- Is there no point e on your list? http://forum.shrapnelgames.com/images/icons/icon10.gif
- It might also be worth somehow factoring in some desirability for building castles at/near "where the action is". IE: The AI is probably better off building a castle near where its current main army is engaged than at some place on the other side of its empire.
- Another thing to consider is that if the AI does start building castles anywhere near its enemies is that it should make sure it is capable of defending the province while the castle is under construction (to protect its investment), and will be able to defend the castle after it's built. It would be a bad thing if the AI starts building undefended or marginally defended castles that opponents could easily take and use for themselves to support their advance.
- It might be worth setting some castle-to-province ratios, at which castle building becomes greater and greater priorities. Say:
</font><blockquote><font size="1" face="sans-serif, arial, verdana">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">if (ctp-ratio &lt; 0.1) // if less than 1 castle per 10 provinces
save_income_percentage_for_castle(0.2) // save 20% of income towards castle
else if (ctp-ratio &lt; 0.05) // 1 castle per 20 provinces
save_income_percentage_for_castle(0.5) // save half of income towards castle
etc.</pre><hr /></blockquote><font size="2" face="sans-serif, arial, verdana">The numbers above are arbitrary, but you get the idea. This could allow a gradually increasing priority for castles as the AI expands, and also would allow the AI to save up for castles rather than just building them when it happens to have enough money or relying on occasional money-saving turns.

tinkthank April 16th, 2004 06:06 PM

Re: SUGGESTION: AI castle building algorithm
 
Quote:

Originally posted by Gandalf Parker:

I wonder how much "thinking" this would take. I usually comment that it doesnt matter how long it takes a turn to process because its a "pass turn file to host" type game. But AI improvements mostly affect solo players and improving the AI would do any good if it changes the game to something too slow to hold their attention.

<font size="2" face="sans-serif, arial, verdana">As an SP nerd, I would gladly pay 400% in turn generation time for better AI without blinking, and probably 800% if it were pretty decent. But that is just my sole opinion.

Go Arralen go!

Gandalf Parker April 17th, 2004 07:10 PM

Re: SUGGESTION: AI castle building algorithm
 
I think Castle building is more important to an AI win than the spread of units purchased. And the formula would be easier to test. In fact if you turn on --scoredump you get an html with numbers for everything which would make the math much easier in later games (not have to count provinces and such)

ioticus April 17th, 2004 11:53 PM

Re: SUGGESTION: AI castle building algorithm
 
You mean it would be possible to download a mod that improves the AI and lets it build castles?! When can I download it?

Gandalf Parker April 18th, 2004 12:19 AM

Re: SUGGESTION: AI castle building algorithm
 
Quote:

Originally posted by splooger:
You mean it would be possible to download a mod that improves the AI and lets it build castles?! When can I download it?
<font size="2" face="sans-serif, arial, verdana">No the modding doesnt support directly changing the AI. Im just saying that we are more likely to get a small change to the linear AI than ever getting a complete rewrite.

There are some MODs in the work which might make a difference but as far as I can see they will have to be a mod for each nation you want AI'd. They would do things like make castles cheaper and remove the light units that the AI loves.

There are also some MAPs which strengthen the AIs.

[ April 17, 2004, 23:48: Message edited by: Gandalf Parker ]

MStavros May 9th, 2004 05:54 PM

Re: SUGGESTION: AI castle building algorithm
 
All right, imho the AI should build castles like this:

</font><blockquote><font size="1" face="sans-serif, arial, verdana">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> Province
Province - Castle &amp; Province - Province
Province
Province - Castle &amp; Province - Province
Province </pre><hr /></blockquote><font size="2" face="sans-serif, arial, verdana">Just multiply it in all directions.

[ May 09, 2004, 16:54: Message edited by: MStavros ]

Gandalf Parker May 9th, 2004 06:33 PM

Re: SUGGESTION: AI castle building algorithm
 
Quote:

Originally posted by MStavros:
All right, imho the AI should build castles like this:

</font><blockquote><font size="1" face="sans-serif, arial, verdana">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> Province
Province - Castle &amp; Province - Province
Province
Province - Castle &amp; Province - Province
Province </pre><hr /></blockquote><font size="2" face="sans-serif, arial, verdana">Just multiply it in all directions.

<font size="2" face="sans-serif, arial, verdana">OK now test it. Play a game pretending to be the AI and do that, faithfully. See if you can beat the AI's with it.

Leif_- May 9th, 2004 07:01 PM

Re: SUGGESTION: AI castle building algorithm
 
[quote]Originally posted by Gandalf Parker:
Quote:

Originally posted by MStavros:
OK now test it. Play a game pretending to be the AI and do that, faithfully. See if you can beat the AI's with it.
<font size="2" face="sans-serif, arial, verdana">Actually, he can't test it yet; as he haven't suggested any police for when the AI should build castles. As soon as it's got enough money at the start of a turn? If it's got enough money after recruiting units? And so on.

MStavros May 9th, 2004 07:37 PM

Re: SUGGESTION: AI castle building algorithm
 
Yes I any suggestions? The older replies here are very interesting btw.

[ May 09, 2004, 18:38: Message edited by: MStavros ]

Gandalf Parker May 9th, 2004 09:06 PM

Re: SUGGESTION: AI castle building algorithm
 
[quote]Originally posted by Leif_-:
</font><blockquote><font size="1" face="sans-serif, arial, verdana">quote:</font><hr /><font size="2" face="sans-serif, arial, verdana">Originally posted by Gandalf Parker:
Quote:

Originally posted by MStavros:
OK now test it. Play a game pretending to be the AI and do that, faithfully. See if you can beat the AI's with it.
<font size="2" face="sans-serif, arial, verdana">Actually, he can't test it yet; as he haven't suggested any police for when the AI should build castles. As soon as it's got enough money at the start of a turn? If it's got enough money after recruiting units? And so on.
</font><hr /></blockquote><font size="2" face="sans-serif, arial, verdana">Yeah I was hoping he would notice it. If he blindly pursues his castle plan he would end up with no troops.

I figure the best castle-building time frame would be when the AI has enough money for a castle without saving. It would also be easiest to program. But his present configuration looks like it would be finding a location to build on at about the 12 turn into the game. Is that when one turns income is more than the cost of a castle?

delacroix May 9th, 2004 09:10 PM

Re: SUGGESTION: AI castle building algorithm
 
To take the fort-building suggestion in a slightly different direction, (maybe it will spur someone's creativity), is anyone complaining about the temple building algorithm the AI has? If not, wouldn't it be possible to modify the temple building AI into a temple-or-fort building AI? As in, if the temple check passes but too many temples exist, start to focus on forts? If no suitable fort location is found, then revert back to building a temple this turn. That could answer the "when" to build a fort, and "how" to accumulate resources for the fort. My post doesn't deal with "where" the fort should be built, others have proposed options for that.

But if the AI can afford to build 200gc temples, it can afford to build a 250gc fort. And if it can afford to build 2 temples over a span of a couple turns, it certainly could have instead afforded to build the 450gc castle, and so on...

I don't know how the temple-building AI works exactly, whether it only builds temples when it has the 200gc at the start of the turn, or whether it saves the 200 over the course of many turns. Either could be adapated to fort-building. In the latter you just save over more turns, in the former you can just store/save 200gc (or 250 would be a better option for the initial save) until enough money is accumulated to build that fort.

The temple building AI is rather decent at getting the job done, so it handles a lot of cases by itself. Early game it takes a while for the AI to build their temples, so the forts would naturally come after a certain proportion of temples were built. And the AI would start to build a fort or two when it hit that time period where the AI starts to fill up every province with a temple (IMO this is about the prime time when forts should be appearing). However, late-game if an AI was conquered to only a few remaining provinces and had a temple in each, the building-AI would say 'focus on building forts', but the "where" condition in most cases would prevent the castle from being built [unless of course one of those remaining provinces was some choke-point / high resource / not adajcent to another fort type condition]. So the AI wouldn't in most cases "waste" money building forts late-game when it had a small territory size.

Of course there'll be some holes in the idea and/or limitations since its quite a rough draft, but maybe it'll give someone a more 'developed' idea.

mivayan May 9th, 2004 10:49 PM

Re: SUGGESTION: AI castle building algorithm
 
I think that for placement of a castle, you can ignore indie troops, chokepoints, neighouring enemies etc and just focus on maximizing resources for national troops. The other things are too hard to get right, but maximizing castle resources is easy.

for each province I own:
if I build a castle here, what will the combined resources in all castles be, assumin no provinces changes owner untill it is done.

Then pick the province with the highest result.

Gandalf Parker May 9th, 2004 11:39 PM

Re: SUGGESTION: AI castle building algorithm
 
Building for resources isnt a bad idea. And it simplifies the programming side. Also if you simply chose a castle location which is not next to another castle (1 away? 2 away?) but ignoring if you own all the neighboring provinces then you could still luck into a chokepoint or a good frontline location.

Adding temples might also be a good idea. So if I have enough to build, I look for a high resource location which is not too close to anothe castle, if I cant find one then I look for a temple location which allows recruiting priests. How does that sound?

HotNifeThruButr May 10th, 2004 03:38 AM

Re: SUGGESTION: AI castle building algorithm
 
What about building a temple and lab at every fort location? Is that do-able or would it hinder the AI?

Edit: Also, what about requiring more desire poinst for less costly forts and more desire points for more costly forts? So they don't have too little watch towers or too many Fort. cities.

BTW, Arralen, it'd be cool if you wrote a spellcasting AI.

Edit: Also, consider reducing desire to 0 if the province has an unrest site, like Inkpot End, Brigand Lair, etc.

[ May 10, 2004, 03:23: Message edited by: HotNifeThruButr ]


All times are GMT -4. The time now is 10:09 PM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©1999 - 2025, Shrapnel Games, Inc. - All Rights Reserved.