SnakeAI

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
mousetail
Engineer
Engineer
Posts: 14
Joined: 22 Mar 2014 08:45

SnakeAI

Post by mousetail » 01 Feb 2018 20:19

Some of you may remember my previous attempt at an AI, CPU. Creating if was a fun experience, but the result was super buggy and didn't generate much profit, and generally did a lot of stupid stuff. Since then, I have learned a lot about programming in general, and decided to give it another try. Thus, I present to you snakeAI.
Image
Some features:
  • 150,000 revenue in 3 years, 200,000 in 4, profit after 9 years
  • Works with most non-insane new-grf's (tested with several vehicle and industry sets)
  • Road vehicle only for now, usually reaches the limit after a couple of years
  • Only builds short-distance routes
  • Dynamically increases vehicle count when vehicles can't handle the supply
  • Vehicles get interesting names
There are probably still plenty of bugs, and I have a few features I still think I may be able to finish before my holiday ends. Please send me all your crashes, bugs, and general strange behavior. There might be some I can fix.
Attachments
screenshot.png
(2.39 MiB) Not downloaded yet
SnakeAI.tar
(81 KiB) Downloaded 136 times
my AI: CPU, SnakeAI

Wormnest
Engineer
Engineer
Posts: 95
Joined: 14 Jul 2013 12:33
Location: Netherlands

Re: SnakeAI

Post by Wormnest » 04 Feb 2018 00:02

It's always good to see a new AI appearing.
However you might think about putting your AI online on bananas. Most people are too lazy to manually install an AI (including me). I think it will increase the chance of getting feedback. Good luck!

mousetail
Engineer
Engineer
Posts: 14
Joined: 22 Mar 2014 08:45

Re: SnakeAI

Post by mousetail » 14 Feb 2018 08:53

New version uploaded to bananas.
New features:
  • The automatic road vehicle duplication system has been tweaked to not overproduce RV's
  • Now secondary industries are also serviced. This allows profit when using YETI where primary industries hardly earn anything.
  • The AI attempts to expand stations when too many vehicles are using them, to prevent traffic jams.
Image
Attachments
screenshot2.png
(4.19 MiB) Not downloaded yet
my AI: CPU, SnakeAI

xarick
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 26 Feb 2015 00:52

Re: SnakeAI

Post by xarick » 14 Feb 2018 15:01

crash report, Snake v2
Attachments
Transport city, 1955-09-01.sav
(241.83 KiB) Downloaded 77 times
screenshot#2.png
(242.64 KiB) Not downloaded yet
Formerly known as Samu

mousetail
Engineer
Engineer
Posts: 14
Joined: 22 Mar 2014 08:45

Re: SnakeAI

Post by mousetail » 15 Feb 2018 19:02

Thanks Xarick, should be fixed now. Other changes include slightly better loan management and some bug fixing in the station expanding routine.
Image
Even though this AI is quite simple, there are still some code paths that are super annoying to debug since they are taken so rarely. Sometimes while testing it runs fine for 20 years before some feature I implemented a long time ago starts behaving weird.
Attachments
screenshot3.png
(2.35 MiB) Not downloaded yet
my AI: CPU, SnakeAI

mousetail
Engineer
Engineer
Posts: 14
Joined: 22 Mar 2014 08:45

Re: SnakeAI

Post by mousetail » 17 Feb 2018 15:30

Updated version:
  • Expanding station works better
  • Slightly changed naming scheme for vehicles
  • Deals properly with new construction getting in the way of old routes
  • Destroys depots that get in the way of expanding stations
Image
Attachments
Brown & Co., Jul 17th, 1954.png
(605.17 KiB) Not downloaded yet
my AI: CPU, SnakeAI

mousetail
Engineer
Engineer
Posts: 14
Joined: 22 Mar 2014 08:45

Re: SnakeAI

Post by mousetail » 26 Feb 2018 14:32

New version, the most significant new feature is planes. Planes are built to form a network, where every airport should have connections to as many as possible different airports as it can handle. Snake can also upgrade airports and airplanes, though it rather often doesn't work for some unknown reason (ERR_UNKNOWN is so fun to debug).
Image
Other changes:
  • Fixed bug where building a new station would sometimes infinite loop
  • RV's are also upgraded
  • Delete one RV when a 3 or more RV's are waiting for full load at a empty station, to avoid all vehicles from a station being sold for negative profit at the same time when it is actually still producing cargo
  • Introduced bug where Snake will continue to try and build routes after the vehicle limit has been passed
  • Actually use vehicle cost to estimate vehicle cost instead of the randomly chosen 10,000 pounds
  • Slightly more efficient loan management during pathfinding
  • Better station naming scheme
  • Introduced many more bugs I have not found yet
Attachments
screenshot4.png
(1.07 MiB) Not downloaded yet
my AI: CPU, SnakeAI

xarick
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 26 Feb 2015 00:52

Re: SnakeAI

Post by xarick » 26 Feb 2018 16:56

I recently took SnakeAI v4 for my road ai competition tests. It did well, here's the topic:

viewtopic.php?p=1171159#p1171159

Once I get the chance, I'll try the newer version.
Formerly known as Samu

xarick
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 26 Feb 2015 00:52

Re: SnakeAI

Post by xarick » 28 Feb 2018 09:16

SnakeAI v4. The AI appears to be stuck for 2 years already. Can't finish building the route.

Code: Select all

dbg: [script] [0] [I] 85
dbg: [script] [0] [I] cloned vehicle LVST Funni Farm to Dintb Facto 15
dbg: [script] [0] [I] fixing unbuilt road (ERR_VEHICLE_IN_THE_WAY)
dbg: [script] [0] [I] #v 1404 max: 2500
dbg: [script] [0] [I] no build location
dbg: [script] [0] [I] Industry failed: Shorbourne Factory(GOOD)
dbg: [script] [0] [I] Industry failed: Fudtown Farm(GRAI)
dbg: [script] [0] [I] Industry failed: Fudtown Farm(LVST)
dbg: [script] [0] [I] Industry failed: Frafingway-on-sea Factory(GOOD)
dbg: [script] [0] [I] from Fort Pendhattan Ridge Farm to Fort Pendhattan Ridge Factory
dbg: [script] [0] [I] Pathfinding...
dbg: [script] [0] [I] Completed, building route
EDIT: My bad, this is SnakeAI v4, not v5, sorry.
Attachments
Snake, 1st May 1960.sav
(1.95 MiB) Downloaded 75 times
screenshot#80.png
(291.27 KiB) Not downloaded yet
Formerly known as Samu

mousetail
Engineer
Engineer
Posts: 14
Joined: 22 Mar 2014 08:45

Re: SnakeAI

Post by mousetail » 28 Feb 2018 17:17

New version, contains mostly fixess:
  • Fixed multiple crashes related to upgrading airports
  • Snake does a better estimation of the number of vehicles initially needed, instead of just building 4
  • Turned out my system to delete vehicles with negative income broke at some point, but it's fixed now
  • Fixed strange behavior when close to the vehicle limit
  • Made airport blacklists clear every five years, so it can retry when new airports become available.
While I think I allready have a bit many high-res images for a thread, I have a really nice screenshot of testing the limits of my AI by putting 190+ busses on a short intercity route. Snake sold most of them after about 1.5 years, except some actually magically managed to make a profit:
Image
@xairick Thanks for the report. That is indeed probably a bug, and I'll look into it.
Attachments
Snake, Jan 21st, 1951.png
(828.65 KiB) Not downloaded yet
my AI: CPU, SnakeAI

mousetail
Engineer
Engineer
Posts: 14
Joined: 22 Mar 2014 08:45

Re: SnakeAI

Post by mousetail » 07 Mar 2018 20:09

Version 7, only minor changes:
  • Fixed bug where attempting to build a plane on a heliport would cause a infinite loop due to no depot being found
  • Made it so Snake prefers connecting industries that are already serviced by itself even if the distance is greater, this increases profit under FIRS and similar sets
  • Now includes a margin before building a new route so upgrading vehicles has priority
my AI: CPU, SnakeAI

mousetail
Engineer
Engineer
Posts: 14
Joined: 22 Mar 2014 08:45

Re: SnakeAI

Post by mousetail » 12 Mar 2018 10:37

Version 8. Turned out my vehicle upgrade system has become horribly broken at some point, resulting in lots of way too old vehicles running around, as well as lots of vehicles without orders. Fixed now.
my AI: CPU, SnakeAI

mousetail
Engineer
Engineer
Posts: 14
Joined: 22 Mar 2014 08:45

Re: SnakeAI

Post by mousetail » 20 Jun 2018 11:33

Version 9. Will now (attempt to) delete level crossings after a train crash. In case of a crash, the AI will first:
  • Replace the vehicle
  • Send all vehicles with shared orders to the depot
  • Wait at least 50 time units, then 10 more until the level crossing can be removed
  • Recursively remove all dead ends owned by Snake in a 10 by 10 area around the crash site
  • re-pathfind the route of the crashed vehicle
  • Start all vehicles on the route again.
Fixed this after noticing Snake was spending excessive amounts of money replacing vehicles on busy level crossings. The system does not currently always work. When multiple lines are using the same level-crossing, only one is replaced. It also does not detect whether the crossing is owned by a other company, (I believe there is no API function for this) and will attempt to destroy it anyway.
my AI: CPU, SnakeAI

xarick
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 26 Feb 2015 00:52

Re: SnakeAI

Post by xarick » 29 Sep 2018 14:23

excessive cpu valuator crash, openttd 1.8.0
Attachments
Unnamed, 1952-05-05.sav
(4.72 MiB) Downloaded 58 times
Unnamed, 1952-04-25.png
(249.01 KiB) Not downloaded yet
Formerly known as Samu

Wormnest
Engineer
Engineer
Posts: 95
Joined: 14 Jul 2013 12:33
Location: Netherlands

Re: SnakeAI

Post by Wormnest » 21 Sep 2019 15:26

Your AI performed great in the first years when starting up. See e.g. the grey line in the image I posted in the EmotionAI topic.
However as soon as SnakeAI reaches the vehicle limits you see many ERR_VEHICLE_TOO_MANY. It should try to improve its best routes in that case and get rid of under performing ones.

It probably also is a good idea to add a setting that defaults to off to allow building debug signs.
Attachments
Unnamed, 2052-05-14.png
(554.88 KiB) Not downloaded yet

mousetail
Engineer
Engineer
Posts: 14
Joined: 22 Mar 2014 08:45

Re: SnakeAI

Post by mousetail » 29 Nov 2019 15:10

Version 10 uploaded: Small update to fix valuator crash and helicopters failing to land on helidepots
my AI: CPU, SnakeAI

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 2 guests