TracAI

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
dadloo
Engineer
Engineer
Posts: 2
Joined: 27 May 2015 12:10

TracAI

Post by dadloo »

Hi, I started playing this game recently and got really hooked up in it. So I decided to try write new AI (also I needed a topic for my bachelor thesis :) ). This is my first attempt to create AI. I would really appreciated posting bugs here if someone finds any.

Implemented:
- trains (town-to-town and industry-to-industry routes)
- reusing accepting industries stations
- aircrafts (passengers and mail only) note: this is modified version of WormAI
- choosing ai speed (difficulty)
- save/load function
- demolishing unfinished or unused routes

Known issues:
- signaling is not perfect (sometimes creates deadlock)
- sometimes after a while it stops buying new vehicles (buying does not suceed for unknown reasons)

This AI does not have NewGRF support (meaning only that it has not been tested) so if anyone tries it with NewGRF please post here if there were any issues or not.
Brumi
President
President
Posts: 921
Joined: 18 Jul 2009 17:54

Re: TracAI

Post by Brumi »

I'm trying it right now.
The AI is remarkably stable for a first release so far, still going strong after 20 years. The only problem is that it only has 12 trains and 7 aircraft currently (I've seen more aircraft before, one of them probably crashed). The terrain is mountainous, maybe the pathfinder is having quite a hard time.

I am amazed to see that the AI already does some railway networking, good job on that :) And I'm especially happy that we have another multi-profile AI (trains and aircraft, passengers and freight) :)

There are two problems I see so far:
  • You mentioned that the signalling is not perfect. I fail to see how this possibly deadlocks (apart from overloading the network with so many trains that there is no space anymore), but the main problem is that you're mixing path signals with block signals. So either use path signals only (simply delete those exit signals at the platforms and use path signals everywhere else) or block signals only (change all your current path signals to simple block signals).
  • It's really nice to see that it removes unused routes, but some sections are not cleared properly.
    TracAI tracs.png
    TracAI tracs.png (134.79 KiB) Viewed 9202 times
And as I was writing this post, the AI crashed :(
TracAI crash.png
TracAI crash.png (29.37 KiB) Viewed 1974 times
Anyway, it's nice to see a new AI using trains, best of luck for your thesis :)
dadloo
Engineer
Engineer
Posts: 2
Joined: 27 May 2015 12:10

Re: TracAI

Post by dadloo »

Thanks for the quick reply, did not expect that :). Also thanks for the signal tip. I am quite new to the OpenTTD and signals are still quite confusing to me.

I have to admit that my AI doesn't build many routes, therefore does not have many trains (in contrast to other AIs).

I will definitely look at the demolishing (why it does not demolishes station tracks). I am quite suprised that it did not come up when i tested it (I had to be thorough because ot the thesis), though it will be probably after my finals.

For the signal deadlock, it happens rarely (that is why it is not fixed yet). Sometimes pathfinder uses part of route even from opposite direction (meaning it uses route between two signals). This causes that signal is one tile after a 'exit' junction and if trains stops at that signal it can block both ways. It needs to have certain amount of trains (but not many that you could call it jam).

I have a question about your crash report (btw. thanks for that). How big was your map when the AI crashed? It will help me understand the problem.
Brumi
President
President
Posts: 921
Joined: 18 Jul 2009 17:54

Re: TracAI

Post by Brumi »

According to the logs, it seems that TracAI was still alive at the time of my last autosave, at least it says something about loading the save state when I load up the savegame. It's a 512x512 map, see it attached az autosave0.sav.

But I found something that may be more interesting to you: the AI crashes instantly upon loading one of my autosaves, I attached that one as well as autosave8.sav.
Attachments
autosave0.sav
(564.64 KiB) Downloaded 333 times
autosave8.sav
(541.54 KiB) Downloaded 292 times
autosave8 crash.png
autosave8 crash.png (30.29 KiB) Viewed 1970 times
Wormnest
Engineer
Engineer
Posts: 117
Joined: 14 Jul 2013 12:33
Location: Netherlands

Re: TracAI

Post by Wormnest »

Nice to see that you found my WormAI useful enough to reuse especially since I still lack time and motivation to work on it myself.
I haven't looked at your AI yet but good luck!
User avatar
Core Xii
Traffic Manager
Traffic Manager
Posts: 228
Joined: 08 Apr 2008 09:47
Location: Finland

Re: TracAI

Post by Core Xii »

In a very vanilla game from 1950 to 2050 against AdmiralAI and some other AIs that crashed at some point or another, TracAI won by a decent margin.

Some observations about its behavior:

It pathfinds both ways between two stations separately. This seems wasteful in terms of planning time, as a bi-directional route is very likely to be optimal for the two tracks to run alongside one another.

It begins pathfinding from the destination to the source, and will not populate the tracks with trains until both directions have been pathfound. It could build the source-destination track first and put a train on it, while pathfinding the other direction, to make a bit more money.

It builds depots at the exit of the destination station, and buys trains there. That means that those trains have to make half the trip empty, pointlessly. It should rather build a depot and buy trains at the entrance to the source, so they can start loading faster.
Wormnest
Engineer
Engineer
Posts: 117
Joined: 14 Jul 2013 12:33
Location: Netherlands

Re: TracAI

Post by Wormnest »

TracAI crashed after being in second place for a long time.
Attachments
Unnamed, 1987-10-25.png
(732.05 KiB) Not downloaded yet
xarick
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 26 Feb 2015 00:52

Re: TracAI

Post by xarick »

Survived 100 years without crashing for me, though. Tested it as solo since 1950-2051

I noticed a train jam and a few abandoned tracks laying around.
Attachments
TracAI, 1st Jan 2051.sav
(454.29 KiB) Downloaded 277 times
TracAI #2, 2051-02-09.png
TracAI #2, 2051-02-09.png (149.74 KiB) Viewed 7721 times
openttdCore2.cfg
(10.75 KiB) Downloaded 292 times
Formerly known as Samu
xarick
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 26 Feb 2015 00:52

Re: TracAI

Post by xarick »

TracAI v1 OpenTTD 1.6.1-RC1

I took TracAI for a train competition 100 year solo test, starting from 1950. He actually started really strong, beating the other competitors for a short period of time, but he started to fall as soon as he got to manage train jams. It creates way so many trains that they can't physically fit on the entire connection start to finish. It got to a point where his profits actually started to diminish. It's been a constant struggle ever since. The script however, died by 2015.

Here's part of the log.
dbg: [script] [0] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] Selling not suceeded ERR_VEHICLE_NOT_IN_DEPOT
dbg: [script] [0] [I] 2015-03-08 --- Urgent Tasks Done ---
dbg: [script] [0] [W] Building new industry rail route
dbg: [script] [0] [I] Finding industry pair...
dbg: [script] [0] [I] Suitable pair found
dbg: [script] [0] [I] IndustryPair - Industry PRO: Nedinghead Coal Mine Industry ACC: Fort Padham Power Station Cargo: COAL Distance: 114 Value: 268800000
dbg: [script] [0] [I] ipro tilelist not found
dbg: [script] [0] [I] Finding industry pair...
dbg: [script] [0] [I] Suitable pair found
dbg: [script] [0] [I] IndustryPair - Industry PRO: Shorningstone Coal Mine Industry ACC: Senfingburg Power Station Cargo: COAL Distance: 84 Value: 268800000
dbg: [script] [0] [I] iacc tilelist not found
dbg: [script] [0] [I] Finding industry pair...
dbg: [script] [0] [I] Suitable pair found
dbg: [script] [0] [I] IndustryPair - Industry PRO: Shorningstone Coal Mine Industry ACC: Fenfingley Power Station Cargo: COAL Distance: 154 Value: 268800000
dbg: [script] [0] [I] iacc tilelist not found
dbg: [script] [0] [I] Finding industry pair...
dbg: [script] [0] [I] Suitable pair found
dbg: [script] [0] [I] IndustryPair - Industry PRO: Shorningstone Coal Mine Industry ACC: Wradingbury Power Station Cargo: COAL Distance: 160 Value: 268800000
dbg: [script] [0] [W] pro station not build
dbg: [script] [0] [I] 2015-03-09 Managing rail routes
dbg: [script] [0] [I] Removing route 54
dbg: [script] [0] [I] Removing route 153
dbg: [script] [0] [I] Removing route 1440
dbg: [script] [0] [I] Removing route 1481
dbg: [script] [0] [I] Removing route 1876
dbg: [script] [0] [I] Removing route 2049
dbg: [script] [0] [I] Removing route 2280
dbg: [script] [0] [I] Saving TracAI game data. Used ops: 38717
dbg: [script] [0] [I] Removing route 2653
dbg: [script] [0] [I] Removing route 3624
dbg: [script] [0] Your script made an error: parameter 1 has an invalid type 'null' ; expected: 'integer'
dbg: [script] [0]
dbg: [script] [0] *FUNCTION [RemoveRoute()] tracai-1.0\rail_manager.nut line [856]
dbg: [script] [0] *FUNCTION [ManageRailRoutes()] tracai-1.0\rail_manager.nut line [912]
dbg: [script] [0] *FUNCTION [Start()] tracai-1.0\main.nut line [295]
dbg: [script] [0]
dbg: [script] [0] [is_depot_acc_used_by_more_routes] false
dbg: [script] [0] [is_depot_pro_used_by_more_routes] false
dbg: [script] [0] [is_station_acc_used_by_more_routes] false
dbg: [script] [0] [route_idx] 146
dbg: [script] [0] [S] [route] INSTANCE
dbg: [script] [0] [S] [route_id] 3624
dbg: [script] [0] [S] [this] INSTANCE
dbg: [script] [0] [S] [i] 146
dbg: [script] [0] [S] [routes_len] 155
dbg: [script] [0] [S] [this] INSTANCE
dbg: [script] [0] [S] [build_air_delay_factor] 1
dbg: [script] [0] [S] [build_rail_delay_factor] 1
dbg: [script] [0] [S] [sleepingtime] 100
dbg: [script] [0] [S] [this] INSTANCE
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
TracAI, 1st Apr 2015.sav
(3.6 MiB) Downloaded 287 times
TracAI, 1st May 2015.sav
(3.08 MiB) Downloaded 277 times
openttdCore4.cfg
(11.23 KiB) Downloaded 279 times
Formerly known as Samu
xarick
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 26 Feb 2015 00:52

Re: TracAI

Post by xarick »

excessive cpu usage in valuator function
dbg: [script] [0] (start: 2107-02-02; stop: 2121-10-01)
dbg: [script] [0] [W] path_pro_acc not found
dbg: [script] [0] Saving TracAI game data. Used ops: 2754
dbg: [script] [0] [W] ticker: 1700
dbg: [script] [0] [W] Building new town rail route
dbg: [script] [0] Saving TracAI game data. Used ops: 2754
dbg: [script] [0] Saving TracAI game data. Used ops: 2754
dbg: [script] [0] Saving TracAI game data. Used ops: 2754
dbg: [script] [0] Saving TracAI game data. Used ops: 2754
dbg: [script] [0] Your script made an error: excessive CPU usage in valuator function
dbg: [script] [0]
dbg: [script] [0] *FUNCTION [IsTileRectagleFlatAndBuildable()] tracai-1.0\util.nut line [93]
dbg: [script] [0] *FUNCTION [Valuate()] tracai-1.0\valuators.nut line [60]
dbg: [script] [0] *FUNCTION [Valuate()] NATIVE line [-1]
dbg: [script] [0] *FUNCTION [GetTownStationSpotList()] tracai-1.0\rail_builder.nut line [770]
dbg: [script] [0] *FUNCTION [CreateNewTownRoute()] tracai-1.0\rail_manager.nut line [191]
dbg: [script] [0] *FUNCTION [Start()] tracai-1.0\main.nut line [282]
dbg: [script] [0]
dbg: [script] [0]
  • INSTANCE
    dbg: [script] [0] [S] [tile_to] 135409
    dbg: [script] [0] [S] [tile_from] 130800
    dbg: [script] [0] [S] [this] INSTANCE
    dbg: [script] [0] [S] [north_nw_se] false
    dbg: [script] [0] [S] [north_ne_sw] false
    dbg: [script] [0] [S] [self] INSTANCE
    dbg: [script] [0] [S] [tile] 130800
    dbg: [script] [0] [S] [this] INSTANCE
    dbg: [script] [0] [S] [valuator] INSTANCE
    dbg: [script] [0] [S] [other_town_direction] 8
    dbg: [script] [0] [S] [town_tile] 125164
    dbg: [script] [0] [S] [town_tilelist] INSTANCE
    dbg: [script] [0] [S] [radius] 4
    dbg: [script] [0] [S] [number_of_tracks] 2
    dbg: [script] [0] [S] [platform_length] 5
    dbg: [script] [0] [S] [other_town] 12
    dbg: [script] [0] [S] [town] 158
    dbg: [script] [0] [S] [this] INSTANCE
    dbg: [script] [0] [S] 1
    dbg: [script] [0] [S] [town_pair_array] ARRAY
    dbg: [script] [0] [S] [railtype] 3
    dbg: [script] [0] [S] [cost] NULL
    dbg: [script] [0] [S] [money_reservationID] NULL
    dbg: [script] [0] [S] [station_acc] NULL
    dbg: [script] [0] [S] [station_pro] NULL
    dbg: [script] [0] [S] [town2_tilelist] INSTANCE
    dbg: [script] [0] [S] [town1_tilelist] INSTANCE
    dbg: [script] [0] [S] [best_town_pair] NULL
    dbg: [script] [0] [S] [this] INSTANCE
    dbg: [script] [0] [S] [build_air_delay_factor] 1
    dbg: [script] [0] [S] [build_rail_delay_factor] 1
    dbg: [script] [0] [S] [sleepingtime] 100
    dbg: [script] [0] [S] [this] INSTANCE
    dbg: [script] [0] [S] Your script made an error: excessive CPU usage in valuator function
    dbg: [script] [0] [S]
    dbg: [script] [0] [S] *FUNCTION [GetTownStationSpotList()] tracai-1.0\rail_builder.nut line [770]
    dbg: [script] [0] [S] *FUNCTION [CreateNewTownRoute()] tracai-1.0\rail_manager.nut line [191]
    dbg: [script] [0] [S] *FUNCTION [Start()] tracai-1.0\main.nut line [282]
    dbg: [script] [0] [S]
    dbg: [script] [0] [S] [valuator] INSTANCE
    dbg: [script] [0] [S] [other_town_direction] 8
    dbg: [script] [0] [S] [town_tile] 125164
    dbg: [script] [0] [S] [town_tilelist] INSTANCE
    dbg: [script] [0] [S] [radius] 4
    dbg: [script] [0] [S] [number_of_tracks] 2
    dbg: [script] [0] [S] [platform_length] 5
    dbg: [script] [0] [S] [other_town] 12
    dbg: [script] [0] [S] [town] 158
    dbg: [script] [0] [S] [this] INSTANCE
    dbg: [script] [0] [S] 1
    dbg: [script] [0] [S] [town_pair_array] ARRAY
    dbg: [script] [0] [S] [railtype] 3
    dbg: [script] [0] [S] [cost] NULL
    dbg: [script] [0] [S] [money_reservationID] NULL
    dbg: [script] [0] [S] [station_acc] NULL
    dbg: [script] [0] [S] [station_pro] NULL
    dbg: [script] [0] [S] [town2_tilelist] INSTANCE
    dbg: [script] [0] [S] [town1_tilelist] INSTANCE
    dbg: [script] [0] [S] [best_town_pair] NULL
    dbg: [script] [0] [S] [this] INSTANCE
    dbg: [script] [0] [S] [build_air_delay_factor] 1
    dbg: [script] [0] [S] [build_rail_delay_factor] 1
    dbg: [script] [0] [S] [sleepingtime] 100
    dbg: [script] [0] [S] [this] INSTANCE
    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
Formerly known as Samu
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 2 guests