Latest Posts

Topic: Improving the AI

hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 1099
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2020-02-08, 12:12

GunChleoc wrote:

Actually, tribe_->refinedlog() is still being used, so it has to stay. For example:

~~~~ if (!(temp_buildcosts.first == tribe_->rawlog() || temp_buildcosts.first == tribe_->refinedlog() || temp_buildcosts.first == tribe_->granite())) { bo.critical_building_material.push_back(temp_buildcosts.first); } ~~~~

Ok I analyzed the code about refinedlog.
It is only used in 2 occasions:
1. to exclude it from the criritcal building materials for military sites
2. to exclude it from the criritcal building materials for training sites

I believe this to be wrong because on many occasions refinedlog is the most critical building material in fact. So I suggest to get rid of it completely. Furthermore it might be good to exclude granite from milsites critical building material as it is in the other sites.


Top Quote
Tibor
Joined: 2009-03-23, 23:24
Posts: 1316
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2020-02-08, 20:33

The idea behind this is:

The building material is split into two types:

  • "trivial" like log, planks, rocks - just as excluded in the code - this is material that will eventually come to the building site
  • "non-trivial" - the rest of building material - usually produced in special site - mine or some complex productionsite - that might never come if such producer does not exist

For example when considering building of new militarysites - they are split to two types: trivial-material-only and non-trivial-material-also and the latter type checks the presence of non-trivial material on stock.The trivial-material-only sites can be build always

Also search for BuildingAttribute::kBuildingMatProducer in the code

So this has bigger effects that presented, this should be considered, reviewed, tested and also IMHO the reason for this change is wrong - to removing some attributes for the sake of removing.

Alternatively you can consider some new AI hints like "produces_non_trivial_building_material" for mines/productionsites, and "needs_non_trivial_building_material" for some militarysites. Please consider this.

So I am not in favour of this change


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 1099
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2020-02-08, 20:48

Tibor wrote:

The idea behind this is:

The building material is split into two types:

fully understood and reasonable.

  • "trivial" like log, planks, rocks - just as excluded in the code - this is material that will eventually come to the building site

problem was this was not equal for all types of buildings refinedlog was only crirical for milsites and trainsites not for prodsites. granite was not critical for trainsites and so on.
futhermore in most cases refinedlog is not trivial as it is the material which is often to rare. think of barbarian blackwood.

  • "non-trivial" - the rest of building material - usually produced in special site - mine or some complex productionsite - that might never come if such producer does not exist

For example when considering building of new militarysites - they are split to two types: trivial-material-only and non-trivial-material-also and the latter type checks the presence of non-trivial material on stock.The trivial-material-only sites can be build always

Also search for BuildingAttribute::kBuildingMatProducer in the code

So this has bigger effects that presented, this should be considered, reviewed, tested and also IMHO the reason for this change is wrong - to removing some attributes for the sake of removing.

it is not for the sake of removing it was just to clean the code. I found a wrong positioned loop as well you might look at the diff. However refinedlog wasn't used very prominent and for me defining it as trivial isn't true.

Alternatively you can consider some new AI hints like "produces_non_trivial_building_material" for mines/productionsites, and "needs_non_trivial_building_material" for some militarysites. Please consider this.

So I am not in favour of this change


Top Quote
Tibor
Joined: 2009-03-23, 23:24
Posts: 1316
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2020-02-08, 21:07

Well, I agree that this can be improved, or perhaps to consider also new tribes.

But as for current tribes - the AI will always build rangers, wood cutters and wood hardener (the last one is part of basic economy) - so we can safely presume that production of hardened wood is secured, although might be slow.

However if we dont have something like crystal mine - we just dont have it. And might never have.

AI should know that buildings X, Y, Z are special, even thoug are not part of basic economy (mines cannot be), we must prefer them.

The result of this might be that AI will never build a military site as it will first check if it has enough hardened wood on stock - and it might not have.... and will wait till sufficient hardened wood will be on stock.

You should at least test it with few AI-only games - if the change is for better....

I will look at the diff about that loop


Top Quote
Tibor
Joined: 2009-03-23, 23:24
Posts: 1316
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2020-02-08, 21:11

You seems to be right about the loop


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 1099
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2020-02-08, 22:36

Tibor wrote:

Well, I agree that this can be improved, or perhaps to consider also new tribes.

But as for current tribes - the AI will always build rangers, wood cutters and wood hardener (the last one is part of basic economy) - so we can safely presume that production of hardened wood is secured, although might be slow.

However if we dont have something like crystal mine - we just dont have it. And might never have.

As you said we already included everything needed to not deadlock in basic econmy. Which works well. After basic economy established buildings producing wares that are short are getting a bonus. this works well so in general AI builds the right buildings.

AI should know that buildings X, Y, Z are special, even thoug are not part of basic economy (mines cannot be), we must prefer them.

In fact empire Marblemine and atlantean crystalmine are part of basic economy.

The result of this might be that AI will never build a military site as it will first check if it has enough hardened wood on stock - and it might not have.... and will wait till sufficient hardened wood will be on stock.

if not enough of a ware on stock the shortage of buildmaterial in the building observer will be set. However this just gives some penalty to the score whis is controlled by Genetics. It won't prevent the building build but less big buildings might be build if not enough Blackwood (barbarians), planks (atlanteans and empire), bricks (frisians) or rope (amazons) is available. Sometimes they never get finished due to the lack of these materials.

You should at least test it with few AI-only games - if the change is for better....

I tested it with my usual setup on Full Moon. I couldn't see much difference however this was impaired by using the charcoal change which is weird and shopuld not go in. If at all AI uses only small buioldings for first expansion not medium ones anymore.

I will look at the diff about that loop

An I will have another look into the MatProducer attribute.

EDIT: Done setting of the attribute kBuildingMatProducer is only considering granite and log as trivial, as do the building observers of all types of building now (aftrer my changes) as well.

        for (DescriptionIndex ware : bo.ware_outputs) {
            // building material except for trivial material
            if (tribe_->is_construction_material(ware) &&
                !(ware == tribe_->rawlog() || ware == tribe_->granite())) {
                bo.set_is(BuildingAttribute::kBuildingMatProducer);
                if (bo.type == BuildingObserver::Type::kMine) {
                    mines_per_type[bo.mines].is_critical = true;
                    mine_fields_stat.add_critical_ore(bo.mines);
                }
            }
        }
Edited: 2020-02-08, 22:44

Top Quote
Tibor
Joined: 2009-03-23, 23:24
Posts: 1316
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2020-02-09, 14:33

OK, after some thinking I think it can work - I mean including the processed wood into critical building materials, but still each tribe should have at least one militarysite built purely from trivial materials.

But I must comment on the basic economy concept. This is set of buildings that can be built as soon as possible, providing there is enough building space. Should not include sites that are terrain dependent, as it is not guaranteed that such terrain is within the reach of AI within ~one hour of gametime. However there is 120 minutes timeout for basic economy - if not achived before, AI gives up and proceeds as if basic economy was achieved.

So if you include some mines in basic economy, and AI does not have it, it restricts AI only in first two hours...

This was my idea when I created the concept.

Also a comment about building material producers: If we have building material producers within basic economy, the concept of this flag becomes less needed, but is still usefull.


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 1099
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2020-02-09, 15:12

Tibor wrote:

OK, after some thinking I think it can work - I mean including the processed wood into critical building materials, but still each tribe should have at least one militarysite built purely from trivial materials.

that is not the case anymore if we count processed wood or the new tribes processed materials as critical. However it doesn't do any harm to the AI as bigger buildings are only more discouraged then now but not prevented after the processed wares are available in sufficient amount it performs as normal. I had a playtest on Full Moon and the frisians in 4th position won in 13:10 which is the fastest AI win I have seen on this so far.
By the way the threshold to declare shortage is dependent on the Building by this productionsites get penalized less often then Military sites. If necessary we could invent a seperate treshold for small military buildings, but I don't deem this necessary.

But I must comment on the basic economy concept. This is set of buildings that can be built as soon as possible, providing there is enough building space. Should not include sites that are terrain dependent, as it is not guaranteed that such terrain is within the reach of AI within ~one hour of gametime. However there is 120 minutes timeout for basic economy - if not achived before, AI gives up and proceeds as if basic economy was achieved.

So if you include some mines in basic economy, and AI does not have it, it restricts AI only in first two hours...

that is correct but especially empire depends on having at least one marble mine to build up an economy so if there isn't stones somewhere they are restricted anyway. Same but not that strict for atlanteans with quartz.

This was my idea when I created the concept.

Also a comment about building material producers: If we have building material producers within basic economy, the concept of this flag becomes less needed, but is still usefull.

Never doubted that I just wanted to say that for this flag refined log was never seen as "trivial" material, as I didn't change anything in the code sniplet provided in my last post.

Edited: 2020-02-09, 15:12

Top Quote
Tibor
Joined: 2009-03-23, 23:24
Posts: 1316
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2020-02-09, 15:33

Please check the code here:

https://github.com/widelands/widelands/blob/8217940d2daf7989ff8ce4aae5a2805c6a9dfa77/src/ai/defaultai.cc#L2515

I really think having one trivial-only military site per tribe cannot do any harm.

Also more tests that one game is needed, we have 4 tribes and there is a lot of randomness in results...

Well, "trivial" is just a world, in real life this is like grain vs gold. With some effort you can grow more and more grain basically out of nothing, but you cannot get gold the same way


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 1099
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2020-02-09, 16:32

Tibor wrote:

Please check the code here:

https://github.com/widelands/widelands/blob/8217940d2daf7989ff8ce4aae5a2805c6a9dfa77/src/ai/defaultai.cc#L2515

I know this code as stated in my last post. It is where according to different tresholds the buildmaterial_shortage flag is calculated. this is used later on to discourage this type of building on a single spot. But if other values generate enough positive score it will be build anyhow.

I really think having one trivial-only military site per tribe cannot do any harm.

No it can't but it isn't necessary. As AI stil expands and it expands not slower then before. So I guess expansion generates mor positive score then this is generating negative score.

Also more tests that one game is needed, we have 4 tribes and there is a lot of randomness in results...

I always let them all fight against each other. I will run a second one now with shifted positions.

Well, "trivial" is just a world, in real life this is like grain vs gold. With some effort you can grow more and more grain basically out of nothing, but you cannot get gold the same way

Again this is fully understood. My point was that in the code for defining a building that produces build material the refinedlog was always treated as it is now for all building observers. So my change more the less harmonized the treatment of the refinedlog ware for all instances in our code.
Furthermore it is not always log. As for the Frisians we declared brick as refinedlog.


Top Quote