TownCars AI

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

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

TownCars AI

Post by Zuu » 16 Mar 2009 21:04

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 31160 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 31157 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.
Attachments
TownCars-5.tar
(18 KiB) Downloaded 1529 times
Last edited by Zuu on 25 Mar 2011 23:00, edited 1 time in total.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9292
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: TownCars AI

Post by planetmaker » 16 Mar 2009 22:22

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?

User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 313
Joined: 13 Jul 2008 00:57
Contact:

Re: TownCars AI

Post by Michiel » 16 Mar 2009 23:03

Now that's a fun idea :)

Hypolite
Engineer
Engineer
Posts: 126
Joined: 10 Jan 2009 07:20
Location: Paris, france

Re: TownCars AI

Post by Hypolite » 17 Mar 2009 08:57

I totally agree with this AI. :D

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

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: TownCars AI

Post by Zuu » 17 Mar 2009 09:51

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.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

User avatar
Benny
Tycoon
Tycoon
Posts: 2185
Joined: 25 Aug 2007 17:03
Location: ~/

Re: TownCars AI

Post by Benny » 17 Mar 2009 10:10

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. :)
Image

User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5391
Joined: 13 Sep 2004 13:21
Location: The Moon
Contact:

Re: TownCars AI

Post by PikkaBird » 17 Mar 2009 12:50

Nice. :)

What about intercity traffic? :P

Morloth
Transport Coordinator
Transport Coordinator
Posts: 378
Joined: 07 Feb 2008 14:06
Location: Glasgow

Re: TownCars AI

Post by Morloth » 19 Mar 2009 15:56

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.

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: TownCars AI

Post by Zuu » 19 Mar 2009 18:16

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.
Attachments
TownCars-v3.tar
(24.5 KiB) Downloaded 520 times
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9292
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: TownCars AI

Post by planetmaker » 21 Mar 2009 09:33

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 30262 times
big_town.png
big_town.png (73.02 KiB) Viewed 30273 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).

zombie
Traffic Manager
Traffic Manager
Posts: 153
Joined: 19 May 2005 22:19
Location: Germany

Re: TownCars AI

Post by zombie » 21 Mar 2009 11:54

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
OpenTTD: OpenTTD-Wiki
OpenTTDCoop: Blog, Wiki
My favorite patches: cargo destinations, shared infrastructure

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: TownCars AI

Post by Zuu » 21 Mar 2009 19:52

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.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

User avatar
fjuedes
Engineer
Engineer
Posts: 5
Joined: 06 Apr 2009 17:55
Skype: frank.juedes
Location: Houston, TX

Re: TownCars AI

Post by fjuedes » 08 Apr 2009 01:18

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.
Attachments
StreetTraffic.1.tar
(30 KiB) Downloaded 414 times
In a world without walls and fences, who needs windows and gates?

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: TownCars AI

Post by Zuu » 08 Apr 2009 05:56

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)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

User avatar
fjuedes
Engineer
Engineer
Posts: 5
Joined: 06 Apr 2009 17:55
Skype: frank.juedes
Location: Houston, TX

Re: TownCars AI

Post by fjuedes » 08 Apr 2009 07:28

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)
In a world without walls and fences, who needs windows and gates?

User avatar
indio
Traffic Manager
Traffic Manager
Posts: 168
Joined: 11 Jul 2008 14:46
Location: Cremona, Italy

Re: TownCars AI

Post by indio » 14 Apr 2009 14:46

that's a great idea!!! thanx lot :bow:
but, how i can instal it?

Code: Select all

(>____<)
Image Image
----------------------------------------------------------------------------
i had got a cake >_<
Image

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: TownCars AI

Post by Zuu » 14 Apr 2009 19:10

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)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

ruivilela
Engineer
Engineer
Posts: 16
Joined: 24 Jan 2007 10:22

Re: TownCars AI

Post by ruivilela » 26 Apr 2009 17:16

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:

User avatar
SupSuper
Engineer
Engineer
Posts: 26
Joined: 13 Apr 2003 19:18
Location: Portugal
Contact:

Re: TownCars AI

Post by SupSuper » 10 Jul 2009 17:48

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:
Attachments
PRV Transport, 16th May 1958#1.png
(217.77 KiB) Downloaded 120 times
PRV Transport, 16th May 1958#2.png
(215.17 KiB) Downloaded 93 times
Water train!

User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: TownCars AI

Post by fanioz » 12 Jul 2009 04:53

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
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest