Pathfinder issue with AITileList

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
reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Pathfinder issue with AITileList

Post by reylas » 21 Jun 2008 14:05

Quick question. In the original NoAI thread there was a discussion about a pathfinder not building roads in a North-West, West-North direction. I now have the same issue, so I went back to that discussion. All I could find was this:

"D0h, foolish me. I used a AITileList instead of a normal AI to store the tiles... It works as it should now "

Can I ask why that would make a difference. I don't understand. I would have thought and AITileList would be the same as a AIList without a value field (or a value of 0).

Thanks,
MarkS.

Yexo
Tycoon
Tycoon
Posts: 3653
Joined: 20 Dec 2007 12:49

Re: Pathfinder issue with AITileList

Post by Yexo » 21 Jun 2008 14:09

I don't remember that discussion and I'm not going to search through that whole thread. Can you please provide a picture of the problem you are facing and/or a link to the original discussion?

reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: Pathfinder issue with AITileList

Post by reylas » 21 Jun 2008 14:30

Yexo wrote:I don't remember that discussion and I'm not going to search through that whole thread. Can you please provide a picture of the problem you are facing and/or a link to the original discussion?
Well, the reason I you should not look through the entire thread is that was the only thing said. But he had the same problem I did. Turns out, my problem is that my road builder is not building turns at all. I am building the path with signs, and the path looks good, but turns are not being constructed. I have tried BuildRoad and BuildRoadFull neither which helps. I will post a picture in the next post.

MarkS

Yexo
Tycoon
Tycoon
Posts: 3653
Joined: 20 Dec 2007 12:49

Re: Pathfinder issue with AITileList

Post by Yexo » 21 Jun 2008 14:32

Are you using your own pathfinder or the library one? If you use the pathfinder from the library, sample code on using it can be found here: http://wiki.openttd.org/index.php/AI:Pathfinder

reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: Pathfinder issue with AITileList

Post by reylas » 21 Jun 2008 14:36

This screenshot kinda shows what I am talking about.
Notice that turns are what messes it up. But the list of tiles to build are the P signs. So a somewhat valid path is found, but the road does not get built on turn tiles. Just some advice, is there something I should be watching for when building between tiles that change direction.

My algorithm does this. Start with the first tile A, build to the next tile B. Make A = B, grab next B then build, then repeat.

Thanks,
MarkS
Attachments
Unnamed, 19th Jan 1931.png
(653.04 KiB) Downloaded 54 times

reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: Pathfinder issue with AITileList

Post by reylas » 21 Jun 2008 14:37

Yexo wrote:Are you using your own pathfinder or the library one? If you use the pathfinder from the library, sample code on using it can be found here: http://wiki.openttd.org/index.php/AI:Pathfinder
I am using my own. I just wanted to climb that mountain because it was there. No offense to the library pathfinder, I just wanted to challenge myself to accomplish something that I never thought I could do. So far, it is winning, but I am still swinging :)

MarkS

Yexo
Tycoon
Tycoon
Posts: 3653
Joined: 20 Dec 2007 12:49

Re: Pathfinder issue with AITileList

Post by Yexo » 21 Jun 2008 14:40

Without code I can't say exactly what you do wrong, but I assume it is the following:
1) You call your pathfinder, it returns a path A-B-C-D-E-F-G (where A-G are tiles)
2) You try to build the road: you build A-B, C-D, E-F etc.
While step 1 is correct, step 2 is wrong. You should build A-B, B-C, C-D etc.

Is there some optimalization in your build code to build straight pieces of track in one go? I think the bug is located there.

Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: Pathfinder issue with AITileList

Post by Rubidium » 21 Jun 2008 14:41

The only difference between AIList and AITileList is that AITileList can't store negative invalid tiles (i.e. negative values). If using AIList instead of AITileList solves the problem then it lies somewhere in that or unsigned integers not being converted to signed integers.

reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: Pathfinder issue with AITileList

Post by reylas » 21 Jun 2008 14:59

Rubidium wrote:The only difference between AIList and AITileList is that AITileList can't store negative invalid tiles (i.e. negative values). If using AIList instead of AITileList solves the problem then it lies somewhere in that or unsigned integers not being converted to signed integers.

ok, thanks, that sounds like what I thought. He must of had a different problem than me.

Thanks,
MarkS.

reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: Pathfinder issue with AITileList

Post by reylas » 21 Jun 2008 15:03

Yexo wrote:Without code I can't say exactly what you do wrong, but I assume it is the following:
1) You call your pathfinder, it returns a path A-B-C-D-E-F-G (where A-G are tiles)
2) You try to build the road: you build A-B, C-D, E-F etc.
While step 1 is correct, step 2 is wrong. You should build A-B, B-C, C-D etc.

Is there some optimalization in your build code to build straight pieces of track in one go? I think the bug is located there.
No, I am just in the initial stages, so there is no optimization. I am doing one thing squirrly though and that is I am walking the parent node list and building a TileList from the walk. The signs are being built while I am building the TileList. Once I have built it, the pathfinder returns the list of tiles to build a road on. My concern was that I know the tiles are in there, just for some reason if there is a change of direction, the road does not build.

I will add some debugging code to try and spot it. I was just wondering if there was any special thing I was missing when building a turn in the road. I go from A-B then B-C, then C-D and what not. Seems when there is a change of direction I fail.

Thanks,
MarkS.

TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1312
Joined: 31 May 2004 09:21

Re: Pathfinder issue with AITileList

Post by TrueBrain » 21 Jun 2008 15:37

If I can guess, I would guess the problem is that AITileList (and any other list) automatically sorts. In pathfinding, this mostly is not something you want. So either you need to use AIList where the 'item' value is a number from 0 to N, and the 'value' is the tile, or better yet would be to use the Squirrel array stuff (which doesn't automatically sort). But of course, without any code, this is just a blind guess.
The only thing necessary for the triumph of evil is for good men to do nothing.

reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: Pathfinder issue with AITileList

Post by reylas » 22 Jun 2008 13:54

TrueLight wrote:If I can guess, I would guess the problem is that AITileList (and any other list) automatically sorts. In pathfinding, this mostly is not something you want. So either you need to use AIList where the 'item' value is a number from 0 to N, and the 'value' is the tile, or better yet would be to use the Squirrel array stuff (which doesn't automatically sort). But of course, without any code, this is just a blind guess.
Actually, I believe the sorting is what was getting me. I had an AIList with a Tile and it's parent. That List does not matter from a sorting standpoint since I have to walk that list from tile to its parent to its parent and so on. No matter how it sorted, the path was the same. What I was doing was walking that LIST and creating another LIST that was the path. That path is getting sorted and being hosed.

Funny thing is, I added a counter as the item number, that still sorted funny. So I changed to have the tile as the item, the counter as the value, but is still sorted out of order. So I just started building the road while walking the path instead of transfering to another list. Works fine. I know I will run into the sort issue again though. Must spend some time to figure that one out.

Thanks for everyone's help. Now I am building ugly roads, but they work!

MarkS

Yexo
Tycoon
Tycoon
Posts: 3653
Joined: 20 Dec 2007 12:49

Re: Pathfinder issue with AITileList

Post by Yexo » 22 Jun 2008 14:43

You don't need to use an AIList for that kind of thing. AIList is great if you want to use valuators / sorting, but for most other things, you can just use a squirrel array.
Example code:

Code: Select all

local myarray = [];
myarray.push(5);
myarray.push(3);
for (local i = 0; i < myarray.len(); i++) {
  AILog.Info(i + ": " + myarray[i]);
}
Untested code, so it may contain a typo, but code like this works.

TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1312
Joined: 31 May 2004 09:21

Re: Pathfinder issue with AITileList

Post by TrueBrain » 22 Jun 2008 16:28

Also, AIList by default sorts on the value. Use the Sort function to change it to sort based on the item. Here you can also control descending/ascending.
The only thing necessary for the triumph of evil is for good men to do nothing.

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 7 guests