Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Tue Nov 13, 2018 3:41 am

All times are UTC




Post new topic  Reply to topic  [ 34 posts ]  Go to page 1 2 Next
Author Message
 Post subject: TeshiNet, yet another AI
PostPosted: Mon Dec 05, 2011 1:55 am 
Offline
Engineer
Engineer

Joined: Fri Dec 25, 2009 7:56 pm
Posts: 12
Hi everyone,

I'm releasing TeshiNet, an AI that primarily uses road vehicles, and some aircraft.

It will transport most types of cargo, including passengers, and should be broadly compatible with most NewGRF's as long as non-articulated RV's are available that can be refit for the available cargoes.

TeshiNet is written to "play nicely" -- it will not try for more than one passenger subsidy per instance at any given time, and it doesn't tend to spam RV's on any particular route, so traffic jams are not much of an issue.

Current version: v4.0.3, released 2015-04-20

Change log:

v4.0.3
  • Because of the impending closure of Google Code, project is now hosted on GitHub. Links to Google Code revision numbers may stop working when that site closes.
  • Bugfix: crash at load due to requiring old version of SuperLib. Now depends on v38.
  • BaNaNaS update: Added PriorityQueue to the dependencies to prevent crashes.

v4.0.2
  • Bugfix: Although 4.0.1 resolved the reported crash, it regressed a prior bug where the first try at a route (as a new company) would never be built properly, and in some cases many stations would not be built correctly. Re-fixed.

v4.0.1
  • Bugfix: crash at main.nut line 607 due to invalid parameters. Thanks to MAG101 for the bug report.

v4
Version 4 breaks compatibility with older savegames. v4 and up cannot load savegames from v3 and previous.

  • Implemented an event handler to detect crashed vehicles, unprofitable vehicles, and industry closures
  • Now searches periodically for available upgrades to road vehicles, and replaces the outdated vehicles
  • Now detects the location of an RV-hit-by-a-train crash, and replaces the level crossing with a bridge if possible
  • Also detects vehicles with invalid orders, along with vehicles missing orders entirely, and sells them. Thanks to Lowkee33 for the suggestion.
  • Now sets order flags for freight routes to avoid pickup at the destination station.
  • Restrict new passenger routes to towns above 500 population.
  • Removed unprofitable route check, since checking for individually unprofitable vehicles makes it redundant
  • Fixed a minor issue where the first route as a new company would never be built properly.
  • Modified the "enable buses" AI setting so changing it will actually take effect before reloading the game.
  • Removed profitability restriction on adding vehicles to routes, per suggestion from Lowkee33. Also now adds new trucks before buses (in case it runs out of money) as freight cargoes are generally worth more per unit than PAX.

Known issues:
None currently

Planned improvements:
  • Add support for trains
  • Better handling of unprofitable plane routes
  • Convert to API version 1.1
  • Handle freight delivered to towns, such as goods or food
  • Make a setting as to whether to "play nicely", would mostly affect how many subsidies it tries for

TeshiNet is available on BaNaNaS. Please let me know if you have any suggestions for improvement, or run into any bugs! You can also file bugs on the GitHub page for TeshiNet.


Last edited by teshiron on Mon Apr 20, 2015 8:33 pm, edited 10 times in total.

Top
   
PostPosted: Mon Dec 05, 2011 7:57 am 
Offline
Tycoon
Tycoon

Joined: Wed Aug 26, 2009 6:33 am
Posts: 2493
Location: Poland
@Tourists - there is a function in Superlib to handle this ( GetPAXCargo() ). And welcome!

_________________
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD


Top
   
PostPosted: Mon Dec 05, 2011 2:47 pm 
Offline
Engineer
Engineer

Joined: Fri Dec 25, 2009 7:56 pm
Posts: 12
Kogut wrote:
@Tourists - there is a function in Superlib to handle this ( GetPAXCargo() ). And welcome!


Thanks! It's interesting because I'm already using that function to identify the PAX cargo, but it still ends up building tourist buses anyway.


Top
   
PostPosted: Mon Dec 05, 2011 3:45 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Wed Nov 07, 2007 10:44 pm
Posts: 9049
Location: Sol d
teshiron wrote:
Kogut wrote:
@Tourists - there is a function in Superlib to handle this ( GetPAXCargo() ). And welcome!


Thanks! It's interesting because I'm already using that function to identify the PAX cargo, but it still ends up building tourist buses anyway.

Both, tourists and 'normal' passenger are a PAX cargo. You might need to refit your bus to normal passengers and / or check the actual cargo label. but maybe there's a more elegant or an existing solution

_________________
Image
OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone | NewGRF web translator
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML


Top
   
PostPosted: Mon Dec 05, 2011 4:53 pm 
Offline
Engineer
Engineer

Joined: Fri Dec 25, 2009 7:56 pm
Posts: 12
planetmaker wrote:
Both, tourists and 'normal' passenger are a PAX cargo. You might need to refit your bus to normal passengers and / or check the actual cargo label. but maybe there's a more elegant or an existing solution


The function in SuperLib tries to distinguish PASS from TOUR, and it actually does so correctly most of the time. My problem was that I had decided to save the identified pax cargoID, and I was testing using a savegame where I had previously saved the wrong cargoID -- causing it to overwrite the correct pax cargo identification when Load() was called. D'oh.


Top
   
PostPosted: Mon Dec 05, 2011 7:04 pm 
Offline
Chairman
Chairman

Joined: Sat Jul 18, 2009 5:54 pm
Posts: 886
I decided to give your AI a test run.
It built 2-3 routes, then a few years later, it sold its stations, leaving the vehicles behind. After restarting the AI, it repeated this 3 times.

EDIT: Corrected ugly grammar mistake


Last edited by Brumi on Mon Dec 05, 2011 10:46 pm, edited 1 time in total.

Top
   
PostPosted: Mon Dec 05, 2011 9:53 pm 
Offline
Engineer
Engineer

Joined: Fri Dec 25, 2009 7:56 pm
Posts: 12
Brumi wrote:
I decided to give your AI a test run.
It built 2-3 routes, then a few years later, it sold its stations, leaving the vehicles behind. After I restarting the AI, it repeated this 3 times.


That's odd. It's most likely related to one or more settings or NewGRFs you are using, because I didn't encounter anything like that in my testing. The behavior you describe would seem to be the AI trying to kill the route because it's unprofitable, and the vehicles are not getting the message to go to the depot. But why the route wouldn't work in the first place, and why it wouldn't clean up the route properly, is beyond me.

Can you provide a savegame or a list of the NewGRFs you used? That would be very helpful.


Top
   
PostPosted: Mon Dec 05, 2011 10:49 pm 
Offline
Chairman
Chairman

Joined: Sat Jul 18, 2009 5:54 pm
Posts: 886
Well, most probably it's my settings that cause the trouble. I used the Generic Tram Set and the Temperate Oil Wells Only Decrease Neutraliser when I tested your AI, these shouldn't make a difference. Now I tested it without any NewGRFs, and I still saw the strange behaviour.

So here is an openttd.cfg, the bug can be reproduced with these settings.


Attachments:
openttd.cfg [9.99 KiB]
Downloaded 100 times
Top
   
PostPosted: Wed Dec 07, 2011 7:51 am 
Offline
Engineer
Engineer

Joined: Fri Dec 25, 2009 7:56 pm
Posts: 12
Brumi wrote:
Well, most probably it's my settings that cause the trouble. I used the Generic Tram Set and the Temperate Oil Wells Only Decrease Neutraliser when I tested your AI, these shouldn't make a difference. Now I tested it without any NewGRFs, and I still saw the strange behaviour.

So here is an openttd.cfg, the bug can be reproduced with these settings.


That was very helpful. I forget sometimes that not everyone plays with the same settings I do!

With high construction costs, low number of towns, mountainous terrain, and the slow vehicles available at that date (1950), it was just very difficult for the initial routes to turn a profit. I'd set it to start removing routes too early, and not wait long enough for the vehicles to get to the depot when removing a route.

I've made several changes to its early game behavior in order to make it more viable, including; get a larger initial loan, build shorter routes when only slow vehicles are available, do not remove routes unless it already already has 10 routes going, only build 3 vehicles for each route instead of 5, etc. I also have it waiting 4x as long for vehicles to get to the depot when a route is removed. These changes will all be in version 3 which I hope to release this week sometime.

Thanks for your feedback!


Top
   
PostPosted: Thu Dec 08, 2011 4:36 am 
Offline
Engineer
Engineer

Joined: Fri Dec 25, 2009 7:56 pm
Posts: 12
TeshiNet v3 has been released; see the top post in this topic to download.

Note: I made a typo in one function call that I didn't catch until after I uploaded to BaNaNas, and 3 unfortunate souls downloaded the buggy version. If you were one of them, sorry! Update from BaNaNaS to get the replacement version of v3.


Last edited by teshiron on Thu Dec 08, 2011 5:30 am, edited 1 time in total.

Top
   
PostPosted: Thu Dec 08, 2011 4:44 am 
Offline
Tycoon
Tycoon

Joined: Wed Aug 26, 2009 6:33 am
Posts: 2493
Location: Poland
You can also bump version of fixed AI, this way they will update it in the automatic way.

_________________
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD


Top
   
PostPosted: Thu Dec 08, 2011 5:25 am 
Offline
Engineer
Engineer

Joined: Fri Dec 25, 2009 7:56 pm
Posts: 12
Kogut wrote:
You can also bump version of fixed AI, this way they will update it in the automatic way.


That's true, I forgot you can use decimal versions on BaNaNaS.


Top
   
PostPosted: Sun Dec 11, 2011 12:46 am 
Offline
Engineer
Engineer

Joined: Fri Nov 25, 2011 8:49 pm
Posts: 20
Hi teshiron. I've been playing with your AI recently. One thing that would make this better was if the amount of buses/trucks the AI was variable, rather than just three. I think I have seen it buy more as time goes by, but there is a lot of missed profit.

I've also occasionally seen buses/trucks with "Invalid Order" as their first order. I see by the log that you are checking for vehicles with "No Orders", but I don't know if those two things are exclusive. I think it happens when you delete the stations before all of the vehicles are sold.

Anyway, a very nice AI so far. Haven't seen any glaring bugs, or any crashes. Sometimes it has trouble getting started, but I think that would be solved by it buying more vehicles rather than look for new routes.


Top
   
PostPosted: Sun Dec 11, 2011 1:26 am 
Offline
Engineer
Engineer

Joined: Fri Dec 25, 2009 7:56 pm
Posts: 12
@Lowkee33: Thanks for the feedback.!

I'm planning to check for "Invalid Order" as well as --No Orders-- in the next version; not really sure why I didn't in the first place! :)

As for route capacity, I had originally planned (when I started writing this off-and-on over a year ago) that I could manage capacity well enough by starting with 5 vehicles per route regardless, and then buying more vehicles, one at a time, whenever there was more than 200 units of cargo waiting at a periodic check.

That seems to work fairly well in later game years or on easier difficulty settings, but 5 to start often seemed to be overkill on shorter routes or for smaller towns. This was especially noticeable using the settings file Brumi provided. So, I cut it back to 3 vehicles when starting the route, and also restricted it from buying vehicles to supplement the route unless the vehicle could pay for itself within 3 years (i.e. only purchase if average profit per vehicle for the route * 3 > vehicle price).

What I really need to do is find a way to calculate capacity and buy vehicles accordingly, but I haven't figured a good way to do it (and I'm stubborn -- I want to figure it out myself and not shamelessly stealborrow a method from another AI :lol: )

Until then, I might make the number of vehicles a configurable setting in v4, and I welcome suggestions for other ways to tackle the problem.


Top
   
PostPosted: Sun Dec 11, 2011 2:47 am 
Offline
Engineer
Engineer

Joined: Fri Nov 25, 2011 8:49 pm
Posts: 20
teshiron wrote:
(and I'm stubborn -- I want to figure it out myself and not shamelessly stealborrow a method from another AI :lol: )

Until then, I might make the number of vehicles a configurable setting in v4, and I welcome suggestions for other ways to tackle the problem.


So what do you want? :)

I am working on an AI as well. I use station ratings to figure out if another vehicle is needed. I'm going to have to rant a little, figuring this out was a little tricky.

A main difference between your AI and mine is that my buses have a full load in their first order. This means that bus and truck orders are very similar, I have the same function create them (the only difference is the given cargo ID). Full Load at station 1, regular stop at Station 2, then go to the depot if needed.

The tricky part is that Get Station Ratings requires a cargo ID. It is tough to tackle from the station side of things, because how do we know that there is only one cargo/industry within the range of the station. My solution is with the depots, every route has its own. This means:
Code:
local depotList = AIDepotList(AITile.TRANSPORT_ROAD);
foreach (depot, index in depotList){
  Sleep(1);
  local vehicleList = AIVehicleList_Depot(depot);      
  local vehicle = vehicleList.Begin();
  local stationPos = AIOrder.GetOrderDestination (vehicle, 0);
  local station = AIStation.GetStationID(stationPos);
  local engine = AIVehicle.GetEngineType(vehicle);
  local cargo = AIEngine.GetCargoType(engine);
 
  if (AIStation.GetCargoRating (station, cargo) < 63) {
    takeLoan();
    local newVehicle = AIVehicle.CloneVehicle(AIOrder.GetOrderDestination (vehicle, 2), vehicle, false);  // OrderDestination 2 is the Depot
    AIVehicle.StartStopVehicle (newVehicle);
    repayLoan();
  }
}


Every route has its main station kept at very-good ratings. I have issues with over-building. Right now this is controlled by a Sleep(2500) between every call to this function. That is pretty much my whole while (true) loop. Every few years check for a new route, otherwise just maintain ratings.


Top
   
PostPosted: Tue Dec 13, 2011 4:04 am 
Offline
Engineer
Engineer

Joined: Fri Dec 25, 2009 7:56 pm
Posts: 12
@Lowkee33: The problem I can foresee when trying to use ratings is that, with slow vehicles and somewhat long-ish routes, the number of vehicles to keep the rating high will be more than is necessary for the cargo to transport -- i.e. they will not run enough cargo each to turn a profit.

What I meant by determining capacity is how some AI's seem to have a way of determining how many vehicles they should buy, in advance -- I see log messages like "Need capacity of 500, at 49, buying 10 buses" or whatever. Absent a system to do that, I think buying more vehicles when there's excessive waiting cargo, and selling vehicles when they have an unprofitable year, works well enough. Try v4 and let me know what you think.


Top
   
PostPosted: Tue Dec 13, 2011 4:06 am 
Offline
Engineer
Engineer

Joined: Fri Dec 25, 2009 7:56 pm
Posts: 12
TeshiNet v4 released!

Change log:
Version 4 breaks compatibility with older savegames. v4 and up cannot load savegames from v3 and previous.

  • Implemented an event handler to detect crashed vehicles, unprofitable vehicles, and industry closures
  • Now searches periodically for available upgrades to road vehicles, and replaces the outdated vehicles
  • Now detects the location of an RV-hit-by-a-train crash, and replaces the level crossing with a bridge if possible
  • Also detects vehicles with invalid orders, along with vehicles missing orders entirely, and sells them. Thanks to Lowkee33 for the suggestion.
  • Now sets order flags for freight routes to avoid pickup at the destination station.
  • Restrict new passenger routes to towns above 500 population.
  • Removed unprofitable route check, since checking for individually unprofitable vehicles makes it redundant
  • Fixed a minor issue where the first route as a new company would never be built properly.
  • Modified the "enable buses" AI setting so changing it will actually take effect before reloading the game.
  • Removed profitability restriction on adding vehicles to routes, per suggestion from Lowkee33. Also now adds new trucks before buses (in case it runs out of money) as freight cargoes are generally worth more per unit than PAX.

Please see the first message for download, or download from BaNaNas, and as always, you can post here or open an issue on the Google Code site if you encounter any bugs or have suggestions.


Top
   
PostPosted: Wed Dec 14, 2011 4:12 pm 
Offline
Engineer
Engineer

Joined: Wed Dec 14, 2011 12:55 am
Posts: 28
Your AI crashed about 2 days after its loaded

There a Screenshot (savegame too large to uploaded)


Attachments:
Felső-Balatonladányháza Transport, 13th Dec 1946.png [118.68 KiB]
Downloaded 3 times


Last edited by MAG101 on Wed Dec 14, 2011 4:26 pm, edited 4 times in total.
Top
   
PostPosted: Wed Dec 14, 2011 4:14 pm 
Offline
Tycoon
Tycoon

Joined: Thu Dec 20, 2007 12:49 pm
Posts: 3653
MAG101 wrote:
There a Save and Screenshot
Great, could you also upload those :)


Top
   
PostPosted: Thu Dec 15, 2011 3:40 pm 
Offline
Engineer
Engineer

Joined: Fri Dec 25, 2009 7:56 pm
Posts: 12
MAG101 wrote:
Your AI crashed about 2 days after its loaded

There a Screenshot (savegame too large to uploaded)


Oops! I thought I had fixed that error, but I apparently didn't catch it everywhere. Thank you for your bug report, version 4.0.1 has been released to fix this bug. You can download it here or from BaNaNaS.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 34 posts ]  Go to page 1 2 Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000-2018 phpBB Limited

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2018.
Hosted by Zernebok Hosting.