Defence strategies? (for the AI)

Share and discuss strategies for playing the game, and get help and tips from other players.

Moderator: Forum Moderators

Locked
Darkas
Inactive Developer
Posts: 4
Joined: March 25th, 2010, 9:37 am

Defence strategies? (for the AI)

Post by Darkas »

Hello!

As a (big) part of my Google Summer of Code proposal for Wesnoth, I want to improve the AI, so it can defend better (recognize if the enemy is too strong for attacking, but also defending people/places). I've tried finding some good strategies by myself, but I'm not sure if they're good enough or even wrong, so I'll list them up for you and I'm asking for help on improving them.

- Line units with highest resistances, most hp and best field modifiers and get the rather weak units/healers to the back
- Flee to have your units standing on villages/fields where they can fight better
- In case you have units that are close to leveling up, but not much hp, try to get them killing enemies
- If you're too weak, flee even at the cost you loose villages (if not, try to defend them)
- If there's a unit that doesn't have a big hp maximum, but is at good health, use a formation so that it can just be attacked by one enemy

- If the AI wants to protect a unit or a special place, they'll use the same tactics, but they always keep close to that place, so they don't flee into it and they won't walk towards their enemies

I haven't been playing Wesnoth for a that long time, so that's it. Thanks in advance for your help :)
Last edited by Iris on October 21st, 2013, 1:03 am, edited 1 time in total.
Reason: Retiring obsolete sticky.
batoonike
Posts: 75
Joined: January 3rd, 2009, 8:14 pm

Re: Defence strategies? (for the AI)

Post by batoonike »

-Consider time of day in cases when its obvious, like drakes vs undead, neutrals vs loyalists, and attack or retreat accordingly.
-When retreating because of bad ToD, keep just 1 hex out of the opponents best moves so when ToD changes the AI can react right away.
User avatar
jaimeastorga2000
Posts: 29
Joined: July 25th, 2009, 12:28 pm

Re: Defence strategies? (for the AI)

Post by jaimeastorga2000 »

I think your strategies are good. Here's what I have to add, based on my own experiences:

Don't forget the "line units at the edge of terrain which has a higher defense than surrounding terrain" technique (for instance, most units in a mountain/plain, plain/water, or plain/swamp edge would have a clear defensive advantage if they held the first one and did not allow the enemy to cross the border, forcing the other troops to fight from inferior terrain). For this and other strategies revolving around lines, it is sometimes a good idea to leave a gap if a unit is more needed elsewhere; only skirmishers will be able to take advantage of it unless the line breaks. Ideally, the hexagon left abandoned would be one with weak defensive terrain for your units.

In such formations, if they have corners or other irregularities, it is also usually a good idea to place the healer behind these places, since they can often heal 3 or more front-line units rather than the 2 they normally manage.

When several wounded units need to defend a village and one can heal, it is often a good idea to put the healer in the village so s/he can be healed and heal at the same time, improving the health of both units.

If the AI is defending a hexagon, it should place cheap unit on it most of the time. If it starts losing and the enemy closes in, it can move the other unit and retreat it's leader to the hexagon, so that the enemy will have to get past what is often the AI's toughest unit in order to take it (after recruiting as much as possible, of course). If the AI is defending a person, it probably should have at least 3 cheap level 1 units surrounding it one hex apart to make it hard for the person to be attacked while using up minimal resources.
User avatar
Sorrow
Posts: 230
Joined: July 25th, 2006, 12:07 am
Contact:

Re: Defence strategies? (for the AI)

Post by Sorrow »

Last I heard dauntless was interested in helping develop a smarter AI. Might want to try to contact him.
Let us all measure in milliyards, that way we can all get along.

Replay Archive: http://www.wesnoth.org/wiki/Replays
Darkas
Inactive Developer
Posts: 4
Joined: March 25th, 2010, 9:37 am

Re: Defence strategies? (for the AI)

Post by Darkas »

Thanks to batoonike and jaimeastorga2000 for your suggestions, they sound good :)

Sorrow: Thanks to you too, I think I'll talk to him.
Elvish Scientist
Posts: 62
Joined: February 18th, 2005, 11:06 am

Re: Defence strategies? (for the AI)

Post by Elvish Scientist »

In my opinion improving the recruiting abilities of the AI is more urgent. It tends to ingore the main units and recruits specialists only instead. Exclusively heavy infantry instead of spearmen, no elvish fighters but archers, no drake fighters but clashers and burners only.
Another, less important, flaw is that special abilities (slow, poison, healing) are not used effectively.
csparrow
Posts: 34
Joined: June 5th, 2009, 9:05 am

Re: Defence strategies? (for the AI)

Post by csparrow »

They also need different flavors of AI like one set to spam, master, stalwart, Idiot, and normal. but I understand how difficult that is, well, no I don't, I suck at coding. I sympathize for you developers. You toil all day over mind numbing codes just to have us criticize you.
It is from their foes, not friends that cities learn the lesson of building high walls - Aristophanes
Darkas
Inactive Developer
Posts: 4
Joined: March 25th, 2010, 9:37 am

Re: Defence strategies? (for the AI)

Post by Darkas »

@Elvish Scientist: I'll keep that in mind, maybe it's possible to do that as a part of my project (as far as I can see, it seems rather simple to do that)

@csparrow: I keep that in mind too, I'd really like to do all that, but I might get problems with time :) Thanks for your sympathy :)
User avatar
jaimeastorga2000
Posts: 29
Joined: July 25th, 2009, 12:28 pm

Re: Defence strategies? (for the AI)

Post by jaimeastorga2000 »

Another thing. If any of the AIs units have the slow ability, they should identify the biggest, baddest nearby enemy unit (the one which can inflict the most damage) which hasn't been slowed yet and slow it down, then repeat the process for any remaining slowers. In offense the appropriate follow up would be to gang up on it and kill it while it is weakened, but in defense it is more effective to ignore it while it is weakened and continue forming defensive lines based on terrain (hopefully ones that include the units which were used to slow the enemy unit). If this is done turn after turn, the opponent's biggest attackers lack effectiveness and the attack loses momentum. This should be done before anybody else who is going to attack those units attacks them, of course, to diminish the counter-attack.
Darkas
Inactive Developer
Posts: 4
Joined: March 25th, 2010, 9:37 am

Re: Defence strategies? (for the AI)

Post by Darkas »

I've added all these ideas now to my wiki page (http://wiki.wesnoth.org/index.php?title ... sal_Darkas), so thanks again for your ideas :)

@ElvishScientist: I was told that a recruiting improvement is actually not that easy. Sorry!
fog_of_gold
Posts: 637
Joined: December 20th, 2009, 5:59 pm
Location: Germany

Re: Defence strategies? (for the AI)

Post by fog_of_gold »

Darkas wrote:[...]- In case you have units that are close to leveling up, but not much hp, try to get them killing enemies[...]
Better would be the other way arround:
Use them for tanks. So if you have, let's say 2 experience points left, the enemy have either to kill the unit with two units or have to have at least 5 units circling this unit to attack. So if you use them being careful enough so you won't be circled, you defend wounded units. This is especially in campaigns very useful, where it can be a bad idea to level units(because of upkeep). The ai will nearly level the unit but left one experience point. Of course before you use them this way, you have to heal them and flee away from level 0 units since they won't level but still damage you.
User avatar
FAAB
Inactive Developer
Posts: 52
Joined: November 15th, 2008, 12:15 pm

Re: Defence strategies? (for the AI)

Post by FAAB »

batoonike wrote:-Consider time of day in cases when its obvious, like drakes vs undead, neutrals vs loyalists, and attack or retreat accordingly.
-When retreating because of bad ToD, keep just 1 hex out of the opponents best moves so when ToD changes the AI can react right away.
IMHO that is what of the most important thing when defending: always keep an eye on the time of day.
As batoonlike hinted, you should not only care of the current ToD but the one on the next turn.
It is obvious that you should not have the same behavior with lawful side at dawn or at dusk. Hence knowing only the current time of day is useless. Ideally you should have access to the list of ToD for the next turns [first ToD, is the one of this turn, the next in the list is for next turn and so on]. As a side note, only being able to make the difference between dawn and dusk is not enough. Knowing if you are on first night or second night is very important too when defending (as lawful).

The last comment regarding the ToD is that you should know if the ToD changes after your turn or after your opponent's turn. On defense, loyalist can be more blunt on the second night if the ToD changes after their turn as the opposition (supposed chaotic) will have no more bonus when countering. This information can be get by comparing your side number with your opponent's : the highest side number will get the ToD changed after his turn. But it might cleaner to get a special function to give you this information.

HTH.
We are highly interested in translation for Nightmares of Meloen. Incomplete translations are appreciated too!
So if anyone is kind enough to contribute for a translation, here is the po file to use.
sam_waz_here
Posts: 77
Joined: November 13th, 2007, 7:15 am
Location: under a rock

Re: Defence strategies? (for the AI)

Post by sam_waz_here »

How will your ai impact survival extreme games where the ai needs to attack or the players can't get strong enough to fight the leaders?
Where is the love?
Tet
Posts: 391
Joined: February 18th, 2009, 5:11 am

Re: Defence strategies? (for the AI)

Post by Tet »

Hi there. Just my 5 cent.
Reading this I get the impression the ai will avoid fighting and run at the end. So as the computer has to loose eventually, I would include some Kamikaze/Bansai-attack switch to inflict final damage on the player instead of fleeing into the map corners.
Many scenarios do that allready. There is target setting on enemy leaders. There is: ignore bad combat. This is good if the player starts on defence. However after the first onslaught the ai is getting weak for the mock-up. Building decent defensive position would be cool for the ai. Right now they usually jump into the water, if you offer a bait while playing against ai.

Good luck. Would be nice to have a smarter computer.
My Temple Project: http://forums.wesnoth.org/viewtopic.php?f=23&t=29800
This is "must-play" campaign! Don´t read the thread, unless you need help. http://forums.wesnoth.org/viewtopic.php?f=8&t=31895
User avatar
Maiklas3000
Posts: 532
Joined: June 23rd, 2010, 10:43 am

Re: Defence strategies? (for the AI)

Post by Maiklas3000 »

I wrote this in my review of LoW3: Ka'lian Under Attack, which is basically a defensive struggle for the allied leader until towards the end...
The AI for the allied forces needs to be improved, and it would be nice if the allied forces would cooperate with yours in some sense. I suggest taking a cue from flocks of birds or ant colonies, which self-organize by having each individual operate according to some simple rules. There should be rules like:

* somewhat prefer a hex two away from a friendly unit
* much prefer a hex next to a friendly unit
* more prefer a hex in line with two friendly units
* greatly prefer better terrain (no swimming without a good reason!)
* if you're poisoned, tremendously prefer villages, curers and healers, in that order
* if you're about to level up and are low on hit points, go for an easy kill if available (or easy combat if you just need one point), but otherwise avoid combat and seek healing

It would probably work best to have the computer move each unit one hex at a time, though that would be a big change.
What I'm wanting is that when I form a line, then the AI-controlled allied leader should tend to move his troops up into my line, filling gaps, extending, or waiting behind. The troops should not charge ahead of the line without darn good reason. Again, I think this can be accomplished by each individual unit using bug-like intelligence, i.e., simple rules.

Another thing I've noticed is that healthy units tend to run around wounded units to attack the enemy, even if it means jumping from a fortress into a moat. Then, on the same turn, the wounded units retreat. So now the AI has given up the fortress in favor of the moat. What a disaster. In addition to needing to very highly favor defensive terrain, the AI needs to move wounded units first. Part of the theory here is that there are more places to retreat than there are on the front line, so the wounded units have more places to choose from. You could help the wounded by first moving any healthy units 1 hex off villages... if later in the turn it seems like they should in fact defend the village, they can always move back.

To summarize:

1. Clear villages (and healers) of 100% healthy troops by one hex.
2. Retreat wounded to villages and healers.
3. Advance healthy troops to the line.
Locked