Page 1 of 3

MailAI

Posted: 19 Jan 2011 18:16
by Hephi
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.

Re: MailAI

Posted: 19 Jan 2011 18:51
by Zuu
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. :-)

Re: MailAI

Posted: 19 Jan 2011 19:03
by Lord Aro
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

Re: MailAI

Posted: 19 Jan 2011 19:58
by Hephi
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)

Re: MailAI

Posted: 19 Jan 2011 21:40
by Yexo
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.

Re: MailAI

Posted: 19 Jan 2011 22:47
by Hephi
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.

Re: MailAI

Posted: 19 Jan 2011 22:55
by Yexo
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!");
   */

Re: MailAI

Posted: 19 Jan 2011 23:09
by Hephi
aha! I remember... thanks. I'll fix that on the next occasion.

Re: MailAI

Posted: 20 Jan 2011 10:19
by Brumi
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 29461 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 29461 times
And another one of this type:
Unnamed, 10th Jan 1967.png
Unnamed, 10th Jan 1967.png (68.92 KiB) Viewed 29461 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

Re: MailAI

Posted: 20 Jan 2011 11:06
by Hephi
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.

Re: MailAI

Posted: 21 Jan 2011 12:51
by Brumi
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
Unnamed, 8th Apr 1971.png (41.18 KiB) Viewed 6493 times
For some reason, this window still displays v20110119, although it is the newest version.

I've attached the savegame.

Re: MailAI

Posted: 21 Jan 2011 19:45
by Hephi
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)

Re: MailAI

Posted: 21 Jan 2011 20:14
by Zuu
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.

Re: MailAI

Posted: 21 Jan 2011 20:17
by Brumi
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.

Re: MailAI

Posted: 21 Jan 2011 21:26
by SirkoZ
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 29333 times

Re: MailAI

Posted: 25 Mar 2011 16:36
by dasy2k1
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)

Re: MailAI

Posted: 25 Mar 2011 21:18
by Zuu
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?

Re: MailAI

Posted: 01 Apr 2011 07:24
by Hephi
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.

Re: MailAI

Posted: 01 Apr 2011 07:25
by Hephi
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 :)

Re: MailAI

Posted: 25 Jul 2011 15:46
by Hephi
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