News:

Want to praise Simutrans?
Your feedback is important for us ;D.

Limit the length of AI bridge

Started by z9999, May 02, 2009, 01:13:27 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

z9999

In nightlies, AI build too long bridges, I don't like this.
Please limit the length of AI bridge as before. by way_max_bridge_len.

Dwachs

Imho, this problem should better be solved by adapting the pak's, ie setting a maximum length for this bridge.

How should the ai know that you do not like such long bridges?

The ai (in fact the way builder) decides to build the long bridge. This decision making needs an upgrade too.
Parsley, sage, rosemary, and maggikraut.

z9999

Quote from: Dwachs on May 04, 2009, 05:55:46 AM
Imho, this problem should better be solved by adapting the pak's, ie setting a maximum length for this bridge.

If it is possible to limit the length anyway, way_max_bridge_len is better than max_length.

Quote from: Dwachs on May 04, 2009, 05:55:46 AM
How should the ai know that you do not like such long bridges?

By way_max_bridge_len. I set this value 3 or 4. It is enough to build a bridge.
AI should know I don't like loger bridge that way_max_bridge_len.

If AI was clever enough, they would think maintenance cost of bridges.

I have an interesting game. These 2 bridges was made by AI, when the fisrst time AI could build it, length was not limited yet.
I'm not sure current AI could build such a clever way or not.

gerw

Quote from: z9999 on May 04, 2009, 07:21:57 AM
I'm not sure current AI could build such a clever way or not.
He could. It's the only way, to connect the desired station tile. There isn't any check about maintenance or building costs.

Dwachs

Here is a patch. It will affect all players. Maybe you want exclusive rights for the human player?


===================================================================
--- bauer/brueckenbauer.cc      (revision 2447)
+++ bauer/brueckenbauer.cc      (working copy)
@@ -182,6 +182,12 @@
                length ++;
                pos = pos + zv;

+               // test max length configured in simuconf.tab
+               if(length > welt->get_einstellungen()->way_max_bridge_len) {
+                       error_msg = "Bridge is too long for this type!\n";
+                       return koord3d::invalid;
+               }
+
                // test may length
                if(besch->get_max_length()>0  &&  length > besch->get_max_length()) {
                        error_msg = "Bridge is too long for this type!\n";
Parsley, sage, rosemary, and maggikraut.

gerw

I think, it should not affect the brueckenbauer directly. It should be placed in wegbauer_t::check_for_bridges, in order to limit only the length of bridges built by the wegbauer.

Dwachs

second try:


Index: bauer/brueckenbauer.cc
===================================================================
--- bauer/brueckenbauer.cc (revision 2449)
+++ bauer/brueckenbauer.cc (working copy)
@@ -169,7 +169,9 @@



-
+// tries to find a suitable end tile for bridge
+// .. starting at pos in direction zv
+// .. if ai_bridge is true then the shortest possible bridge is returned
koord3d brueckenbauer_t::finde_ende(karte_t *welt, koord3d pos, koord zv, const bruecke_besch_t *besch, const char *&error_msg, bool ai_bridge )
{
const grund_t *gr1; // on the level of the bridge
@@ -182,7 +184,13 @@
length ++;
pos = pos + zv;

- // test may length
+ // test max length configured in simuconf.tab
+ if(length > welt->get_einstellungen()->way_max_bridge_len) {
+ error_msg = "Bridge is too long for this type!\n";
+ return koord3d::invalid;
+ }
+
+ // test max length
if(besch->get_max_length()>0  &&  length > besch->get_max_length()) {
error_msg = "Bridge is too long for this type!\n";
return koord3d::invalid;
@@ -254,7 +262,7 @@
}
}
if(gr2->get_grund_hang()==hang_t::flach) {
- if(  ai_bridge  &&  !gr2->hat_wege()  &&  !gr2->get_leitung()  ) {
+ if(  (ai_bridge || length == welt->get_einstellungen()->way_max_bridge_len)  &&  !gr2->hat_wege()  &&  !gr2->get_leitung()  ) {
return pos;
}
if(gr2->get_typ()==grund_t::boden  &&  !gr2->get_halt().is_bound()) {



So I implemented two options:

1) All bridges are limited by way_max_length
2) The longest bridge built by ai has length=way_max_length

Both things can be enforced separately. What would you prefer?
Parsley, sage, rosemary, and maggikraut.

prissi

The bridge length sould use the pak settings. However, for AI a seperate delimiter is needed. It should imho only limited AI bridge length.

Dwachs

#8
To achieve this, the ai_bridge has to be extended to allow for the distinction
(a) find shortest / longest bridge
(b) use way_max_length or not
I.e. bool ai_bridge -> uint8 ai_bridge

Patch attached :)
Parsley, sage, rosemary, and maggikraut.

gerw

I would suggest the following:
static koord3d finde_ende(karte_t *welt, koord3d pos, koord zv, const bruecke_besch_t *besch, const char *&msg, uint8 type=0 );
If type==0 => use current (non ai) behaviour
If type>0 => Limit size by way_max_bridge_len + get koord3d of type.th free tile.

With this behaviour, the AI has more possibilities to build bridges. This would also allow to build bridges in some situations, where currently no bridges can be built.

Dwachs

Quote from: gerw on May 07, 2009, 07:57:42 AM
If type>0 => Limit size by way_max_bridge_len + get koord3d of type.th free tile.

coudl oyu epxalin plesae?

The case type=0 is already in the patch. But I dont understand what you mean for type>0.
Parsley, sage, rosemary, and maggikraut.

gerw

type = 1 => return first free tile
type = 2 => return second free tile
and so on. But if the tile is more than way_max_bridge_len away, return koord3d::invalid.

If you have the following tile configuration, and wan't to build a bridge up-down:

Free
River
Free
River
Free

Then the first tile is between the two rivers, and the AI won't find a way with the current algorithm. But the second free tile is behind the river and all is fine...

Dwachs

#12
thanks, I got it now. Should be no problem to implement this.

What about this:

The way builder for ai's test every possible length for bridges between 1 and way_max_length? Of course then more tiles are visited in the way builder, but it should not increase computing times alot.
Parsley, sage, rosemary, and maggikraut.

gerw

Yes, it should be easy. I can do this, if I find some free time... Maybe tomorrow.

Dwachs

#14
new patch, with the behavior as in my previous post.

edit: brueckenbauer::baue calls finde_ende itself. this might cause troubles, if the brueckenbauer finds a different end tile than the way builder.
Parsley, sage, rosemary, and maggikraut.