Couple Questions

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

Couple Questions

Post by reylas »

Couple of quick questions.

We have the ability to create an AIStationList, but what about AIDepotList? I looked for a STATION_TYPE for AIStationList for RoadDepot, but could not find one. I have a homebrew function to find my depots, but I am sure it is not as efficient.

Also, not totally AI related, but is there a way to get the magic number(game seed) inside a game. I keep forgetting to write it down, and then I find a unique situation that gives my AI trouble, but I want to restart the current game with all AI building gone. That way I can check the situation again to see if code changes help. Is there a way to get the seed after the game starts?

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

Re: Couple Questions

Post by Rubidium »

Use the getseed console command.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Couple Questions

Post by Yexo »

There is no efficient way to check for depots except just scanning tiles. A DepotList won't be created therefor (as it'd need to scan the whole map).

To get the seed, open the console and type 'getseed'. You can also restart the current map by opening the console and typing 'restart'. Both without the quotes of course.
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: Couple Questions

Post by TrueBrain »

Well, we can make AIDepotList, not a real problem. Only problem are hangars, and that is fixable.

What I only wonder is, how useful is this? Knowing where depots are doesn't tell you much ... not even if they connect to your route or what ever. I personally for my AIs keep track of when I build a depot, and on which route that is. This way I can always find the depot back, when I need to add new vehicles and stuff. Much easier in my opinion :)
The only thing necessary for the triumph of evil is for good men to do nothing.
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: Couple Questions

Post by Rubidium »

But then one would need to store the complete state to the map when saving the game (i.e. in the case of saveload) and I do not think it is wise to completely store the binary representation of the VM as that might very easily hinder savegame compatability in the future.
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: Couple Questions

Post by TrueBrain »

Shall we not go into saveload issues now? And for sure not in this topic? Seems a bit .. not-related.

AIDepotList should be added if there is a user-request (like this topic), as it is equal to AIVehicleList and AIStationList, so that is fine.

The point only one might wonder, why a user would want the function (at this stage of the NoAI Framework). If you want to clone a vehicle, it would be rather expensive to find a depot that connects to your route. If you want to create a new route, the same is true. So one might wonder for what the topic started wants to use it. This purely out of interest in how people use functions of the framework.
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: Couple Questions

Post by reylas »

Ok, cool. I did not know about restart and getseed. Good things to know. Thanks.

As for the DepotList command, it may be that I am doing things wrong (forgive me, as I do not do much programming in real life) but this was my thought process for my AI.

I take and pick a city then build an intra-city bus route. So I have say 2 bus stations and a road depot. Then I go looking for the nearest 'big enough' town and build an intra-city bus route. Same function serves both. So I feed it a city, it builds bus routes with a road depot. Then I decide to connect the citys. So my pathfinder finds a legal path between, builds the road. So now I need to find a road depot that I know I have alread built. I know the two bus stations that I want to connect because I build an AIStationList, and Valute the distance to the townA and townB I want to connect. This gives me the closest stations to my to town centers (and population). Now I need to find a road depot that is in one of these two towns. After that, my AI scans the cities that I have connected already, then finds the next best city to either town and keeps growing.

Without keeping a persistant list, I was trying (may be stupid on my part) to keep from storing all that information. All I keep persistant is that I have a list of towns I have connected. Since I was using AIStationLists to find my two stations to connect, I figured I could use an AIDepotList and valuate on distance to the towns I am connecting to find a close depot to the one of the towns to build buses.

For some reason, that is becoming less clear as I type this :), I did not want to store any information. I am building each function to work independently. My AI constantly scans AIStationList, AIIndustryList and what not to find useful information. It just felt right to me that I could have an AIDepotList as well instead of keeping it myself.

If it is decided that it is not needed, then I will keep my own list as well. I just thought it was already there since AIStationList was there, and I was missing it. You guys know well more on what is useful than I do. It is funny, anytime I think of a function that I could use, it is there. GetComplementSlope was like a gift at christmas when I noticed it was already there :)

Also, I understand that the way I am going about building a company may not be the most efficient, but I am going for something different. I know that most would not build out the way I am, but I am having fun learning and tweaking. Again, I am not a programmer by trade. I just felt that companies usually start locally and grow out to nationally, then globally. I am trying to replicate that instead of building all over the map.
Finaldeath
Engineer
Engineer
Posts: 72
Joined: 09 Apr 2006 23:49
Location: UK
Contact:

Re: Couple Questions

Post by Finaldeath »

Keeping your own internal list is a good idea. A depot could be used by multiple routes, which is fair enough. But without storing it all, you'd only have disjoint information - there is a depot, but who knows what it is related to?

And the assumption a depot will be in a city won't necessarily always be true, if you expand your AI to work differently :)

Not that a depot list (of your depots) wouldn't be terribly bad, just not too useful if you persistently store the ones you build.
Finaldeath
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: Couple Questions

Post by TrueBrain »

reylas wrote:Ok, cool. I did not know about restart and getseed. Good things to know. Thanks.

As for the DepotList command, it may be that I am doing things wrong (forgive me, as I do not do much programming in real life) but this was my thought process for my AI.

I take and pick a city then build an intra-city bus route. So I have say 2 bus stations and a road depot. Then I go looking for the nearest 'big enough' town and build an intra-city bus route. Same function serves both. So I feed it a city, it builds bus routes with a road depot. Then I decide to connect the citys. So my pathfinder finds a legal path between, builds the road. So now I need to find a road depot that I know I have alread built. I know the two bus stations that I want to connect because I build an AIStationList, and Valute the distance to the townA and townB I want to connect. This gives me the closest stations to my to town centers (and population). Now I need to find a road depot that is in one of these two towns. After that, my AI scans the cities that I have connected already, then finds the next best city to either town and keeps growing.

Without keeping a persistant list, I was trying (may be stupid on my part) to keep from storing all that information. All I keep persistant is that I have a list of towns I have connected. Since I was using AIStationLists to find my two stations to connect, I figured I could use an AIDepotList and valuate on distance to the towns I am connecting to find a close depot to the one of the towns to build buses.

For some reason, that is becoming less clear as I type this :), I did not want to store any information. I am building each function to work independently. My AI constantly scans AIStationList, AIIndustryList and what not to find useful information. It just felt right to me that I could have an AIDepotList as well instead of keeping it myself.

If it is decided that it is not needed, then I will keep my own list as well. I just thought it was already there since AIStationList was there, and I was missing it. You guys know well more on what is useful than I do. It is funny, anytime I think of a function that I could use, it is there. GetComplementSlope was like a gift at christmas when I noticed it was already there :)

Also, I understand that the way I am going about building a company may not be the most efficient, but I am going for something different. I know that most would not build out the way I am, but I am having fun learning and tweaking. Again, I am not a programmer by trade. I just felt that companies usually start locally and grow out to nationally, then globally. I am trying to replicate that instead of building all over the map.
I like people like you :) A clear and perfectly sound explanation :) As I said before, AIDepotList should be added, and will be added soon I guess. I was just really wondering why you would need it :) Just one word of advice, which comes more out of experience than any knowledge: either check very good if your depot really connects to your road-network, or just build a new one ;) It would be nasty if a human could just remove a piece of road and your depot gets disconnected :) And towns tend to disconnect my depot more often than I would like when I build a depot close to a town ... grr ;)
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: Couple Questions

Post by reylas »

TrueLight wrote: I like people like you :) A clear and perfectly sound explanation :) As I said before, AIDepotList should be added, and will be added soon I guess. I was just really wondering why you would need it :) Just one word of advice, which comes more out of experience than any knowledge: either check very good if your depot really connects to your road-network, or just build a new one ;) It would be nasty if a human could just remove a piece of road and your depot gets disconnected :) And towns tend to disconnect my depot more often than I would like when I build a depot close to a town ... grr ;)
One of the first functions I wrote was a town walker. I run it every so often to give me a list of all road tiles in a city. *If* my road walker places a tile in an AIList, then I know that it is connected. I check every tile that I try to build on to see if it is in the town walker list. If it is, then I know my bus can get there. Run that every year or two to check connectivity then I am done.

Thanks for the kind words. I am one of those people who understand algorithms and what you need to do, but never do my self. This time, I am seeing if I am capable of writing an AI that can make some money. So far so good.

Maybe we should start an "Ethics in AI" thread. I have already *uncovered* with my functions ways of sabotaging enemy AI's. :)

Thanks,
MarkS
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Couple Questions

Post by Yexo »

reylas wrote:Maybe we should start an "Ethics in AI" thread. I have already *uncovered* with my functions ways of sabotaging enemy AI's. :)
I would like to see your AI make use of it in the tournament. Of course that's not the way to go, but testing how well all AIs cope with some sabotage would be fun.
reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: Couple Questions

Post by reylas »

Yexo wrote:
reylas wrote:Maybe we should start an "Ethics in AI" thread. I have already *uncovered* with my functions ways of sabotaging enemy AI's. :)
I would like to see your AI make use of it in the tournament. Of course that's not the way to go, but testing how well all AIs cope with some sabotage would be fun.
Right now, I have an AI that builds a decent road network with busstations. I am just cleaning up code, finding exceptions to my planning, handling mistakes. I hope to build something to compete this week, If I can get it clean enough and decent enough that the developers dont go into laughing fits when they see the code (Man is it ugly). I promise you, I doubt I am doing anything textbook. They will scratch their heads when they see the 'thinking' process my AI does. Plus, I bet it will not score one victory :)

Then, I could add a few tricks to try and make some money, but mess with other AI's in the process. So I may devolve into that :)
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Couple Questions

Post by Yexo »

reylas wrote:Right now, I have an AI that builds a decent road network with busstations. I am just cleaning up code, finding exceptions to my planning, handling mistakes. I hope to build something to compete this week, If I can get it clean enough and decent enough that the developers dont go into laughing fits when they see the code (Man is it ugly). I promise you, I doubt I am doing anything textbook. They will scratch their heads when they see the 'thinking' process my AI does. Plus, I bet it will not score one victory :)
Why not release it when you think it works? Nobody will laugh at you because your code is unclean, as long as it builds some decent lines. The only one who'll care about ugly code is yourself, when you need to find bugs :)
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: Couple Questions

Post by Rubidium »

reylas wrote:Plus, I bet it will not score one victory
I'd say not going bankrupt in the tournament against other AIs is quite a victory; it all depends how you look at it.
reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: Couple Questions

Post by reylas »

I just saw where AIDepotList was just committed. Wow, that was quick. Thanks a bunch.

MarkS.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 16 guests