Inconsistency in the AIRoad class

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
Maninthebox
Engineer
Engineer
Posts: 113
Joined: 08 Aug 2008 11:35
Contact:

Inconsistency in the AIRoad class

Post by Maninthebox »

The road class has a function called GetNeighbourRoadCount which does pretty much what you'd expect given it's name, but not entirely :) I would expect such a function to return the same value as having a for loop going over all 4 neighbours and use IsRoadTile() on those and count the amount of trues. Unfortunately, it doesn't, as IsRoadTile counts drive through stations as road, whereas GetNeighbourRoadCount doesn't. Is this intentional? If not, could this get changed perhaps?
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: Inconsistency in the AIRoad class

Post by Zutty »

I'm not sure what the API function is meant to do, but it might be best to re-evaluate your approach.

Are you a content entrant? If so I wont ask you to post any code but can you tell us what you are trying to achieve with GetNeighbourRoadCount()?

Perhaps you should have a special case for DTRSs. I know that might upset the elegance or simplicity of your current solution, but IMHO robustness is more important. The tricky thing with DTRSs is that they MIGHT not be facing the right way, so just using IsRoadTile() on a DTRS isn't enough to say whether or not you can plow a route through it.

Imagine a situation like this...
dtrs-problem.PNG
dtrs-problem.PNG (8.8 KiB) Viewed 2334 times
In step 2 the town just randomly builds a bit of road that happens to conenct to the wrong side of a DTRS. Then in step 3 the pathfinder comes along, sees that IsRoadTile() for the DRTS returns true, and tries to make an invalid connection.
PathZilla - A networking AI - Now with tram support.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Inconsistency in the AIRoad class

Post by Yexo »

Zutty wrote:In step 2 the town just randomly builds a bit of road that happens to conenct to the wrong side of a DTRS. Then in step 3 the pathfinder comes along, sees that IsRoadTile() for the DRTS returns true, and tries to make an invalid connection.
The last thing is not true, since the pathfinder uses BuildRoad in testmode to see if the route can be build, so it will never find a route though the wrong side of a drive-through station.
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: Inconsistency in the AIRoad class

Post by Zutty »

Oh I didn't know that, but then that depends on whether or not he is using the library pathfinder.

Really I was just trying to demonstrate that simply using IsRoadTile() isn't enough. I'm sure everyone knows this already anyway!
PathZilla - A networking AI - Now with tram support.
wilco_moerman
Engineer
Engineer
Posts: 70
Joined: 05 Jun 2008 15:51

Re: Inconsistency in the AIRoad class

Post by wilco_moerman »

Something related to this. I noticed that if you build a tunnel with minimum length (entrance and exit are adjacent tiles) that AIRoad.AreRoadTilesConnected(tunnel_entrance, tunnel_exit) returns false.

I don't know if this is by design or if it is a bug?
Nunc dimittis servum tuum Domine secundum verbum tuum in pace
Maninthebox
Engineer
Engineer
Posts: 113
Joined: 08 Aug 2008 11:35
Contact:

Re: Inconsistency in the AIRoad class

Post by Maninthebox »

I am a contestant in the TJIP challenge, so I can't say too much about what I'm doing or show code :) But Zutty illustrates nicely the problem with having DTRS in neighbourcount: you'd like to have the DTRS in the neighbourcount if and only if the orientation allows you to drive through it from the tile you passed as a parameter to this function and not while approaching it from the side. This might just be my interpretation though as I'm not sure what the original intent was for this function.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 9 guests