ChooChoo, a train network 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
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

Thanks Zuu! I'll look into it, I think I've seen something similar happen as well.
Wasila
Tycoon
Tycoon
Posts: 1498
Joined: 15 Mar 2008 07:02

Re: ChooChoo, a train network AI

Post by Wasila »

I started this AI about ten minutes into a cargodist game, in 1915 with the 2cc trainset (no actual trains, just 'metro vehicles') and I got this error message immediately:
ChooChoo Error 2.PNG
(78.66 KiB) Downloaded 126 times
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: ChooChoo, a train network AI

Post by Brumi »

Hi Michiel,
I did some testing (again) with your AI and I'm amazed by the construction speed of your AI.
But I also encountered some strange behaviour (screenshot and savegame attached):
I don't know if it's intentional or not, but it tends to start out with single-lane line, totally separate from the network which is built later. It maynot be a problem, but sometimes ChooChoo simply removes one of the railway stations which are already in use.
Anyway, it's nice to see these railway networks! :)
choochoobug.png
choochoobug.png (72.31 KiB) Viewed 3743 times
Unnamed, 18th Jul 1980.sav
(86.83 KiB) Downloaded 191 times
EDIT: I'm using 0.7.1, please tell me if some other version is needed.
Now also available in Bananas :D
It's not in the list under the 'Check online content' in 0.7.1.
Timmaexx
Transport Coordinator
Transport Coordinator
Posts: 301
Joined: 03 Jan 2009 17:55

Re: ChooChoo, a train network AI

Post by Timmaexx »

Brumi wrote:
Now also available in Bananas :D
It's not in the list under the 'Check online content' in 0.7.1.
Nightly?
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: ChooChoo, a train network AI

Post by Brumi »

Timmaexx wrote:Nightly?
It's there in the nightly (r16964), but the same bug occurs in that as well.
choochoobug_nightly.png
choochoobug_nightly.png (98.49 KiB) Viewed 8175 times
Michiel: please edit the first post with the minimum version needed or make ChooChoo available on Bananas for 0.7.1 users!
Last edited by Brumi on 27 Jul 2009 14:20, edited 1 time in total.
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

Brumi wrote:Hi Michiel,
I did some testing (again) with your AI and I'm amazed by the construction speed of your AI.
Thanks for trying it out! I've put in a multiplier in the pathfinder so it doesn't necessarily find the optimum path. This makes it many times faster.
Brumi wrote:But I also encountered some strange behaviour (screenshot and savegame attached):
I don't know if it's intentional or not, but it tends to start out with single-lane line, totally separate from the network which is built later. It may not be a problem, but sometimes ChooChoo simply removes one of the railway stations which are already in use.
That is intentional - on mountainous or desert maps with a 100k loan, it's often not possible to build a crossing (especially if this requires terraforming) and double track and still have enough money left for a train. To avoid that, it starts with a couple of single track lines and the cheapest locomotive, between towns of a minimum size, to generate at least some income. If it makes an unlucky choice it may still fail, but it's more likely to get off the ground. Eventually, I plan to have it remove those lines once it gets decent income from its networks - but that's not implemented yet. It definitely shouldn't delete that station while it is still in use. I've also had a bug report where it would delete the wrong end of a crossing, and I suspect that these may be related. I'll see if I have time to investigate...
It's not in the list under the 'Check online content' in 0.7.1.
Correct, it needs a nightly for one of the bug fixes regarding exceptions. I think it'll work with 0.7.2 once that is released.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: ChooChoo, a train network AI

Post by Yexo »

Michiel wrote:
It's not in the list under the 'Check online content' in 0.7.1.
Correct, it needs a nightly for one of the bug fixes regarding exceptions. I think it'll work with 0.7.2 once that is released.
Can you please check whether it works in 0.7.2-RC2?
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: ChooChoo, a train network AI

Post by Dustin »

Michiel wrote:
Brumi wrote:Hi Michiel,
I did some testing (again) with your AI and I'm amazed by the construction speed of your AI.
Thanks for trying it out! I've put in a multiplier in the pathfinder so it doesn't necessarily find the optimum path. This makes it many times faster.
So did you do this to the A* library, or make your own pathfinder? I spent weeks on a custom made pathfinder that would be faster than A*. Looks like you probably had a better idea. :D

I want to know more about it if you don't mind explaining.
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

Open up the tar and have a peek :)
The current library rail pathfinder doesn't support it yet (the road version does, I think) so I hacked it in. It's only a one line change in the last line:

Code: Select all

function Rail::_Estimate(cur_tile, cur_direction, goal_tiles, self)
{
	local min_cost = self._max_cost;
	/* As estimate we multiply the lowest possible cost for a single tile with
	 *  with the minimum number of tiles we need to traverse. */
	foreach (tile in goal_tiles) {
		local dx = abs(AIMap.GetTileX(cur_tile) - AIMap.GetTileX(tile[0]));
		local dy = abs(AIMap.GetTileY(cur_tile) - AIMap.GetTileY(tile[0]));
		min_cost = min(min_cost, min(dx, dy) * self._cost_diagonal_tile * 2 + (max(dx, dy) - min(dx, dy)) * self._cost_tile);
	}
	return min_cost*self.estimate_multiplier;
}
With self.estimate_multiplier declared at the top of the file. Basically, the higher the multiplier, the faster it is (because it ignores more tiles) and the more the result can deviate from the optimum path. I'm currently using a multiplier of 2. That's usually quite fast, as long as it doesn't have to route around a lake.
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

Yexo wrote:Can you please check whether it works in 0.7.2-RC2?
Seems to work fine!
Kerygma
Engineer
Engineer
Posts: 14
Joined: 30 Jun 2009 11:06
Location: Germany

Re: ChooChoo, a train network AI

Post by Kerygma »

I just encountered a problem when testing ChooChoo with the DBSet. The engine it built is longer than the default so the train doesn't fit into the station, blocking the second platform.
Attachments
Unbenannt, 24. Feb 1940.png
Train too long
(264.79 KiB) Downloaded 88 times
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

Nyargh! Bloody newgrfs :P
OK, seems wagons/engines are not always half a tile (or a multiple) in length. I'll have to check the length of the train in smaller units then.
User avatar
GeekToo
Tycoon
Tycoon
Posts: 961
Joined: 03 Jun 2007 22:22

Re: ChooChoo, a train network AI

Post by GeekToo »

I've been away for a while, and now I've got a little more time, I was pleasantly surprised a couple of more train AI's are present. Congrats!

So I decided to start a game of Tconvoy (the train test version of Convoy) against ChooChoo, to check the quality of the competition, but unfortunately:
(OTTD trunk rev 17030)

Code: Select all

dbg: [ai] [2] [S] *FUNCTION [CheckError()] .../bin/content_download/ai/ChooChoo.302.tar/choochoo.302/task.nut line [59]
dbg: [ai] [2] [S] *FUNCTION [BuildPath()] .../bin/content_download/ai/ChooChoo.302.tar/choochoo.302/builder.nut line [545]
dbg: [ai] [2] [S] *FUNCTION [Run()] ..../bin/content_download/ai/ChooChoo.302.tar/choochoo.302/builder.nut line [505]
dbg: [ai] [2] [S] *FUNCTION [Run()] ..../bin/content_download/ai/ChooChoo.302.tar/choochoo.302/builder.nut line [698]
dbg: [ai] [2] [S] *FUNCTION [Run()] ..../bin/content_download/ai/ChooChoo.302.tar/choochoo.302/task.nut line [99]
dbg: [ai] [2] [S] *FUNCTION [Start()] ..../bin/content_download/ai/ChooChoo.302.tar/choochoo.302/main.nut line [60]
dbg: [ai] [2] [S]
dbg: [ai] [2] [S] [this] INSTANCE
dbg: [ai] [2] [S] [built] true
dbg: [ai] [2] [S] [prevprevprev] 7302
dbg: [ai] [2] [S] [prevprev] 7046
dbg: [ai] [2] [S] [prev] 6790
dbg: [ai] [2] [S] [path] INSTANCE
dbg: [ai] [2] [S] [this] INSTANCE
dbg: [ai] [2] [S] [this] INSTANCE
dbg: [ai] [2] [S] [station] INSTANCE
dbg: [ai] [2] [S] [crossing] INSTANCE
dbg: [ai] [2] [S] [this] INSTANCE
dbg: [ai] [2] [S] [this] INSTANCE
dbg: [ai] [2] [S] [task] INSTANCE
dbg: [ai] [2] [S] [minMoney] 0
dbg: [ai] [2] [S] [this] INSTANCE
User avatar
dillonb3
Engineer
Engineer
Posts: 4
Joined: 31 Jul 2009 11:30
Location: Dundalk, Ireland

Re: ChooChoo, a train network AI

Post by dillonb3 »

I've recently downloaded this AI and I'm having a problem with it. Every time I load a save game of mine with this AI present the AI goes automatically bankrupt. Any Help would be greatly appreciated.
Due to the recession the light at the end of the tunnel has been switched off
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

GeekToo wrote:I've been away for a while, and now I've got a little more time, I was pleasantly surprised a couple of more train AI's are present. Congrats!

So I decided to start a game of Tconvoy (the train test version of Convoy) against ChooChoo, to check the quality of the competition, but unfortunately: [snip]
Thanks! Lemme check... Hmm, that should be fine, actually. In the tar, that's the following bit:

Code: Select all

	case AIError.ERR_NOT_ENOUGH_CASH:
		costEstimate *= 2;
		throw NeedMoneyException(costEstimate);
It should just continue building when it gets more money. If it died there - what version were you running? It needs 0.7.2 or a nightly, which don't have the "die by exception, you AI scum!" bug.
dillonb3 wrote:I've recently downloaded this AI and I'm having a problem with it. Every time I load a save game of mine with this AI present the AI goes automatically bankrupt. Any Help would be greatly appreciated.
It support save/load yet, I'm afraid - it forgets all about its stations when reloaded. I'm about to post an update, I'll try to have basic save/load support in the next version!
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

Update time! Bunch of bug fixes, and cleaner network building - that's what it's about, after all.

Image

As suggested by ZeroMD, stations now come with their own depot. Because of that, I've doubled the interval of depots built along the tracks. Downside: it now needs a 3 tiles wide flat area for stations (because I'm lazy and just check for one big rectangle, not a smaller rectangle plus sticky-outy bit), instead of only 2 tiles wide.

Image

It now removes all bits of crossings that it can. The picture above is what's left after only two sides remain. Also, I've removed the exit signals, which weren't needed and could get trains to block the crossing while they waited for the signal to clear.

New TAR is in the first post and in Bananas.

Current to-do list:
- basic save/load support
- fix bug where building tracks breaks, but it thinks it succceeded
- sell off trains that run at a loss
- go into maintenance mode when the map is full
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

Save/load support! Apparently (I never tested it :oops:) it just crashed hard because I didn't even define my Load() function properly...
Anyway, it turned out that it didn't actually need any persistent state, so this was a quick one :)

It does abandon the current task list, so any network it's working on when you save is abandoned after loading and it just starts a new one. For now, and probably eternity, I won't bother trying to save running pathfinders, etc. :p

New tarballs coming up!

Edit: done! Now I'm back to zero downloads in Bananas :(

Devs: is there a way to make it available in Bananas for both 0.7.2 and nightlies?
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: ChooChoo, a train network AI

Post by Rubidium »

Michiel wrote:Devs: is there a way to make it available in Bananas for both 0.7.2 and nightlies?
If you set minimum version to 0.7.2 and no maximum version it should work.
User avatar
GeekToo
Tycoon
Tycoon
Posts: 961
Joined: 03 Jun 2007 22:22

Re: ChooChoo, a train network AI

Post by GeekToo »

Michiel wrote:
It should just continue building when it gets more money. If it died there - what version were you running? It needs 0.7.2 or a nightly, which don't have the "die by exception, you AI scum!" bug.
GeekToo wrote: (OTTD trunk rev 17030)
And I don't know whether ChooChoo.302.tar is significant for you, I downloaded it last night from Bananas (ingame)
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 40 guests