Trans AI .:19.07.23 :.

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
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: Trans AI :: 09-07-13 ::

Post by fanioz »

Dustin wrote: Fanioz,

I am trying your AI out against mine. In 3 of 4 trials your AI got off to a slow start and went bankrupt (at which time I stopped). However, when yours got a good start, mine can't keep up. My passing lane builder is just too slow. (I have some ideas to fix that.) Your system (however it works) works nicely and you build routes much faster than my AI. Well done sir!

I like your network. Your stations with the depot and PBS signal works really well.

I would suggest you should limit your starting route distance. If your first route is short (50-200 tiles) then your AI gets a good start and runs well. Otherwise it's very nice. I really like your debug output. Very friendly. -> Good Job :-D

I would like to see derchesten try to do better. Yours is a nice AI and I am impressed by it. Moreso that you aren't a programmer. Squirrel isn't the easiest scripting language! (But I like it well for this.)
Thanks Dustin. :D. I would like to take an other approach to solve the pathfinding waste time.
Thanks for testing. :D
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: Trans AI :: 09-07-13 ::

Post by Brumi »

Hi Fanioz,
I experienced some strange behaviour while playing with your AI. If '#opcodes before AI is suspended' is set to 5,000, sometimes Trans AI 'forgets' to start the first vehicle of a line, and doesn't rename the recieving station. I tried to figure out when this happens, but it seems to be random, it occurs in roughly 50% of the cases when the opcode count is set to 5,000. May be a bug in the API... Or are the AIs expected to behave differently based on this setting?
Anyway, I like the idea that Trans starts the first train before building the second line, it comes good if the AI fails to build it.
TransAI strange behaviour.sav
(90.22 KiB) Downloaded 172 times
And some other issues:
If the AI fails to connect a road due to congestion, it doesn't check (correctly) if the road is OK or the vehicles indeed arrive to the station. Later Trans buys loads of new trucks, hoping to improve the service, but fails.
I'm happy to see that Trans transports mail (and passengers by train), but it's not optimal yet, it often tries to transport mail from small villages. Or it builds entire mail trains, and the station is too far away from the town centre. Maybe combined passenger/mail trains?
I'm sorry if I seem to crtiticise your AI, in fact I really like it :)
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Trans AI :: 09-07-13 ::

Post by Zuu »

About not renaming certain stations, I have noticed that sometimes PAXLink fail to rename its inter-city stations. I have not been able to track down the reason for it, but I have not tried any different op-code settings than the default value.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: Trans AI :: 09-07-13 ::

Post by fanioz »

Brumi wrote:Hi Fanioz,
Hi, (again) Brumi :D
Brumi wrote: I experienced some strange behaviour while playing with your AI. If '#opcodes before AI is suspended' is set to 5,000, sometimes Trans AI 'forgets' to start the first vehicle of a line, and doesn't rename the recieving station. I tried to figure out when this happens, but it seems to be random, it occurs in roughly 50% of the cases when the opcode count is set to 5,000. May be a bug in the API... Or are the AIs expected to behave differently based on this setting?
Anyway, I like the idea that Trans starts the first train before building the second line, it comes good if the AI fails to build it.
TransAI strange behaviour.sav
me too, :D , So, it maybe API/OpenTTD bug, but I need to prove it with simplified script to reproduce this behaviour. Another thing happened if opcode was set to 5,000 is : Building a long rail track (about 400+ tiles) it will can't build some tiles in the middle, with the result of AIError.GetLastError() == AIError.Unknown.
And since the sequence of servicing is not satisfied, TransAI will immediatelly break, so it doesn't rename the station. And you're right, this occurs in roughly 50% of the cases.
Brumi wrote: And some other issues:
If the AI fails to connect a road due to congestion, it doesn't check (correctly) if the road is OK or the vehicles indeed arrive to the station. Later Trans buys loads of new trucks, hoping to improve the service, but fails.
Current code doesn't check if a vehicle was arrive at station, just make sure there are road tiles connected. I think, I should improve this. :)
Brumi wrote: I'm happy to see that Trans transports mail (and passengers by train), but it's not optimal yet, it often tries to transport mail from small villages. Or it builds entire mail trains, and the station is too far away from the town centre. Maybe combined passenger/mail trains?
Trans, would try to transport all transportable cargo, but it seems there are many things to check before doing something. :)
Brumi wrote: I'm sorry if I seem to crtiticise your AI, in fact I really like it :)
Thanks, I'm glad to know what is inside your mind / your opinion about Trans. :D
Zuu wrote:About not renaming certain stations, I have noticed that sometimes PAXLink fail to rename its inter-city stations. I have not been able to track down the reason for it, but I have not tried any different op-code settings than the default value.
Well, if that is really true, it mean that OpenTTD opcode switcher (or whatever the name :?: ) forget to return to AI's state, or there is something I did'nt know yet ? :D
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: Trans AI :: 09-07-13 ::

Post by Brumi »

Hi Fanioz,
Recently I've been trying to understand the mechanics of your AI by looking at the AI debug window. Reading the code itself is still hard for me, as I'm completely new to C and Squirrel.
I have a few questions:
What is PRECONDITION_FAILED? ?( The API documentation doesn't say much about this. I'm comfused when I see lines like this: Last month transported:0 PRECONDITION_FAILED
Is it intentional that it always tries the same destination for a given cargo? It can lead to complications when there is not enough space to build the destination station.
I tested TransAI on toyland as well (Why not? :)) ), and there fizzy drinks seem to be problematic. I think this problem may apply to all types of secondary cargo which are transported to towns.
Here is a screenshot:
transai fizzydrink.png
transai fizzydrink.png (111.53 KiB) Viewed 750 times
It seems that TransAI failed to build the source station, and that particular fizzy drink factory can be seen in the background. I think a station could be built there without problems... It might be the problem that Trans doesn't build adjacent stations separately (from a player-point of view, it doesn't press Ctrl while placing a station). Or is it the destination station which cannot be built? :? (it is always harder for goods-type cargoes)
And one more thing, the bug I mentioned in my previous post occurs if the opcode count is set to 10,000, but with a smaller probability.
Nevertheless, it is a good AI, I think it is fun to play against. I like the friendly environment of the debug window, welcoming new companies and industries, etc. :)
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: Trans AI :: 09-07-13 ::

Post by fanioz »

Brumi wrote:Hi Fanioz,
Hi Brumi :D
Brumi wrote: Recently I've been trying to understand the mechanics of your AI by looking at the AI debug window. Reading the code itself is still hard for me, as I'm completely new to C and Squirrel.
I'm a newbie too :) ,look at the 2nd post, there was downloadable code documentation , you may could understand some of them.
Brumi wrote: I have a few questions:
What is PRECONDITION_FAILED? ?( The API documentation doesn't say much about this. I'm comfused when I see lines like this: Last month transported:0 PRECONDITION_FAILED
int32 AIIndustry::GetLastMonthTransported (IndustryID industry_id, CargoID cargo_id) [static]
Get the total amount of cargo transported from an industry last month.

Parameters:
industry_id The index of the industry.
cargo_id The index of the cargo.

Precondition:
IsValidIndustry(industry_id).

AICargo::IsValidCargo(cargo_id).

Returns:
The amount of given cargo transported from this industry last month.
When the Industry no longer valid (disappear) this will return PRECONDITION_FAILED
Brumi wrote: Is it intentional that it always tries the same destination for a given cargo? It can lead to complications when there is not enough space to build the destination station.
Yes. I've think about it. And current code should choose another new destination. But it maybe doesn't work well now.
Brumi wrote: I tested TransAI on toyland as well (Why not? :)) ), and there fizzy drinks seem to be problematic. I think this problem may apply to all types of secondary cargo which are transported to towns.
Here is a screenshot:
transai fizzydrink.png
It seems that TransAI failed to build the source station, and that particular fizzy drink factory can be seen in the background. I think a station could be built there without problems... It might be the problem that Trans doesn't build adjacent stations separately (from a player-point of view, it doesn't press Ctrl while placing a station). Or is it the destination station which cannot be built? :? (it is always harder for goods-type cargoes)
The log said, it was source station can't build there, and I have not found any valid reason why Trans can't find tile any more
Brumi wrote: And one more thing, the bug I mentioned in my previous post occurs if the opcode count is set to 10,000, but with a smaller probability.
I still have no a valid reason too for this.
Brumi wrote: Nevertheless, it is a good AI, I think it is fun to play against. I like the friendly environment of the debug window, welcoming new companies and industries, etc. :)
Thanks... I'm still working on this AI to improve it. :D
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Trans AI :: 09-07-13 ::

Post by Yexo »

fanioz wrote:When the Industry no longer valid (disappear) this will return PRECONDITION_FAILED
Please don't count on that as the IndustryID will be reused when a new industry appears. For example. it's possible that an industry closes on jan 1, and on jan 2 a new industry opens with the same ID.
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: Trans AI :: 09-07-13 ::

Post by Dustin »

Yexo wrote:
fanioz wrote:When the Industry no longer valid (disappear) this will return PRECONDITION_FAILED
Please don't count on that as the IndustryID will be reused when a new industry appears. For example. it's possible that an industry closes on jan 1, and on jan 2 a new industry opens with the same ID.
I have the same sort of logic in my AI. What I did it save the location of the industry, then check to see if that location still has an industry with the same ID. To trick my AI the game would have to remove the industry, then plop down a new one in the same spot with the same ID but different cargo within 90 days.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Trans AI :: 09-07-13 ::

Post by Yexo »

Again, don't count on that not happening. A user might not like a coal mine and use the magic bulldozer cheat to destroy it and then build an iron mine in the same spot;
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: Trans AI :: 09-07-13 ::

Post by Dustin »

Yexo wrote:Again, don't count on that not happening. A user might not like a coal mine and use the magic bulldozer cheat to destroy it and then build an iron mine in the same spot;
Well, I personally consider that to be pretty unlikely. And when the coal runs out I would sell off the route anyway.
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: Trans AI :: 09-07-13 ::

Post by fanioz »

Okay, after investigating ...: :D
1. Its maybe an invalid industry
2. Its maybe an invalid cargo
3. its maybe my variable for storing Industry is not valid
4. All of above is valid :
In this case, my debugger code give an invalid output. it only check if

Code: Select all

 AIError.GetLastError() != AIError.ERR_NONE;
If there is error from previous command (before checking last_month_transported), it would be catch again here. Therefore I ever asked something like AIError.ClearLastErr(), but I think I can do this way :

Code: Select all

AISign.ClearSign(AISign.BuildSign(AIMap.GetTileIndex(1,1), "LastErrorCleaner"));
Would be fixed in the next version.
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Trans AI :: 09-07-13 ::

Post by Yexo »

Another option is to check the return value so see if there is any error. Every command that can return an error returns true if successful and false if not.
Felix Atagong
Engineer
Engineer
Posts: 45
Joined: 16 Apr 2007 19:50
Location: Louvain
Contact:

Re: Trans AI :: 09-07-13 ::

Post by Felix Atagong »

Hi Fanioz,

You'll see a crash report at http://bugs.openttd.org/task/3078... the game crashes when Trans v90713 kicks in...

*** OpenTTD Crash Report ***
Date: 2009-08-01 21:13:40
Build: 0.7.2-RC1 (0) built on Jul 15 2009 20:57:25
Reason: Assertion failed at ..\src\ai\api\ai_testmode.cpp:24: this->GetDoCommandModeInstance() == this
Language: dutch.lng
Exception C0000005 at 004FBAF6

Probably it is Trans (v90713) that causes this behaviour... this is its last message... (see also screenshot)
Executing Headquarter Builder Task

Hope you can do something with that...
Attachments
crash.png
crash.png (6.24 KiB) Viewed 5083 times
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: Trans AI :: 09-07-13 ::

Post by fanioz »

Felix Atagong wrote:Hi Fanioz,

You'll see a crash report at http://bugs.openttd.org/task/3078... the game crashes when Trans v90713 kicks in...

*** OpenTTD Crash Report ***
Date: 2009-08-01 21:13:40
Build: 0.7.2-RC1 (0) built on Jul 15 2009 20:57:25
Reason: Assertion failed at ..\src\ai\api\ai_testmode.cpp:24: this->GetDoCommandModeInstance() == this
Language: dutch.lng
Exception C0000005 at 004FBAF6

Probably it is Trans (v90713) that causes this behaviour... this is its last message... (see also screenshot)
Executing Headquarter Builder Task

Hope you can do something with that...
Confirmed.
will fix it soon, thanks :)
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: Trans AI :: 09-08-19 ::

Post by fanioz »

Here is new U.S Zip code for Trans :P
* 090819 *

Which is doesn't contain any improvement, only fix the following :

Fix :: Crash on un-managed TestMode
Fix :: Wrong "last_transport" setting
Fix :: Error type while Save/Loading Station manager

I'm sorry for any inconvenience. Hope you enjoying :D
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: Trans AI :: 09-08-19 ::

Post by Lord Aro »

will it still run on 0.7.2?
on content download its vanished!
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
Wold
Transport Coordinator
Transport Coordinator
Posts: 318
Joined: 03 Aug 2006 19:32
Skype: woldy_bg
Location: Bulgaria

Re: Trans AI :: 09-08-19 ::

Post by Wold »

Well eventually the road was finished but it took quite a while to do so
Hardinghall Transport, 30th Mar 1966.png
Hardinghall Transport, 30th Mar 1966.png (122.08 KiB) Viewed 732 times
The other thing - you said you've fixed the bridge problem :)
Unnamed, 30th May 1970.png
Unnamed, 30th May 1970.png (78.01 KiB) Viewed 733 times
Image
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: Trans AI :: 09-08-19 ::

Post by fanioz »

A quick update : :lol:
Lord Aro wrote:will it still run on 0.7.2?
on content download its vanished!
It should working now.
Wold wrote:Well eventually the road was finished but it took quite a while to do so
Hardinghall Transport, 30th Mar 1966.png
The other thing - you said you've fixed the bridge problem :)
Unnamed, 30th May 1970.png
Please confirm if I've fixed it now :D
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: Trans AI :: 09-08-23 ::

Post by Brumi »

Hi Fanioz,
I'm happy about the new release. :)
Let me return to the engine selection problem a bit:
I looked in your code, trying to fix it. I did a little change to Vehicles.SortedEngines:

Code: Select all

static function SortedEngines(engines)
	{
		local heap = FibonacciHeap();
		foreach (idx, val in engines) {
			AIController.Sleep(1);
			local score = 1000000;
			if (AIEngine.IsWagon(idx)) {
				score -= AIEngine.GetCapacity(idx);
				heap.Insert(idx, score);
				continue;
			}
			
			local vtype = AIEngine.GetVehicleType(idx);
			if (vtype == AIVehicle.VT_ROAD) {
				score -=  AIEngine.GetMaxSpeed(idx);
			}
			
			if (vtype == AIVehicle.VT_RAIL) {
				score -= AIEngine.GetPower(idx);
				if (!TransAI.Setting.Get(Const.Settings.realistic_acceleration)) {
						score -= AIEngine.GetMaxTractiveEffort(idx);
				}
			}
			heap.Insert(idx, score);
		}
		return heap;
	}
I put the line 'local score = 1000000;' in the foreach cycle, and it worked. :) Trans was now choosing better train engines with the default set. I don't know if there are other places to fix this problem, please tell me if this fix is right or not.
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: Trans AI :: 09-08-23 ::

Post by fanioz »

Brumi wrote:Hi Fanioz,
I'm happy about the new release. :)
Let me return to the engine selection problem a bit:
I looked in your code, trying to fix it. I did a little change to Vehicles.SortedEngines:

Code: Select all

static function SortedEngines(engines)
@see ..above
I put the line 'local score = 1000000;' in the foreach cycle, and it worked. :) Trans was now choosing better train engines with the default set. I don't know if there are other places to fix this problem, please tell me if this fix is right or not.
Well, if that code is work then yes it is. :D , thanks for take the time to bring back issue and fix it.
And because you have made it, TransAI 090824 is now available both in 2nd post and Bananas.

PS:
The trunk code [WIP] would have an other code to handle 2cc trainset too, and for branch, this would be enough.
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 7 guests