MailAI

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

Hephi
Engineer
Engineer
Posts: 69
Joined: 25 Oct 2009 09:56
Location: Belgium

MailAI

Post by Hephi » 19 Jan 2011 18:16

Introducing MailAI, an openTTD AI that transports all your love letters and court orders with trucks and trains!

I have updated this AI to version 2.0, currently tested on openTTD version 1.3.2
Massive improvement when planning on routes to build. If stations are doing good enough will start re-using them for further routes creating more complex forms then just PtP lines.
Does NOT spam road vehicles. It sometimes builds 90° turns on rail so this should be enabled in your settings.
For saving/loading functionality: The AI works after loading but might at this moment have unused buildings or routes.

I hope you enjoy this creation and I appreciate any feedback.
Attachments
MailAI-2.22.tar
(279.5 KiB) Downloaded 549 times
Last edited by Hephi on 19 Oct 2013 08:12, edited 10 times in total.
--------------------------------------------------
MailAI, a casual postal service for openTTD.
--------------------------------------------------

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

Re: MailAI

Post by Zuu » 19 Jan 2011 18:51

If you select a pre-defined license on bananas, you must not include any license file in your tar file that you upload. (in case you tried to upload the exact same tar-file as you have uploaded to the forums)

Also be aware that it is required for you to be able to update the AI later, that you use your account to upload it to bananas. If the devs with raw access to the database are involved, they might be able to work around that. Therefore, try to resolve the issues, rather than having some random guy upload your AI.


Edit: Sounds that your AI and PAXLink will be good friends in theory. :-)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2366
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: MailAI

Post by Lord Aro » 19 Jan 2011 19:03

Excellent! I have been watching MailAI for a while

Haven't had a chance to test it yet, but i will as soon as possible
One thing that occurs to me however, is your coding style. It's, well, a bit rubbish :) It will be much easier to debug if you, for example, base the coding style on the wiki page: http://wiki.openttd.org/Coding_Style
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

Hephi
Engineer
Engineer
Posts: 69
Joined: 25 Oct 2009 09:56
Location: Belgium

Re: MailAI

Post by Hephi » 19 Jan 2011 19:58

Lord Aro wrote: One thing that occurs to me however, is your coding style. It's, well, a bit rubbish :)

Haha :) I do try to make it logical sometimes. Are you referring to what variables I create and at what point or how I handle passing things to functions or what? I know some parts are a big mess because I kept adding code to it.


About the bananas: openTTD accepts 'false' tar files made with winRAR and can read them perfectly, Bananas wants 'real' TAR files so I needed to make it with another archive program (7-zip)
--------------------------------------------------
MailAI, a casual postal service for openTTD.
--------------------------------------------------

Yexo
Tycoon
Tycoon
Posts: 3653
Joined: 20 Dec 2007 12:49

Re: MailAI

Post by Yexo » 19 Jan 2011 21:40

I was just reading some of your code and have a few comments;

Code: Select all

//bad solution to a AIEngine.CanPullCargo,AICargo.CC_MAIL bug using newGRF's
	//following engines can carry mail but will not be on the CanPullCargo returned list
AIEngine.CanPullCargo takes a CargoID as argument, not a cargoclass. As such passing AICargo.CC_MAIL as argument is wrong.

Code: Select all

	local types = AIRailTypeList();
	if (types.Count()>1)
	{
		AIRail.SetCurrentRailType(1);
	} else
	{
		AIRail.SetCurrentRailType(0);	
	}
With railtype newgrfs there is no guarantee that railtype "0" is available. It can happen that railtypes 5 and 6 are available but neither 0 nor 1 are.


I haven't played with your AI yet, but I'll definitely be giving it a try.

Hephi
Engineer
Engineer
Posts: 69
Joined: 25 Oct 2009 09:56
Location: Belgium

Re: MailAI

Post by Hephi » 19 Jan 2011 22:47

I didn't notice the difference bewteen cargoclass and cargo id. How can I know what cargo id to use then? I don't see a list on the NoAI API.

I know about the rail problem but as long as there's no better way of detecting the rail types this will have to work.
--------------------------------------------------
MailAI, a casual postal service for openTTD.
--------------------------------------------------

Yexo
Tycoon
Tycoon
Posts: 3653
Joined: 20 Dec 2007 12:49

Re: MailAI

Post by Yexo » 19 Jan 2011 22:55

You already have the code for that:

Code: Select all

   /*taken out to minimize error value list
   	local mail_list = AICargoList();
	mail_list.Valuate(AICargo.HasCargoClass, AICargo.CC_MAIL);
	mail_list.KeepValue(1);
	if(mail_list.IsEmpty())throw("No mail available in this game! Crashing wildly!");
   */

Hephi
Engineer
Engineer
Posts: 69
Joined: 25 Oct 2009 09:56
Location: Belgium

Re: MailAI

Post by Hephi » 19 Jan 2011 23:09

aha! I remember... thanks. I'll fix that on the next occasion.
--------------------------------------------------
MailAI, a casual postal service for openTTD.
--------------------------------------------------

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

Re: MailAI

Post by Brumi » 20 Jan 2011 10:19

Nicely done :)
You must must have put quite a lot of work in it, it's already bigger in terms of code size than SimpleAI :D
I'm running a game right now, it's been running for 16 years, and... well, it crashed right now, presumably because the first electric locomotive has been introduced.
Unnamed, 5th Aug 1966.png
Unnamed, 5th Aug 1966.png (19.53 KiB) Viewed 15703 times
Apart from that, the only bug I've encountered so far was this:
Unnamed, 3rd Jan 1960.png
Unnamed, 3rd Jan 1960.png (69.9 KiB) Viewed 15703 times
And another one of this type:
Unnamed, 10th Jan 1967.png
Unnamed, 10th Jan 1967.png (68.92 KiB) Viewed 15703 times
There were two instances of MailAI running for a while, but they tended to use the same towns, so I stopped the second instance. It's not a big problem, as not all towns are able to produce a sufficient amount of mail...

The estimates in the AI debug window are a bit strange to me... Why is the actual profit sometimes higher than the optimal profit? :)

Anyway, the routes are nicely built, I like those passing lane sections :D

Hephi
Engineer
Engineer
Posts: 69
Joined: 25 Oct 2009 09:56
Location: Belgium

Re: MailAI

Post by Hephi » 20 Jan 2011 11:06

About the four things Brumi posted:

1: Bug fixed, was a typo in replaceVehicle (will be in next update)
2: This is more difficult, I've rewritten the code a bit but apparently it still needs changing. I'm gonna rewrite from the start I think.
3: This is 'normal', it found a switch location but blocked the other track while building it. As it's only graphics this is low on the todo list.
4: Two instances use the same towns indeed. I'm gonna write a function that checks for mail transported before building a route.

Thanks for the input!


New version uploaded in first post!
20/01/2011
- BUGFIX typo caused errors in replaceVehicle (Brumi).
- Replaced cargoclass with cargoid when selecting engines/wagons (Yexo).
- BUGFIX building a depot which it couldn't connect to the road.
- Started code cleanup to be a little less rubish (Lord Aro).
- BUGFIX Didn't start the train after selling a wagon.
--------------------------------------------------
MailAI, a casual postal service for openTTD.
--------------------------------------------------

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

Re: MailAI

Post by Brumi » 21 Jan 2011 12:51

I'm testing the new version. No crash or misplaced rail station this time :)
However, in 1971 (the game was started in 1950) the AI has only 4 trains and 6 road vehicles, although there are other cities worthy of mail transport. And I saw this in the AI debug window:
Unnamed, 8th Apr 1971.png
(41.18 KiB) Downloaded 2 times
For some reason, this window still displays v20110119, although it is the newest version.

I've attached the savegame.
Attachments
Unnamed, 14th Apr 1971.sav
(463.09 KiB) Downloaded 261 times

Hephi
Engineer
Engineer
Posts: 69
Joined: 25 Oct 2009 09:56
Location: Belgium

Re: MailAI

Post by Hephi » 21 Jan 2011 19:45

I forgot to adjust version number :oops:

About your save game. What grf are you using? It says I'm missing grf files when I load the game.

It appears to me that the AI must have 'hung' building a railroute. I can't find a solution for controling the railpathfinder,
if there's no possible route it just keeps on looking. The best way to work around this is save and load the game which restarts the AI.

That's also why if you load up your saved game it suddenly sends all those old vehicles to the depot for replacing.
While it was hanging it couldn't perform the vehicle checks. It also immediately started building a new rail route.

I'll add some code that will show the town it's trying to build so whenever the AI has hung we'll see
because the last lines will be 'building rail route from townA to townB' and nothing ever comes after it.

On openttdcoop there's a new version if you're interested, ran out of time to tar it and upload it here.
21/01/2011
- IMPROVE Handling objects in the way of the railpathfinder. (crossing roads and rails)
- IMPROVE Correctly detecting bridges in BuildPassings so trackwalker can continue.
- IMPROVE Rewrote code that builds the switch in front of the station, now also chooses best side. (Brumi)
- FIX Typo in BuildRailStation that led to leaving (yet another) tile undestroyed when cleaning up station.
- BUGFIX Switchlocation finder handled coast tiles wrong.
- BUGFIX Sold vehicle before orders where copied resulting in empty order list.
- BUGFIX When selling wagons it was possible for the train to end up stopped at the depot.
- BUGFIX when it couldn't move wagons (Brumi)
--------------------------------------------------
MailAI, a casual postal service for openTTD.
--------------------------------------------------

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

Re: MailAI

Post by Zuu » 21 Jan 2011 20:14

If you have a recent nightly or 1.1 beta you can click on the NewGRF button on the load game dialog and then find on online content.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

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

Re: MailAI

Post by Brumi » 21 Jan 2011 20:17

Hephi wrote:About your save game. What grf are you using? It says I'm missing grf files when I load the game.
I was using the Generic Tram Set and the Temperate Oil Wells Only Decrease Neutralizer (I wish this name wasn't this long :D ), none of them should affect your AI.

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

Re: MailAI

Post by SirkoZ » 21 Jan 2011 21:26

Brumi wrote:I was using the Generic Tram Set and the Temperate Oil Wells Only Decrease Neutralizer (I wish this name wasn't this long :D ), none of them should affect your AI.
:lol: I just had to somehow put the word neutraliser into it. :mrgreen:

Anyhow - just saw this topic - I'll give the newcomer AI a run together with SimpleAI.
tasty.gif
tasty.gif (1.45 KiB) Viewed 15575 times

dasy2k1
Transport Coordinator
Transport Coordinator
Posts: 334
Joined: 20 Sep 2006 23:43
Location: UK
Contact:

Re: MailAI

Post by dasy2k1 » 25 Mar 2011 16:36

Ive found a bug...

It dosent seem to be aware of the forbid trains from making 90° turns setting and such keeps building impossible railways (normally with 90° required to exit passing loops)

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

Re: MailAI

Post by Zuu » 25 Mar 2011 21:18

In bananas, I have noticed that you have set the url to:

Code: Select all

http://www.tt-forums.net/viewtopic.php?f=65&t=52478&p=925782#p925782/projects/ai-mailai
Perhaps the ending part is a paste-error?
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

Hephi
Engineer
Engineer
Posts: 69
Joined: 25 Oct 2009 09:56
Location: Belgium

Re: MailAI

Post by Hephi » 01 Apr 2011 07:24

dasy2k1 wrote:Ive found a bug...

It dosent seem to be aware of the forbid trains from making 90° turns setting and such keeps building impossible railways (normally with 90° required to exit passing loops)

It's somewhere in the fine print that this AI needs 90° turns enabled. Normally 90° degree turns should only exist in
a rare occasion on station exit and with some depots. Sorry for the inconvenience.
--------------------------------------------------
MailAI, a casual postal service for openTTD.
--------------------------------------------------

Hephi
Engineer
Engineer
Posts: 69
Joined: 25 Oct 2009 09:56
Location: Belgium

Re: MailAI

Post by Hephi » 01 Apr 2011 07:25

Zuu wrote:In bananas, I have noticed that you have set the url to:

Code: Select all

http://www.tt-forums.net/viewtopic.php?f=65&t=52478&p=925782#p925782/projects/ai-mailai
Perhaps the ending part is a paste-error?
I guess so but the clicky works :)
--------------------------------------------------
MailAI, a casual postal service for openTTD.
--------------------------------------------------

Hephi
Engineer
Engineer
Posts: 69
Joined: 25 Oct 2009 09:56
Location: Belgium

Re: MailAI

Post by Hephi » 25 Jul 2011 15:46

Found a bug trying to build a rail station. I'm not sure why it didn't build the train station but still went ahead building the truck station adjacent to the rail station. Also the added articulated stops function should only build to the adjacent station but seem to be build on the spot where the train station should be.

Image
--------------------------------------------------
MailAI, a casual postal service for openTTD.
--------------------------------------------------

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 2 guests