Ai builds fisher huts whithout reachable fish

Bug #1760502 reported by hessenfarmer
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
widelands
Fix Released
Medium
Unassigned

Bug Description

After all fish is caught AI still builds and dismnantles fisher huts in an endless loop

Related branches

Revision history for this message
hessenfarmer (stephan-lutz) wrote :
Revision history for this message
hessenfarmer (stephan-lutz) wrote :
Revision history for this message
TiborB (tiborb95) wrote :

I looked at your replays, but as you did not state coordinates and time where/when to look I gave up.

But I tested own games with Crater and Crossing the Horizonts maps - and did not spotted the behavior. Are you sure you have used at least revision 8637 of the branch?

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

ok I used 8637 for the replay.

for the fisher hut you need to watch for example the region north of the red HQ between 150 and 180 minutes there is no fish left but after dismantling a well the AI builds a fisher hut.

for the other behaviour you can watch for example the red player he has conquered all buildable land after around 60 minutes after that it never attempts to conquer the mountain north north west of its only gold mine. This is where the iron is.
As long as there is any fish to catch it seems that the AI is doing the thing properly but if all fish is caught it is in an erratic mode so on crossing the horizon this is around after 2,5 hours.

Sorry for the trouble

Revision history for this message
TiborB (tiborb95) wrote :

OK, you were right, but reasons were bit different. When fisher is dismantled there is still some fish in vicinity (can be <5) and subsequently AI as it sees fish there, it builds new fisher. Now I see 2 approaches
- increase treshold of fish in vicinity to 10 (for building new fisher)
- keeping fish hut longer after the production falls down

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

Sounds reasonable to me if a threshold of 10 works we could have a look if we can reduce this to 5 perhaps. Currently it is 2 as far as I understand the code.

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

OK I had a look into the code to see whether I could find a reason for the AI not conquering pure Mountain regions.
Reason is it is forbidden to do so.
Problem is in line 2936 following. There are only 2 reasons defined for building a military building. First is to conquer new buildable spots which are defined in ai_help_structs as fields with Buildcaps sizemask, which excludes mines. Second reason is for defence purposes, which is not the case in the given situation. So the Ai will never build a military building to just conquer a pure mountain area. genetic algorithm (score of the building)is only considered if the building is allowed to be built, which is not the case in this special case.

Proposed solution is to add mineable fields to the condition after line 2936 in the code.

Revision history for this message
TiborB (tiborb95) wrote :

Try now please

As for second issue - looks like very good catch, I will prepare a fix for this....

Revision history for this message
TiborB (tiborb95) wrote :

And another factor can be just nearby fisher huts that keep catching fish while a new fisher hut is being built...

Revision history for this message
TiborB (tiborb95) wrote :

I will make another tweak, still not enough..

Revision history for this message
TiborB (tiborb95) wrote :

Is not there some issue with fisher - so that he cannot catch fish if there is road on coast? This could explain these fish that are not possible to catch...

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

I'll test this tonight. the road issue might be part of the problem. will keep it in mind while watching the AI.

I am looking forward for the branch with the second fix as for me this is more important than wasting some building material for fisher huts. Thanks for fixing.

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

Just saw you had already done it in a branch there is a branch \mineable_fields which contains exactly the change perhaps you could merge trunk there and propose a merge so I can test this.

Revision history for this message
TiborB (tiborb95) wrote :

No, I dont have any unmerged branch that would fix the issue. But I am going to prepare one

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

Hi,

did a retest last night. As long as the AI is stuck on the small starting island it tries to build fishermens huts. Unfortunately I don't have any printf messages in my windows log (stdout.txt) only the log("Building a fisher on a x b") messages appear constantly. So I don't have any glue how many fish the Ai is identifying and where this fish is located.
So if you please could send me a Linux log where all the messages appear or perhaps you could change the relevant debug messages from printf to log so I can catch them.

So from what I saw there are a couple of things influencing the fishers mostly they can't reach fish due to immovable like trees or fields, roads could block them as well however after 20 hours gametime they should have caught all of them therefore I really could use the logs to dig to the ground of this issue. Most probably the issue won't appear anymore if the second fix is working which I will try tonight. Yesterday I had one run where the red player left the island by accident and immediately stopped to build fishers on the starting island after having more suitable places for them

Revision history for this message
TiborB (tiborb95) wrote :

OK, I will change the printfs to log, but your description is correct, the issue is visible when:
- there are roads on coast (other immovables are not issue, but roads are special because they are WALK-able for AI algorithm, but blocked for fishers algorithm)
- there are no better places with more fish available

Therefore on most maps this is not a big issue

Revision history for this message
TiborB (tiborb95) wrote :

I replaced printfs for logs and pushed new revision.

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

Hi thanks for the logs. I have investigated the thing a lot, but I think I understand this now.

so the fisher work program demands the fisher to walk to a walkable coordinate where the ressource fish is available. then he extracts fish in aradius of 1. Which means he is able to extract a fish from a field which is not walkable, but only if there is some fish still available at the walkable coordinate. I have confirmed this via the debug window of a development build.

As far as I understand your code you will count the fish at all walkable fields and the first unwalkable field (at least the comment in line 1475 is leading in this direction)

so for me the solution might be just to count the fish on the walkable fields as the workers program does. this will lead uiis to be able to reduce the threshhold to 5 I think and should solve the issue.

So please would you give this change a try I am more than happy to test again.

Revision history for this message
TiborB (tiborb95) wrote :

OK, test now, it should work as you asked for

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

Many thanks for the patience,
Have tested it algorithm works fine now. AI now is really only building fishermens huts where the roads are blocking the fish. This we should be able to cope for with the threshold. from analysing the logs I'd like to propose a threshhold of 15 which is more the less two filed with default amount.
Together with the change you could remove the Debug messages and superfluous comments so we can merge the branch

TiborB (tiborb95)
Changed in widelands:
importance: Undecided → Medium
assignee: nobody → TiborB (tiborb95)
status: New → In Progress
Revision history for this message
TiborB (tiborb95) wrote :

OK, all done and pushed

Changed in widelands:
status: In Progress → Fix Committed
Changed in widelands:
milestone: none → build20-rc1
Revision history for this message
GunChleoc (gunchleoc) wrote :

Fixed in build20-rc1

Changed in widelands:
assignee: TiborB (tiborb95) → nobody
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.