Page 1 of 4

TownCars AI

Posted: 16 Mar 2009 21:04
by Zuu
Hello,

Let me present TownCars, which is an AI that builds road vehicles that drive around randomly in towns.
TownCars_Screenshot.png
TownCars_Screenshot.png (96.25 KiB) Viewed 44055 times
In the AI settings there are a few options for defining which road vehicles it should built. The default settings are compatible with the Generic Cars GRF.
TownCars_Settings.png
TownCars_Settings.png (7.79 KiB) Viewed 44052 times
I have not tested with any other car GRFs, but for the AI to be able to distinguish them from buses, they need to either have free price, free running cost or zero capacity. And you need to in the AI settings specify which property that is zero in your GRF. It is also possible to make it only build road vehicles that carry passengers.

If you want this AI to stay alive for long time, you will have to use the cheat dialog to change player to the AI and give it some money for it to keep alive. Depends on the GRF of course, what costs it has to pay per year for the road vehicles.

From version 5 of this AI, it should no longer be selected as a random AI by OpenTTD, so in order to use it one must explicitly select it in the AI Settings. I believe this is the behaviour that most users want.

Dependencies
TownCars 5 requires SuperLib version 6 in order to function. If you download the AI via the in-game content downloader you will get this library automatically.

Re: TownCars AI

Posted: 16 Mar 2009 22:22
by planetmaker
Wow, nice to see this actually implemented :)

Zuu, what about the idea, to give the AI a simple money maker (maybe also via an option), e.g to build one long-distance air route with a few planes (maybe 10) in order to make money and pay for the cars?

Re: TownCars AI

Posted: 16 Mar 2009 23:03
by Michiel
Now that's a fun idea :)

Re: TownCars AI

Posted: 17 Mar 2009 08:57
by Hypolite
I totally agree with this AI. :D

Does he take city size into account ? I mean, dos he build more cars for bigger towns ?

Re: TownCars AI

Posted: 17 Mar 2009 09:51
by Zuu
Hypolite wrote:I totally agree with this AI. :D

Does he take city size into account ? I mean, dos he build more cars for bigger towns ?
No, it doesn't. But it starts building in the biggest town. So that the biggest towns get populated with cars first.

planetmaker wrote:Zuu, what about the idea, to give the AI a simple money maker (maybe also via an option), e.g to build one long-distance air route with a few planes (maybe 10) in order to make money and pay for the cars?
That was an idea I had, but didn't implement it right now.

Re: TownCars AI

Posted: 17 Mar 2009 10:10
by Benny
Maybe you could make it place 2-3 bus stops randomly in the city? It would make it some money, but the cities would start to grow..

I'll test the AI when I get home. :)

Re: TownCars AI

Posted: 17 Mar 2009 12:50
by PikkaBird
Nice. :)

What about intercity traffic? :P

Re: TownCars AI

Posted: 19 Mar 2009 15:56
by Morloth
Way to go Zuu, I like the out of the box thinking you're applying here and in PAX. Mad props to you! :D
PikkaBird wrote:Nice. :)

What about intercity traffic? :P
I think that is pretty much handled by not giving cars order they will simply drive around taking any road available. So if an other company builds a road which links cities I think it will go there as well.

Re: TownCars AI

Posted: 19 Mar 2009 18:16
by Zuu
Morloth wrote:Way to go Zuu, I like the out of the box thinking you're applying here and in PAX. Mad props to you! :D
Not originally my idea with town cars, as this has been suggested for ages. But I was the first one to implement it. Or rather copy and paste parts of PAXLink and then link it together with a new main-loop. Fix bugs, add settings and fine tune. :) But thanks for your warm words anyways. :)


On bananas there is an update, that fixes the bug I mentioned in the PAXLink thread with depots/stations built wrongly next to sloping road with wrong slope direction. This was due to a return of an API function was treated as a boolean where it really was an integer with four possible values.

I couldn't resist to try 15 TownCars AIs, and found another issue, that if the AI failed to build the road bit it did still built the depot, resulting in an unconnected depot (for AIs you need do build the road before, as it is not built automatically as for players). Now it keeps trying as long as the error is "vehicle in the way". Same for building the depot, it will keep trying as long as the error is "vehicle in the way". However when removing the road stump after the depot is removed has always been retrying until it succeeds.

Oh, and naming has been changed so it now names the company #2, #3, .. when the name TownCars fails.

Re: TownCars AI

Posted: 21 Mar 2009 09:33
by planetmaker
Zuu wrote:
Hypolite wrote: Does he take city size into account ? I mean, dos he build more cars for bigger towns ?
No, it doesn't. But it starts building in the biggest town. So that the biggest towns get populated with cars first.
I like that proposal, though (possibly in addition to a max number of cars per town):
small_town.png
small_town.png (17.94 KiB) Viewed 43157 times
big_town.png
big_town.png (73.02 KiB) Viewed 43168 times
Clearly one would expect more traffic in the bigger town - maybe a factor as a setting with something like population / 100 as default and a max vehicle limit of 25 / town?

In any case it's great for the looks :) I asked Zephyris to upload his cars to bananas - so maybe it will then be even easier to get this running in a nice way. Might then be an idea to define that grf as a requirement for the AI :) - though of course it doesn't guarantee that it'll be activated in the newgrf settings then.

EDIT: Another thing which just popped my mind: it might be a bad idea to remove the depots, if vehicle_breakdowns = 1 - e.g. the cars will start to break down constantly, if they have not even a chance of being serviced once in a while. So... maybe leave the depot per town and send the cars for servicing every once in a while (if breakdowns are on only).

Re: TownCars AI

Posted: 21 Mar 2009 11:54
by zombie
Hi.

This AI is a really great idea. The towns look so much better with cars in them. But I would select the towns randomly and not by size. With some AIs (got a game with five of them running) the large towns are really crowded while the rest of the map is "dead".

In my game all AIs went bankrupt after about four years. That's why I thought about a money maker for the AI companies. A money maker could keep the company in business. That leads to my next question: Does the AI upgrade its vehicles to newer models? The AI removes the depot right after all cars hit the road. This way the old cars of the company will stay on the roads forever if the company makes profit. In this case there should be some vehicle upgrade logic.

Kind regards

Zombie

Re: TownCars AI

Posted: 21 Mar 2009 19:52
by Zuu
Thanks for your feedback.

Let me say like this, adding a airline between the two biggest towns might seam simple, but it requires quite some code additions. Upgrading/managing vehicles also requires quite some additional coding. Further improvements to this AI other than bug fixing is quite low on my list. Number of cars based on town size could happen as that is quite simple.


If anyone feel like doing improvements to this AI it is GPL 2, so just go ahead. You might want to fork it and use another name like TownCarsAdvanced so you can make a new entry on bananas for it.


For single player you can just open the cheat window and give it lot of money, and it will not bankrupt. For MP, yes then there can be a reason to have a MM. Or you can make a GRF that has free cars with zero running cost. Then the only cost will be to build the depots, and pay the annual company fee as well as the loan fee.

Re: TownCars AI

Posted: 08 Apr 2009 01:18
by fjuedes
Hi Zuu,

thank's for that inspiration! - I have taken your TownCars.3 and created StreetTraffic.1 from it.
Some of the suggested enhancements from here are implemented:

- The cars will be distributed more naturally, depending on the population of the town
- The cars will be distributed over a longer time, not all cars at once
- Only one depot will be built per city and those depots will not be destroyed, so that
- cars will be maintained
- cars will be re-newed
- If cars are being destroyed by crashes later, they will be replaced
- load/save is implemented
- more configurable options

I am planning to implement a simple money maker, depending on the configuration the StreetTraffic companies are running out of money within 5-10 years.
Any other suggestions welcome!

StreetTraffic is available from here (attachment) or on BaNaNaS.

Best regards from Texas, Frank/2
Zuu wrote:Thanks for your feedback.

Let me say like this, adding a airline between the two biggest towns might seam simple, but it requires quite some code additions. Upgrading/managing vehicles also requires quite some additional coding. Further improvements to this AI other than bug fixing is quite low on my list. Number of cars based on town size could happen as that is quite simple.


If anyone feel like doing improvements to this AI it is GPL 2, so just go ahead. You might want to fork it and use another name like TownCarsAdvanced so you can make a new entry on bananas for it.


For single player you can just open the cheat window and give it lot of money, and it will not bankrupt. For MP, yes then there can be a reason to have a MM. Or you can make a GRF that has free cars with zero running cost. Then the only cost will be to build the depots, and pay the annual company fee as well as the loan fee.

Re: TownCars AI

Posted: 08 Apr 2009 05:56
by Zuu
I have not had time to test it, but it looks like you have done a decent work there!

You say you have implemented save/load, then I suggest you add the tag 'save/load' to BaNaNaS, so users know that you have done that. Even TownCars was marked with 'save/load', but with a note that it was only limited save/load support. (Ie don't go crazy and rebuild everything when the game is load again)

Re: TownCars AI

Posted: 08 Apr 2009 07:28
by fjuedes
Hi Zuu,

the AI works a different now. See the settings here:
Image
In the first phase the AI will select the 15 most populated towns from the game and will build a depot there. The relation between town_id and depot_tile will be stored into an AIList.

Then comes phase two, see the AI-Log here:
Image
The program enters an endless loop in which the list of towns, selected in phase one is processed and
[current population]/100 * [number of cars per 100 inhabitants per town]
are built in each town. After each car a configurable amount of time is slept, as well as after processing of each town and at the end of the loop.
Because this loop runs until the company runs out of money, crashed cars will be replaced in later phases of the game and if there are newer vehicle types available, the existing cars will be replaced with newe ones.

I save the list of town_ids and depot_tiles together with the game, because i don't know (yet!) how to recreate it after a game is loaded - and i wanted to test the load/save functions of the AI framework. :wink:

Here's an example of how it looks like (sorry for the german...)
Image
The depot in the center is the one owned by the AI.

Best regards from Texas, Frank/2

P.S. Currently i am using this AI to learn the API, maybe later this will end up in a new playing AI.
P.P.S Do you have a brief description of how i could build some random (bus-)stops in the towns to produce some money?
Zuu wrote:I have not had time to test it, but it looks like you have done a decent work there!

You say you have implemented save/load, then I suggest you add the tag 'save/load' to BaNaNaS, so users know that you have done that. Even TownCars was marked with 'save/load', but with a note that it was only limited save/load support. (Ie don't go crazy and rebuild everything when the game is load again)

Re: TownCars AI

Posted: 14 Apr 2009 14:46
by indio
that's a great idea!!! thanx lot :bow:
but, how i can instal it?

Re: TownCars AI

Posted: 14 Apr 2009 19:10
by Zuu
Use 0.7.0 or recent nightly.

* Click on the content download button in the menu.
* Select either TownCars or StreetTraffic from the list of downloads, by checking the download check box.
* Select GenericCars or other GRF containing city cars
* Click on download
* Close content download window

* Open NewGRF settings
* Add GenericCars to GRF list
* Close NewGRF settings

* Open AISettings
* Add TownCars/StreetTraffic to one of the slots (you need to set >= 1 AI players first)
* If you use GenericCars then TownCars and probably StreetTraffic default settings find the city cars. If you use another grf you need to fiddle with the settings (see my explanation in some of my posts above)
* Close AISettings

* Start a new game
* Wait until the AI starts. (by default 365 days +- some time)

Re: TownCars AI

Posted: 26 Apr 2009 17:16
by ruivilela
This looks quit nice! StreetTraffic looks more promissing than townCars for now (nightly builds)

At least I tested both and sometimes townCars seems sometimes to refuse to create cars. StreetTraffic is not in the Download content. Maybe ships (sails if there was such grf) going around map would be nice also :)

I notice that StreetTraffic build depots in other cities but it start to creates cars in only one depot.

Usually I flow the cars by creating inter-city roads, but for sure you already know that.

How to send money to other company without cheating? (I see the option but i don't know how to use it). My transport company financing road traffic :mrgreen:

Re: TownCars AI

Posted: 10 Jul 2009 17:48
by SupSuper
A friend of mine tried out your AI on an old savegame with old AIs, using OpenTTD 0.7.1, and got some funky problems, I'm guessing the AI isn't designed to take over other AIs.
Still if it helps, here are some screenshots of the AI Debug messages:

Re: TownCars AI

Posted: 12 Jul 2009 04:53
by fanioz
SupSuper wrote:A friend of mine tried out your AI on an old savegame with old AIs, using OpenTTD 0.7.1, and got some funky problems, I'm guessing the AI isn't designed to take over other AIs.
Still if it helps, here are some screenshots of the AI Debug messages:
Have you tried that with the Nightly build? I think that OpenTTD would only load the same AI name.
Edit :: And of course StreetTrafic is not TownCars :D