AI makes shipyard away from sea

Bug #1554267 reported by king of nowhere
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
widelands
Won't Fix
Medium
TiborB

Bug Description

It happened that i was playtesting a map with seafaring and the ai made a shipyard in a place too far from water. it was close to a river one tile wide, where boats cannot be built; it sits useless. but the ai cannot figure it out; it hasn't dismantled the shipyard, nor has it made a new one in a better place.
built is 7852.

Revision history for this message
king of nowhere (lainluigi86) wrote :
Revision history for this message
king of nowhere (lainluigi86) wrote :
Revision history for this message
TiborB (tiborb95) wrote :

This is indeed something that is not polished. Shipyard is just built close to water, no further checks are done. I will look at it

Changed in widelands:
importance: Undecided → Medium
assignee: nobody → TiborB (tiborb95)
status: New → Confirmed
Revision history for this message
king of nowhere (lainluigi86) wrote :

the shipyard gives a message if it cannot find a place to make boats. using that message to decide to dismantle and build elsewhere could be a good starting point

Revision history for this message
TiborB (tiborb95) wrote :

yes, this can mitigate the problem

Revision history for this message
GunChleoc (gunchleoc) wrote :

Maybe you can access that code to make the decision where to build in the first place?

Revision history for this message
TiborB (tiborb95) wrote :

The problem is to define which "water" is good for seafaring - big enough (biggest one), that means perhaps some scanning the map (~cheating) on AI initialization, to identify target water and then make sure a shipyard is close to the water, but there is no other water nearby, because shipyards builds the ship randomly.

It is not that trivial and AI has no data structures for this logic.

And this is the same problem again - AI has no understanding of space...

Also a big map has over 250 000 fields, and I am not very eager to create data objects with like 100 000 items - fields of target water.

I am working on road rework now and will look at this issue afterwards....

Revision history for this message
king of nowhere (lainluigi86) wrote :

The important factor, what a shypyard needs, is a corner bordered by 6 fields of water. that's the prerequisite for a shypyard working, so if nothing else it should be easy enough to instruct the AI to look not for a field of water, but for a corner surrounded only by water. That would at leaast fix the problem with rivers,, and should be really quick to do.

It still won't help in case the AI builds the shypyard on a small lake. That would require study of the connectivity on water, which I assume will be complex to code. But there is a quick fix for that too. I noticed that the AI only made one shipyard; if it was instead instructed to make more if a port has a long-standing request for ships, and if there is enough wood and stuff in stock, then the Ai would eventually make a shipyard in a better place (to make this more likely, it could be convenient to add that the shipyard should possibly be far away from already existing shipyards, and close to the ports that are not served by ships).
 By the way, enabling the AI to make more than one shipyard is also needed in case the seafaring happens on several, unconnected bodies of water.

Revision history for this message
TiborB (tiborb95) wrote :

You mean the shipyard cannot build a ship on straight coast? This does not fit my experiences....

One-water approach has benefits:
- you can built ports anywhere
- you can place shipyard anywhere and one is enough
- you can pick any ship for expedition
- when tracking ships utilization, all ships are calculated together

Multi-water approach means
- you must identify all distinct waters beforeahead
- you must exactly know where (by which water) ports can be build
- the same with shipyard(s), moreover here you must take care it is not positioned between two distinct waters....
- if you need another ship, you must decide for which water it must be (which shipyard should produce it)

Generally, AI must exactly know which ports+ships belong together, basically it means two or more concurrent and independent seafaring "managements". This is quite a lot of work.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Yes, definitely a lot of work. So, checking for 6 fields like Kaputtnik suggested and risk ending up on the wrong water / a lake would be a better strategy for a fast improvement, even if the results won't be perfect.

Revision history for this message
king of nowhere (lainluigi86) wrote :

@ tibor: it's not a matter of straight coast, it's a matter of it being a coast and not a river. ships always navigate in corners completely surrounded by water, so if one is not available, the ship ccannot be made. Anyway, it just need to check for a water corner instead of a water field, and it avoids the river problem.

As for the multi-water part, I'm not sure I understand what you mean, but if I understand correctly, I have a question: how does the program deal with a situation when there are two lakes, with ports on both, and the lakes are not connected by water? Certainly in that case you need more than one shipyard, because you need ships on both lakes. As far as I know, there is no map with such a feature; I made one back in the times before I went online, but it crashed after a while, maybe because of that.
Luckily, the current routing approach works for multiple lakes - the boat arrives to a port, loads the wares, and brings them to other ports. As long as the routing program in the wares check that the two ports are connected by water, the wares will always be delivered. But what happens when a port asks for an expedition, and there are no ships in that lake?

Now, while making full provisions for such a case would certainly be complex, there are easier ways to at least mitigate the problem:
1) the AI is allowed to build multiple shipyards if there is nothing more urgent to do (maybe controlled by a timer like "don't build more than one shipyard before three hours", or "only make shipyard if you have at least 50 trunks and 20 planks in stock")
2) If a port has required a ship (to carry an expedition or transport wares) and none has arrived in 30 minutes, and there are no shipyards in construction, build another shipyard near that port.

I'm sure those two relatively simple instructions would deal with it, like, 99% of times.

Revision history for this message
TiborB (tiborb95) wrote :

Well current implementation is really plain. F.e. if shipyard is to be build, it just counts water fields in some radius, if above treshold - field is a candidate for shipyard. No further check. Usually it works good enough, but obviously more sophisticated test is needed.

When I talk about 'water' I mean 'interconnected sailable water surfaces'. 'Lakes' and 'rivers' are human view, AI is too stupid to understand the concept.

So if you have two 'waters', there is a shipyard nearby first one and port on second one, port will forever wait for ship and shipyard will never build a second ship because first one will sit idle and thus no further ship is needed.

My idea is AI that is aware of multiple waters but uses only one of them for seafaring.

Ideally it would be nice to partition the map, so that it would be obvious where a shipyard can be built for particular water. Also it would identify which water fields are in fact sailable and which are too narrow or so...

The game engine uses the concept fleet, that is ports + ships, AI can access it but it is ex-post information, and shipyards (or perhaps adjacent coast that are exclusive for one water) are not included there.

Buidling second shipyard is partial solution, but it is still very chancy. And then AI should be able to figure out which one should build a next ship and this means separate tracking one fleet and other fleet.

After all "multiple-water aware single-water seafaring" solution seems the best for me, but I will be thinking about it.

Revision history for this message
king of nowhere (lainluigi86) wrote :

there could be maps with multiple not interconnected sailable places, and sooner or later someone will have to make the distinction in the code to make it work. I had some vague ideas of making such a map myself.
But for now, changing the requirements from fields to corners is certainly a step ahead.

Revision history for this message
TiborB (tiborb95) wrote :

I think there is such map -concentric rings - it is yours, is not it? And for sure there is couple of other such maps...

I was looking into code trying to find a code used for shipyard for placing a new ship - but failed. I wanted to reuse the logic...

Anyway, I introduced new counter "open water nearby" in addition to "water nearby", the open water is field where all 6 adjacent triangles are water, while the latter is a field where any of 6 triangles is water.

You narrow rivers are now properly identified as non-sailable. It is very minimalistic but should improve the situation..

Revision history for this message
king of nowhere (lainluigi86) wrote :

oh, right, i forgot about concentric rings. so, if that map never crashed in about 100 hours i played on it with different tribes, then the water transport algorithm can actuallly handle multiple bodies of water. it's only the ai that cannot deal with it.

Revision history for this message
TiborB (tiborb95) wrote :

Yes, fleet's are independent objects, they know about own ships, ports and wares with their target ports and does not know anything beyond. Game can create many of them and just add/remove ships/ports into/from them. They mainly calculate routes for ships. Expedition ship is taken out of fleet.

If AI has to have multi-water design it will have to create also some kind of objects linked to fleets, the problem is that such AI objects should exist before a fleet is created. Also there is no link between shipyards and fleets.

And this game is not about seafaring so it is question if it is worth of effort.

Revision history for this message
GunChleoc (gunchleoc) wrote :

I think the first step here to be fleet-aware would be to link the shipyard to the fleet - this way, the AI could at least decide which shipyard to use when building a ship.

Revision history for this message
TiborB (tiborb95) wrote :

Yes, I can imagine a fleet_observer object and move part of current logic into it..

Revision history for this message
GunChleoc (gunchleoc) wrote :
Changed in widelands:
status: Confirmed → Won't Fix
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.