Pathfinder issue with AITileList
Moderator: OpenTTD Developers
Pathfinder issue with AITileList
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.
"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.
Re: Pathfinder issue with AITileList
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?
Re: Pathfinder issue with AITileList
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.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?
MarkS
Re: Pathfinder issue with AITileList
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
Re: Pathfinder issue with AITileList
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
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
Re: Pathfinder issue with AITileList
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 swingingYexo 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
MarkS
Re: Pathfinder issue with AITileList
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.
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.
Re: Pathfinder issue with AITileList
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.
Re: Pathfinder issue with AITileList
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.
Re: Pathfinder issue with AITileList
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.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.
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.
Re: Pathfinder issue with AITileList
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.
Re: Pathfinder issue with AITileList
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.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.
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
Re: Pathfinder issue with AITileList
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:
Untested code, so it may contain a typo, but code like this works.
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]);
}
Re: Pathfinder issue with AITileList
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.
Who is online
Users browsing this forum: No registered users and 11 guests