RoadAI

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

11Runner
Engineer
Engineer
Posts: 92
Joined: 01 Sep 2011 19:23
Location: Oregon, USA

RoadAI

Post by 11Runner »

I would like to present my first AI, RoadAI.

This AI will build a rapidly expanding road network. It is currently in
early development so please tell me if you find any bugs so that I can
improve it. The AI works best in the temperate or subarctic regions.

This AI uses Superlib v13. Save and Load is currently unsupported.

You may need to extend your vehicle limit from 500 since the AI builds vehicles
very quickly!
Attachments
RoadAI-1.tar
RoadAI-1
(31 KiB) Downloaded 987 times
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: RoadAI

Post by Zuu »

Nice to see someone doing something different than the typical point to point connection concept.

I'm also happy to see that you've built ontop of the SuperLib library and thus has been able to do this much on just 696 lines of code. I do have to say however, that the code is a bit more compact than my taste of writing code. But it is your AI and your decision how you like to write your code. :-)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: RoadAI

Post by Zuu »

Hello again,

Your AI can sometimes build a huge amount of stations.
Unnamed, 11th Jul 1981.png
(190.07 KiB) Downloaded 2 times
RoadAI_test.sav
Used "Last nightly" => trunk version r22864
(213.81 KiB) Downloaded 511 times
(Edit: this game started in 1950, so some overcrowdyness is to be expected after 30 years of gameplay, but not to this extent)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Level Crossing
Tycoon
Tycoon
Posts: 1187
Joined: 07 Feb 2011 22:04
Location: East Coast, United States

Re: RoadAI

Post by Level Crossing »

Zuu wrote:Hello again,

Your AI can sometimes build a huge amount of stations.
Unnamed, 11th Jul 1981.png
RoadAI_test.sav
(Edit: this game started in 1950, so some overcrowdyness is to be expected after 30 years of gameplay, but not to this extent)
Didn't Paxlink have the same issue? I remember having a game with an old version of Paxlink where the entire city was plastered with bus stations.

How did you solve that?
Like my avatar? See my screenshot thread
11Runner
Engineer
Engineer
Posts: 92
Joined: 01 Sep 2011 19:23
Location: Oregon, USA

Re: RoadAI

Post by 11Runner »

Here is the next release for RoadAI. I only made a couple of fixes
Zuu wrote:Hello again,

Your AI can sometimes build a huge amount of stations.

(Edit: this game started in 1950, so some overcrowdyness is to be expected after 30 years of gameplay, but not to this extent)
I tried to address this issue by preventing the RoadAI from adding more than one network per town.

I also added another AI Setting which controls the maximum number of road networks the AI may make.

Thank you for all of your suggestions!
Attachments
RoadAI-2.tar
RoadAI Version 2
(31.5 KiB) Downloaded 436 times
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: RoadAI

Post by Brumi »

I gave your AI a try, here are my remarks:

I think the AI could have placed the bus station better here:
screenshot1.png
screenshot1.png (298.03 KiB) Viewed 1716 times
Road construction often fails for some reason, maybe the AI ran out of money while building the road and didn't increase its loan?
screenshot2.png
(150.3 KiB) Downloaded 2 times
In my test, the AI has only settled in three towns by the year 1964. I have town density set to low, and every seventh town is a city.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: RoadAI

Post by Zuu »

Brumi: Do you happen to have the save game with the town in screenshot 1?
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: RoadAI

Post by Brumi »

Sorry, I don't have it. SuperLib related issue?
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: RoadAI

Post by Zuu »

I would recommend using SuperLib.Road.BuildStopInTown(town, road_veh_type, accept_cargo = -1, produce_cargo = -1) over using Road.BuildBusStopNextToRoad as the later does not allow specifying cargo that the bus stop should accept. I think however, that future versions of the library should probably allow passing the accept_cargo and produce_cargo params to Build*NextToRoad as well as the higher-level functions that takes a town or industry rather than a tile as argument for where the road station should be placed.

I'm not sure exactly what the choose rule is if you have both accept_cargo == -1 and produce_cargo == -1 which is the case when you use Build*InTown. IIRC it is distance from center, but I dont exactly remember. (it could actually be preferring as far as way from center as possible as that is the behaviour for airports without cargo requirement specified)

It is also worth to mention that RoadAI use min_loops == 25, while CluelessPlus (Road.BuildStopInTown) have it at 50. This setting decide how many steps the algorithm will walk around in the town before settling with the best solution so far.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
11Runner
Engineer
Engineer
Posts: 92
Joined: 01 Sep 2011 19:23
Location: Oregon, USA

Re: RoadAI

Post by 11Runner »

Here is the next (and possibly final) release of RoadAI.
This is a picture of the improvement:
Capture.PNG
Breakdown of AI Improvement
Green is RoadAI v3
Yellow is RoadAI v2
(72.66 KiB) Downloaded 2 times
This is a very rough list of the new features:

1. Greatly improved speed (which actually changes much of the behavior of the AI in many areas :D )

2. Now can mass upgrade vehicles

3. More dynamic vehicle orders (as in vehicles may go to a larger variety of towns in the network)

3. Other various fixes (including a some recommended on this thread)

I am planning on creating a new AI with the majority of this AI's code simply because I feel limited by the name of the AI and I would like to add air, and possibly train support :wink: .
Attachments
RoadAI-3.tar
(34 KiB) Downloaded 329 times
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: RoadAI

Post by Lord Aro »

there's no problem with changing the name of the AI... i think... as long as you keep the shortname the same (?) (you might want someone to check that)
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: RoadAI

Post by FooBar »

Though you cannot change the name of a BaNaNaS entry.

If you consider this AI "done", I'd keep it as it is. Just get a new (short)name for your new AI. It's not that we're particularly short on shortnames.
11Runner
Engineer
Engineer
Posts: 92
Joined: 01 Sep 2011 19:23
Location: Oregon, USA

Re: RoadAI

Post by 11Runner »

OK I see what you mean. If it becomes and issue I hope there is an admin that I can talk to to help me change it. Keep in mind that this AI will still accept bug fixes if you find any bugs that may go into my new AI!
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: RoadAI

Post by Brumi »

I've tried the new version, a problem which I reported earlier still exists, the AI sometimes cannot finish road construction for some reason, probably it is out of money. It would be good if the AI took some loan in this case, or the AI could simply take the maximum loan while constructing a road, then pay it back after construction.
Attachments
roadai.png
(195.76 KiB) Downloaded 2 times
Hephi
Engineer
Engineer
Posts: 72
Joined: 25 Oct 2009 09:56
Location: Belgium

Re: RoadAI

Post by Hephi »

You could try putting something like this?

Code: Select all

if(!buildRoadCommand())
{ 
if(AIError.GetLastErrorString()=="ERR_NOT_ENOUGH_CASH")
{ 
AICompany.SetLoanAmount(AICompany.GetLoanAmount() + AICompany.GetLoanInterval());
buildRoadCommand()
}
}
--------------------------------------------------
MailAI, a casual postal service for openTTD.
--------------------------------------------------
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: RoadAI

Post by Kogut »

crash
Attachments
Selection_004.png
Selection_004.png (13.86 KiB) Viewed 10491 times
Selection_005.png
Selection_005.png (3.57 KiB) Viewed 10491 times
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
11Runner
Engineer
Engineer
Posts: 92
Joined: 01 Sep 2011 19:23
Location: Oregon, USA

Re: RoadAI

Post by 11Runner »

RoadAI-4
Kogut wrote:crash
* Should be resolved
* Updated to SuperLib v39
* Updated to GPL v3
Attachments
RoadAI-4.tar
(70 KiB) Downloaded 178 times
xarick
Transport Coordinator
Transport Coordinator
Posts: 336
Joined: 26 Feb 2015 00:52

Re: RoadAI

Post by xarick »

crash with wrong number of parameters
Attachments
Unnamed, 1968-03-29.png
(262.14 KiB) Not downloaded yet
Formerly known as Samu
xarick
Transport Coordinator
Transport Coordinator
Posts: 336
Joined: 26 Feb 2015 00:52

Re: RoadAI

Post by xarick »

Crash after loading savegame.
Attachments
Unnamed, 1974-03-26.sav
(4.65 MiB) Downloaded 169 times
Unnamed, 1974-05-04.png
(293.37 KiB) Not downloaded yet
Formerly known as Samu
11Runner
Engineer
Engineer
Posts: 92
Joined: 01 Sep 2011 19:23
Location: Oregon, USA

Re: RoadAI

Post by 11Runner »

xarick wrote:crash with wrong number of parameters
yea that crash was pretty stupid, and old!

Here is the fixed version, for both of the issues you sent, xarick
Attachments
RoadAI-5.tar
(70 KiB) Downloaded 176 times
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 8 guests