SimpleAI v14 - trying to remake the old 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
3iff
Tycoon
Tycoon
Posts: 983
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: SimpleAI v9 - trying to remake the old AI

Post by 3iff » 16 Jan 2015 10:34

I never have inflation on so I suppose this 'problem' won't affect me when I use SimpleAI ?

Brumi
President
President
Posts: 904
Joined: 18 Jul 2009 17:54

Re: SimpleAI v9 - trying to remake the old AI

Post by Brumi » 16 Jan 2015 12:48

Yes, it won't affect you. I also never play with inflation myself, the AI actually doesn't cope that well with inflation...

User avatar
3iff
Tycoon
Tycoon
Posts: 983
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: SimpleAI v9 - trying to remake the old AI

Post by 3iff » 16 Jan 2015 13:14

...neither do I. Thanks for that info.

User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1502
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: SimpleAI v9 - trying to remake the old AI

Post by SirkoZ » 18 Jan 2015 19:06

If starting strong (some trains or planes), the SimpleAI copes normally with inflation (4% interest rate),
of course with fixed inflation-affected calculation.

Brumi
President
President
Posts: 904
Joined: 18 Jul 2009 17:54

Re: SimpleAI v10 - trying to remake the old AI

Post by Brumi » 12 Aug 2015 17:21

Long time, no see, eh? :)

I received a contribution from 3iff, which enables the AI to use a custom company naming scheme instead of the default "<town name> Transport" style. It can be enabled in the settings of the AI.
Examples:
SimpleAI names.png
SimpleAI names.png (25.53 KiB) Viewed 6222 times
I've also fixed the problem with the inflation discussed in the last page (hopefully...).

So the new version is out, you can download it from your favourite fruit store or the first post of this thread.

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

Re: SimpleAI v10 - trying to remake the old AI

Post by xarick » 20 Jun 2016 22:13

SimpleAI v10 OpenTTD 1.6.1-RC1

SimpleAI crashed with "Too long to save." error. Server started in 1950.
dbg: [script] [0] [W] Trying to get subsidy:
dbg: [script] [0] PASS from Benfingbridge to Sondtown
dbg: [script] [0] Using single rail
dbg: [script] [0] Chosen wagon: Passenger Carriage
dbg: [script] [0] Chosen engine: 'Millennium Z1' (Electric)
dbg: [script] [0] [W] Could not build source station at Benfingbridge
dbg: [script] [0] _______________________
dbg: [script] [0]
dbg: [script] [0] Train 1,303 is getting old, sending it to the depot...
dbg: [script] [0] Train 1,304 is getting old, sending it to the depot...
dbg: [script] [0] [W] Trying to get subsidy:
dbg: [script] [0] MAIL from Slinthill to Sennington
dbg: [script] [0] [E] No vehicle type available!
dbg: [script] [0] _______________________
dbg: [script] [0] [I]
dbg: [script] [0] [W] Trying to get subsidy:
dbg: [script] [0] [I] PASS from Benfingbridge to Sondtown
dbg: [script] [0] [I] Using single rail
dbg: [script] [0] [I] Chosen wagon: Passenger Carriage
dbg: [script] [0] [I] Chosen engine: 'Millennium Z1' (Electric)
dbg: [script] [0] [W] Could not build source station at Benfingbridge
dbg: [script] [0] [I] _______________________
dbg: [script] [0] [I]
dbg: [script] [0] [I] Train 560 is getting old, sending it to the depot...
dbg: [script] [0] [I] Train 1,305 is getting old, sending it to the depot...
dbg: [script] [0] [W] Trying to get subsidy:
dbg: [script] [0] [I] PASS from Benfingbridge to Sondtown
dbg: [script] [0] [I] Using single rail
dbg: [script] [0] [I] Chosen wagon: Passenger Carriage
dbg: [script] [0] [I] Chosen engine: 'Millennium Z1' (Electric)
dbg: [script] [0] [W] Could not build source station at Benfingbridge
dbg: [script] [0] [I] _______________________
dbg: [script] [0] [I]
dbg: [script] [0] [I] Train 1,306 is getting old, sending it to the depot...
dbg: [script] [0] [E] This script took too long to Save.
dbg: [script] The script died unexpectedly.
One of the running scripts crashed. Please report this to the script author with a screenshot of the AI/Game Script Debug Window
Attachments
Senfingbridge Transport, 1st Dec 2009.sav
(3.73 MiB) Downloaded 95 times
Senfingbridge Transport, 1st Jan 2010.sav
(3.68 MiB) Downloaded 89 times
openttdCore2.cfg
(11.97 KiB) Downloaded 88 times
Formerly known as Samu

Brumi
President
President
Posts: 904
Joined: 18 Jul 2009 17:54

Re: SimpleAI v10 - trying to remake the old AI

Post by Brumi » 27 Jun 2016 18:24

Whoa, that's unexpected, considering that SimpleAI doesn't do anything fancy when saving.

I loaded your savegames, and this is definitely a game too large for this AI. The game stutters quite hard, probably when the AI is doing the general maintenance loop on its routes. It doesn't stutter that hard with the 2010 savegame, so I assume that it's indeed the AI that causes the stuttering. The 2010 savegame is after the crash, right? Because the AI didn't load anything from that one, and it may explain why the 2010 savegame is easier on my computer.

The AI probably has more than 1000 routes in this game, and it seems that this is simply too much. The only solution to this is to introduce a cap for the number of routes that can be built. It's too bad though that it is quite hard to determine a suitable cap :)
For the time being, using lower limits for vehicles or a smaller map will probably avoid this problem.

Thanks for reporting!

Brumi
President
President
Posts: 904
Joined: 18 Jul 2009 17:54

Re: SimpleAI v12 - trying to remake the old AI

Post by Brumi » 10 May 2017 22:16

New version! :) (although it's only a small bugfix...)

There was a recent test done by DerekCZ, which tested the AIs with the World Airliners Set. While the AI did well in DerekCZ's test, Wormnest also tested the AI, and he found out that the AI sometimes won't start building aircraft even when they're the only allowed means of transportation.
So this bug was fixed, SimpleAI should be able to start now if there are some planes it can actually afford.

Version 11 was skipped simply because I messed up the first upload to Bananas :|

And as usual, the new version is available from Bananas or the first post of this thread.

User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1502
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: SimpleAI v12 - trying to remake the old AI

Post by SirkoZ » 21 Oct 2017 19:02

Thank you for this new release, Brumi. As ever, your AI complements OpenTTD perfectly. 8)

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

Re: SimpleAI v12 - trying to remake the old AI

Post by xarick » 27 Feb 2018 22:46

SimpleAI v12, 1.7.2

While testing the new version, it took too long to save while competing for 100 years trains only.

Code: Select all

dbg: [script] [0] [I] _______________________
dbg: [script] [0] [I] 
dbg: [script] [0] [W] Trying to build new service:
dbg: [script] [0] [I] WHEA from Tunston Farm to Frinfinghill City Food Processing Plant
dbg: [script] [0] [I] Using double rail
dbg: [script] [0] [I] Chosen wagon: Grain Hopper
dbg: [script] [0] [I] Chosen engine: 'Millennium Z1' (Electric)
dbg: [script] [0] [I] New station successfully built: Tunston Exchange
dbg: [script] [0] [I] New station successfully built: Frinfinghill City Branch
dbg: [script] [0] [I] Pathfinding...
dbg: [script] [0] [W] Pathfinding failed.
dbg: [script] [0] [I] _______________________
dbg: [script] [0] [I] 
dbg: [script] [0] [E] This script took too long to Save.
dbg: [script] The script died unexpectedly.
One of the running scripts crashed. Please report this to the script author with a screenshot of the AI/Game Script Debug Window
Attachments
Grendingham Transport, 1st Jul 2019.sav
last month alive
(3.87 MiB) Downloaded 59 times
Grendingham Transport, 1st Aug 2019.sav
dead
(3.83 MiB) Downloaded 61 times
Formerly known as Samu

Brumi
President
President
Posts: 904
Joined: 18 Jul 2009 17:54

Re: SimpleAI v12 - trying to remake the old AI

Post by Brumi » 28 Feb 2018 09:48

Thanks for the report :)
I see you've already encountered this problem more than a year ago... Although there are no guarantees that such a fix will work, I will simply have to introduce a hard limit on the number of routes the AI may build.
I don't know when I will be able to gather some time to do it though, but hopefully not too far in the future :)

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

Re: SimpleAI v12 - trying to remake the old AI

Post by xarick » 17 Aug 2018 00:31

Crash with division by 0.
Attachments
Unnamed, 1964-06-20.png
(284.6 KiB) Not downloaded yet
Formerly known as Samu

Brumi
President
President
Posts: 904
Joined: 18 Jul 2009 17:54

Re: SimpleAI v12 - trying to remake the old AI

Post by Brumi » 20 Aug 2018 12:09

Wow, thanks :) This is such a trivial error, I have no idea how we have not seen it earlier!

Brumi
President
President
Posts: 904
Joined: 18 Jul 2009 17:54

Re: SimpleAI v13 - trying to remake the old AI

Post by Brumi » 20 Aug 2018 13:31

Aaaaand there is a new release.

Two bugs reported by xarick are fixed in this release:
  • Fixed the division-by-zero error reported just above.
  • Hopefully fixed the "took too long to save" crash by capping the number of routes at 1000. Luckily, the AI only gets near 1000 under special circumstances, the route count is only around 200-300 in my tests :)
The new version is available from BaNaNaS and the first post of this thread.
Thanks xarick for reporting these bugs!

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

Re: SimpleAI v13 - trying to remake the old AI

Post by xarick » 10 Nov 2018 14:01

SimpleAI v13 created some trains with no orders. I'm not entirely sure what happened, I didn't see it how it started, but I saw the trains running on an unfinished route. I think, but not sure, it build the stations first, then the trains, and only after that, the route. Trains became no longer lost when the route was finished, but they're still without orders.

EDIT: Actually, this is very weird. I'm seeing other AIs with vehicles with no orders, including mine. Need to investigate this better.
EDIT2: Seems that the orders can't be placed. I opened an issue https://github.com/OpenTTD/OpenTTD/issues/6968
Attachments
Unnamed, 1952-12-03.png
(164.83 KiB) Not downloaded yet
Unnamed, 1952-12-03.sav
(17.41 MiB) Downloaded 51 times
Formerly known as Samu

Brumi
President
President
Posts: 904
Joined: 18 Jul 2009 17:54

Re: SimpleAI v13 - trying to remake the old AI

Post by Brumi » 19 Nov 2018 08:45

Well, I had no idea that this was a thing in OpenTTD :)

Thanks for your effort!

User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1502
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: SimpleAI v13 - trying to remake the old AI

Post by SirkoZ » 06 Jan 2019 21:54

Firstly a happy and healthy new year to you all! :)

Now a small issue has been persisting for the last few releases, Brumi.
When AI tries to place lorry near a factory or bus station in town, sometimes it leaves behind road pieces when it can't build the service and deletes the station and depot.
Screenshot:
Attachments
simpleai_13_road_remains.png
simpleai_13_road_remains.png (115.09 KiB) Viewed 3542 times

Brumi
President
President
Posts: 904
Joined: 18 Jul 2009 17:54

Re: SimpleAI v13 - trying to remake the old AI

Post by Brumi » 09 Jan 2019 08:33

Interesting, I wonder why it does that... I guess the other stations nearby have nothing to do with it?

User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1502
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: SimpleAI v13 - trying to remake the old AI

Post by SirkoZ » 09 Jan 2019 10:02

I don't think other stations have anything to do with it.
Sometimes it only "forgets to remove" 2 road pieces in the shape of letter C.

P.S.: I'm currently testing the "delete station and depot after delete the >>C<< roadpieces" code...

Code: Select all

builder.nut -> DeleteRoadStation function
	if (!AIRoad.AreRoadTilesConnected(front, front + dir1) && !AIRoad.AreRoadTilesConnected(front, front - dir2) &&
	!AIRoad.AreRoadTilesConnected(front2, front2 + dir1) && !AIRoad.AreRoadTilesConnected(front2, front2 + dir2)) {
		AITile.DemolishTile(front);
		AITile.DemolishTile(front2);
	}
	AITile.DemolishTile(place);
	AITile.DemolishTile(depot);
Yes, this works just right.

User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1502
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: SimpleAI v13 - trying to remake the old AI

Post by SirkoZ » 09 Jan 2019 13:45

Another thing - in railbuilder.nut -> function TrainEngineValuator is a mixup which causes in games
(subtropic and snow terrain) with inflation and even with vehicles_never_expire the AI to replace faster
engines with the slowest one in later years of the game (approaching 2000), becuase it thinks this is the
cheaper route.
Instead of this:

Code: Select all

	local runningcost_limit = (6000 / Banker.GetInflationRate()).tointeger();
	local runningcost = AIEngine.GetRunningCost(engine).tofloat();
there should be this:

Code: Select all

	local runningcost_limit = 6000;
	local runningcost = (AIEngine.GetRunningCost(engine).tofloat() / Banker.GetInflationRate()).tointeger();
which works well.

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 0 guests