Topic: why the AI don't dismantle the military buildings it's about to lose?

king_of_nowhere
Avatar
Topic Opener
Joined: 2014-09-15, 18:35 UTC+2.0
Posts: 1668
Ranking
One Elder of Players
Posted at: 2015-06-19, 02:47 UTC+2.0

every human, when a military building is going to be conquered, will dismantle it. and when attacked by vastly superior forces, will dismantle before the fight to avoid losing soldiers. there's no harm in it: your opponent can always dismantle it himself if he cannot defend it (there are a few cases where the building is far enough that the opponent cannot dismantle it or he will lose the soldiers, in which case there may be a point in not dismantling; but it's a very rare occurrence). That's a piece of strategy that is fairly intuitive, that everyhuman will use, and yet the AI does not do it. I've seen plenty fo discussion among the pprogrammers on how to teach the AI when to dismantle a conquered building that is not connected to the economy, but that's a situation that only happpens with AI, so by teaching the AI to play like a human the problem would be avoided anyway.

The conditions for dismantling a building are quite intuitive:

  • if a building is going to be conquered by an enemy (enemy soldier going to enter, no defenders left), dismantle it. the basic thing, to slow down the enemy advance.
  • if the enemy is attacking the building, AND power of attacking troops (described using function here https://wl.widelands.org/forum/topic/1742/?page=3#post-13913) is over twice power of defending troops (also counting nearby buildings) AND stronger defending soldier is weaker than weaker attacking soldier, then dismantle it. if all his soldiers are stronger than your soldiers (or your soldiers are too wounded to be of any use), and he also has more soldiers, then he will expect to kill all your soldiers with no losses. better to retreat, and maybe by the time the opponent has advanced you have upgraded your soldiers a bit more
  • if there is one last soldier defending the building, AND the enemy soldier about to engage it has over twice the power (calculated with the same formula as before) then dismantle the building. That basically ensures that if your last soldier is going to face a stronger soldier (or your soldier is too wounded to have any chance), it will survive instead.
  • if there is one last soldier defending the building, AND defending soldier at full hp would have over twice the power of the enemy, but it is wounded enough that it has no more than 130% of enemy power, then dismantle the building. this ensures that if you are defending with a strong soldier against weaker ones, the srong soldier will kill as many roookies as it can, then it will escape before being killed.

count should be updated every time one of the defending soldiers is killed.

I realize that applyiing this principle could lead to the AI never fighting a stronger opponent, and always retreating until it makes a last stand with all his soldiers inside the headquarter. to avoid this, conditions could be set where the AI will defend anyway. they could be

  • if losing the building would mean losing the last warehouse, then defend at all cost. (self-explanatory)
  • if the building is not connected to a warehouse, AND in a 10-step radius there are no friendly roads connected to a warehouse, then defend at all cost (dismantling the buildings would only result in the soldiers wandering around incapable of finding a warehouse until they die). consider passable terrain for this; if there is a warehouse on the other side of a stretch of lava, it is still not connected.
  • if losing the building would damage too much the economy, then defend at all costs. the condition could be triggered by how many non-military (notice: a guardhouse counts as a military building, a training camp for this purpose does not) buildings are in the action radius. giving a score of 1 for a small building, 2 for a medium building, and 4 for a large building, if the military building under attack has at least, say, 15 points in its radius then it willl be defended.

Even in those cases, if the enemy is about to conquer because the last defender died, dismantle the building.

I realize some people prefer to play with an AI whose buildings can be conquered. in which case this behavior could be optionally shut down. or it could be part of a "tournament mode AI" that will use all the human's dirty tricks that casual players may prefer to skip.

Edited: 2015-06-19, 02:54 UTC+2.0

Top Quote
einstein13
Avatar
Joined: 2013-07-29, 00:01 UTC+2.0
Posts: 1116
Ranking
One Elder of Players
Location: Poland
Posted at: 2015-06-19, 03:10 UTC+2.0

king_of_nowhere wrote:

Very good idea!

  • (...) if the military building under attack has at least, say, 15 points in its radius then it willl be defended.

Hmm... 15 points in your idea is like 4 big buildings! It is quite big amount. 4 farms around one building?

OK. I can imagine that situations, but for me it is quite high limit.

Also I don't think that this limit is very important: I can imagine some situations, where this limit should not count. I dismantled few towers with (in your idea) count of ~20 points. I was expected to die- that is true, but defending there was not a good idea.

I realize some people prefer to play with an AI whose buildings can be conquered. in which case this behavior could be optionally shut down. or it could be part of a "tournament mode AI" that will use all the human's dirty tricks that casual players may prefer to skip.

Yes, dismantling military building IS a trick, so it should be with "moderate" and "hard" mode of AI, if we create few difficulty levels. I can't imagine that easy one will use those tricks to win face-tongue.png


einstein13
calculations & maps packages: http://wuatek.no-ip.org/~rak/widelands/
backup website files: http://kartezjusz.ddns.net/upload/widelands/

Top Quote
Tibor

Joined: 2009-03-23, 23:24 UTC+1.0
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2015-06-19, 21:09 UTC+2.0

Well, few words about the question.

Persnally I dont like such dismantling because in reality it does not work this way. But I know some players are using this approach quite extesivelly.

On the other side, AI is not capable of retreat - and this is generall problem.

Not only when attacked, by also when it is short of available soldiers and still has no mines (f.e.). It would be suitable to dismantle some military sites in noncritical areas.

With my current knowledge of battles in widelands I dont know how to do it. I believe there is a battle object, linked to attacked building and that battle object has linkage to involved soldiers - if it is the case it would be possible to gather some of required info needed for calculation.

Right now I have some branch waiting for merge, but I will keep this request in mind.


Top Quote
king_of_nowhere
Avatar
Topic Opener
Joined: 2014-09-15, 18:35 UTC+2.0
Posts: 1668
Ranking
One Elder of Players
Posted at: 2015-06-21, 21:48 UTC+2.0
  • (...) if the military building under attack has at least, say, 15 points in its radius then it willl be defended.

Hmm... 15 points in your idea is like 4 big buildings! It is quite big amount. 4 farms around one building?

OK. I can imagine that situations, but for me it is quite high limit.

Also I don't think that this limit is very important: I can imagine some situations, where this limit should not count. I dismantled few towers with (in your idea) count of ~20 points. I was expected to die- that is true, but defending there was not a good idea.

Like most of our differences in opinions, this arise because you think mostly in terms of big maps, and i think mostly in terms of small maps. In a big map, you can afford to lose 4 farms and you'll barely notice. In a small map, losing 15 points as I defined them is probably enough to completely stop your economy, and you don't have the space to rebuild elsewhere, so you may as well make your last stand there. Anyway, all the numbrs need to be playtested if the idea is implemented. I only did some rough guessing.

Well, few words about the question.

Persnally I dont like such dismantling because in reality it does not work this way. But I know some players are using this approach quite extesivelly.

In my experience in the tournament, every player did that. when they are attacked by level 10 soldiers and could not defend themselves, they dismantled to cut their losses. When I was attacked by greater numbers, I dismantled before my soldiers were in danger of death. And in any case a building about to fall was dismantled. the only times I remember a building actuallly being captured was when there was a big battle with many buildings involved, so a human may fail to notice some of them. I intentionally did that against kuvastin, i launched a large attack against a building and simultaneously sent 2 soldiers against a tower on the other side. it worked, the opponent was distracted by the main attack and did not notice the tower. i conquered it, and it gave me vision to the headquarter, allowing me to attack and burn it and kill the opponent quickly. which showcases how important dismantling can be.

And programmers often say that they would like to make the AI more human-like, so I wondered, that's a real big difference between human and AI, why not to include it?

As for the detail of the programming, I have no idea how to do that. I think the algorithms I proposed should be easily understood by an AI, but I have no experience of actual programming.

Edited: 2015-06-21, 21:48 UTC+2.0

Top Quote
einstein13
Avatar
Joined: 2013-07-29, 00:01 UTC+2.0
Posts: 1116
Ranking
One Elder of Players
Location: Poland
Posted at: 2015-06-22, 01:23 UTC+2.0

king_of_nowhere wrote:

  • (...) if the military building under attack has at least, say, 15 points in its radius then it willl be defended.

Hmm... 15 points in your idea is like 4 big buildings! It is quite big amount. 4 farms around one building? (...)

Like most of our differences in opinions, this arise because you think mostly in terms of big maps, and i think mostly in terms of small maps.

I was thinking about loosing your position on big map: you have only few more space around your headquaters, which is rather empty (all resources are moved to other spots), and you want to have more time to prepare defence in other spot. So it is better to loose your farms in current frontline, just to give some time and save warriors. And yes, that is connected mostly to big maps. But after your answer I have another (better?) idea, how to calculate points:

In a big map, you can afford to lose 4 farms and you'll barely notice. In a small map, losing 15 points as I defined them is probably enough to completely stop your economy,

So basic calculation should consider how many buildings you will lose. Imagine that you have 50 farms. Loss 5 of them is 10%. Different situation is when you have only 8 farms and you expect to lose 5 of them (62,5%). I don't have complete equation for that, but general idea. It will solve difference between big (lots of place) and small (not enough place) maps.

The total points don't have to be integer, they can be float numbers face-smile.png So we can imagine a math model calculating percentage of loss and use that for decision. It should be like:

  • i - different types of buildings (Farms, wells, mills, woodcutters, etc.)
  • p_i - percentage of potential loss of i-type building
  • b_i - basic points for each building (as default 1, 2 or 4)
  • n_i - number of potential destroyed i-type buildings.
  • points = Sum_[for each i] (b_i * n_i * (2*p_i) )

This is only a small change. Your idea is like:

  • points = Sum_[for each i] (b_i * n_i)

If you lose 100% of a building, it counts twice. If you lose only 10%, it counts with 0.2 factor (0.8 point for each farm, for example). Basic points are for 50% loss.

Equation is not strict now. It can change, as well your idea of points face-smile.png It is made up few minutes ago face-wink.png

What do you think?


einstein13
calculations & maps packages: http://wuatek.no-ip.org/~rak/widelands/
backup website files: http://kartezjusz.ddns.net/upload/widelands/

Top Quote
Tibor

Joined: 2009-03-23, 23:24 UTC+1.0
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2015-06-22, 19:32 UTC+2.0

Next turn when I will work on AI I will look also on this stuff. It depends on how difficult it would be to implement. But I dont say "no" face-smile.png


Top Quote
king_of_nowhere
Avatar
Topic Opener
Joined: 2014-09-15, 18:35 UTC+2.0
Posts: 1668
Ranking
One Elder of Players
Posted at: 2015-06-22, 20:01 UTC+2.0

einstein13 wrote:

... What do you think?

I think we are putting the metaphorical cart in front of the metaphorical horse here. first we need some programmer to get interested in this idea (thanks tibor), then we need him/her actually putting it into code - which, as I understand, is not so easy: right now AI does nothing in the battle except deciding when to attack, so it would require writing a lot of new code - and then we can start playtesting and acctually tweaking the numbers.

Yes, I suppose that taking into account the total dimension of the economy would be the best way to decide when to make a last stand, but we are fairly early in the planning. You may also notice that the condition I set for retreating (twice as much power in the attack than in the defence, and the weaker attacking soldier being stronger than the stronger defending soldier) is also extremely conservative.

Also, I prefer to start on the conservative side. right now, the AI never retreats. If the AI retreats a small number of times, when retreating is surely the best action, then that's an improvement. If the AI retreats often, including some times when it should not, we have just changed a weakness with a different one. By making the AI very unlikely to retreat, we can never do worse than the current situation.


Top Quote
einstein13
Avatar
Joined: 2013-07-29, 00:01 UTC+2.0
Posts: 1116
Ranking
One Elder of Players
Location: Poland
Posted at: 2015-06-22, 21:30 UTC+2.0

Ok, I get your point, king_of_nowhere. So I will have more patient now face-smile.png

And Tibor: if you will have any trouble with coding (any math problems, equations needed or anything like that), we are open to help you. I can't write in C++, but testing for sure, plus math ideas face-wink.png


einstein13
calculations & maps packages: http://wuatek.no-ip.org/~rak/widelands/
backup website files: http://kartezjusz.ddns.net/upload/widelands/

Top Quote
teppo

Joined: 2012-01-30, 09:42 UTC+1.0
Posts: 425
Ranking
Tribe Member
Posted at: 2015-06-24, 03:23 UTC+2.0

I dislike dismantling/burning military sites under attack altogether. The defender effectively forces a superior attacker to retreat, by starting to carry mattresses away. I know that WL does not aim towards realistic warfare, but still that is odd.

This play style requires that player observes individual battles, ready to click a button at a critical moment. In my opinion this moves the focus from economy towards battles. When everybody is doing it, AI doing it too makes sense though.


Top Quote
Stefan
Avatar
Joined: 2015-06-24, 21:42 UTC+2.0
Posts: 7
Ranking
Pry about Widelands
Posted at: 2015-06-24, 21:48 UTC+2.0

I agree with teppo. I also dislike the idea of dismantling military buildings under attack. In my opinion it is a better idea to prevent the human players to dismantle a building under attack instead of making the AI do the same thing.


Top Quote