Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Sun Dec 16, 2018 12:17 am

All times are UTC




Post new topic  Reply to topic  [ 68 posts ]  Go to page 1 2 3 4 Next
Author Message
 Post subject: BorkAI
PostPosted: Mon Aug 29, 2011 1:26 am 
Offline
Engineer
Engineer

Joined: Tue Aug 16, 2011 1:26 am
Posts: 37
Greetings,

I've written a simple AI for openttd, called BorkAI.
It's a truck-only AI that creates routes between industries and to towns (but not passengers or mail).

As the proud product of a couple of weeks of trying to learn the NoAI frameworks, it sports
the following features (yes, features, not bugs :D)

* slow-as-hell pathfinder. Abusing the RoadPathfinder isn't the best option, and it shows on big maps,
when it can get literally stuck. It's still fine on small ones though.
* approximate estimation of number of trucks needed. Expecially when competing with others, or transporting hundreds of
goods from factories. Prepare for a few traffic jams :P.
* Bad NewGRF support. Shouldn't crash, but because of some assumptions won't work very well in a non
default setting.


Well it has a few *nice* features also :P

* Does most of the things needed to survive: renewing trucks when they get old, upgrading to faster ones, handling of economy changes (industries appearing/disappearing).
* It's eco-friendly. Try not to build unneeded roads. Actually this is a tunable so you can force it to build the absolute minimum of road required to get from one
place to the other. Nice when playing against it. Or you can let it build as much road as needed to the shortest route available.
* In fact, on the small maps, it's more or less competitive with the other AIs. It won't die easily.



Any feedback is welcome, expecially from someone playing against it (I don't like to play against an AI), or using any kind of customization.


Top
   
 Post subject: Re: BorkAI
PostPosted: Mon Aug 29, 2011 11:39 am 
Offline
Chairman
Chairman

Joined: Sat Jul 18, 2009 5:54 pm
Posts: 888
I've been testing your AI for a while, no bugs or crashes so far :)
I didn't actually play against your AI, but from a player's point of view, I think it would be good not to transport only the "best" cargo. Anyway, on sub-arctic and sub-tropical climates, gold/diamonds are not always the best choice, as production is substantially low.


Top
   
 Post subject: Re: BorkAI
PostPosted: Mon Aug 29, 2011 12:31 pm 
Offline
Engineer
Engineer

Joined: Tue Aug 16, 2011 1:26 am
Posts: 37
Thanks for your suggestions :).

You're right, at the moment the transport selection algorithm is quite naive,
but my first priority was to obtain a "complete" bot, at the cost of a simple behaviour.

Beside improvements to the algorithm itself (like taking into account the amount of goods produced), I plan to
add some randomness to the behaviour of the AI, and make it tunable, so that one can decide
between a varied AI and a tougher (iif boring) one, to play against other AIs for example.


Top
   
 Post subject: Re: BorkAI
PostPosted: Sat Oct 01, 2011 12:37 am 
Offline
Engineer
Engineer

Joined: Tue Aug 16, 2011 1:26 am
Posts: 37
I uploaded a new version.
The new one has much better performance, making it usable also on medium-sized maps (eg. 512x512).
I also fixed a number of bugs, mostly related to the construction of road/stations/depots, and how orders
are handled.
Also, this version shouldn't crash any more when used with some particulare NewGRFs.
I also added some support for mail and passenger transport. If far from perfect, as it won't work very well
in scenarios like sub-tropical. For this reason is disabled by default but can be enable with a setting.
Other two settings available are mostly for when you play against it.
One sets how much the AI will try to re-use existing roads, while the other adds some randomness to the
decisions of the AI (at the moment, it only affects which goods will be transported). This should allow for
a more pleasing game.
In the end the AI should also perform better against other AIs.
As always, some feedback is very welcome.


Top
   
 Post subject: Re: BorkAI
PostPosted: Sat Oct 01, 2011 6:49 am 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4538
Location: /home/sweden
The setting to enable/disable buses and mail could be made a tri-state setting.
  • Off
  • Climate dependent
  • On

If Climate dependent is selected, you only use mail trucks and buses if the climate is temperate. Via AIGameSettings you can access virtually any setting that exist in openttd.conf. The easiest way to figure out their names is to open openttd.conf and search for string that you think the setting name would contain. Or browse it from top to bottom until you find something likely. Another option is of course to make two openttd.conf files with only a change to the ladscape that differs and then diff the files.

_________________
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)


Top
   
 Post subject: Re: BorkAI
PostPosted: Tue Nov 08, 2011 11:08 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4538
Location: /home/sweden
An issue that seem to relate to your AI has been found. See this thread: viewtopic.php?f=31&t=57296

It is caused by sorting an array with 50000 elements. I have read through your code briefly but haven't been able to see why any of the arrays that you sort would be that large.

_________________
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)


Top
   
 Post subject: Re: BorkAI
PostPosted: Tue Nov 08, 2011 11:22 pm 
Offline
Tycoon
Tycoon

Joined: Thu Dec 20, 2007 12:49 pm
Posts: 3653
I suspect main.nut:871. If I read your code correctly you create a list containing every possible route, which means that list can be quite long. Since array.sort() cannot currenctly be suspended while it's running, it must run to completion. Not only does it take quite some time to sort an array containing 50000 elements using squirrels qsort implementation, it even runs out of stack causing OpenTTD to crash.

I'm considering to reimplement the sort() function in squirrel instead of in C++. While this would make your code work again, it'd also cause a big slowdown. I'd advise you against using such big arrays completely.


Top
   
 Post subject: Re: BorkAI
PostPosted: Thu Nov 10, 2011 7:42 pm 
Offline
Tycoon
Tycoon

Joined: Thu Dec 20, 2007 12:49 pm
Posts: 3653
Ok. I couldn't find a way to implement sort() in squirrel (at least not as correct replacement for the current C++ version. After a suggestion from Rubidium I replaced the custom qsort function in squirrel by the C++ std::sort and now it works properly. This means you're AI still works.

I've tried to run your AI on a few very big maps, and every time it takes a very long time before it does anything at all. After 2 years in-game time I've just stopped the game when your AI still didn't build anything at all.


Top
   
 Post subject: Re: BorkAI
PostPosted: Sat Nov 12, 2011 3:34 pm 
Offline
Engineer
Engineer

Joined: Tue Aug 16, 2011 1:26 am
Posts: 37
Hi, thanks for the feedback, and sorry for the delay in answering (I had notifications disabled).
I'll address this issue and post an update as soon as possible.
In any case at the moment the AI is of little use on big maps for that reason and for many others.
With time I'll fix them too.


Top
   
 Post subject: Re: BorkAI
PostPosted: Mon Nov 14, 2011 1:55 am 
Offline
Engineer
Engineer

Joined: Tue Aug 16, 2011 1:26 am
Posts: 37
I uploaded a new version that addresses the problem at hand.
Beside that, it provides much better performance on big and high density maps.
It still far from optimal, but the AI should do something interesting now.
I have a few more changes in mind that will solve the problem, but first I'll
try to fix the performance of the planner (it take ages to build a route,
even on short distances).


Top
   
 Post subject: Re: BorkAI
PostPosted: Mon Oct 29, 2012 1:40 pm 
Offline
Tycoon
Tycoon

Joined: Wed Aug 26, 2009 6:33 am
Posts: 2493
Location: Poland
crashy crash


Attachments:
crash.PNG
crash.PNG [ 7.57 KiB | Viewed 12992 times ]

_________________
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Top
   
 Post subject: Re: BorkAI
PostPosted: Tue Dec 04, 2012 10:33 pm 
Offline
Engineer
Engineer

Joined: Tue Aug 16, 2011 1:26 am
Posts: 37
Hi Kugut,

The errore is quite puzzling, as it seems that a file is missing,
and the archive hasn't changed for the last few months...

Anyway If I remember correctly the referenced file contained only unused code
so it should be easy to fix (lucklily, because I can no longer find my repo on bitbucket... wtf :shock: )

Hopefully

Thanks for reporting the error.


Top
   
 Post subject: Re: BorkAI
PostPosted: Wed Dec 05, 2012 12:06 am 
Offline
Transport Coordinator
Transport Coordinator

Joined: Wed Dec 29, 2010 7:36 pm
Posts: 336
Have a look at http://dev.openttdcoop.org/
Never failed me, and as you will see, many openttd projects :)


Top
   
 Post subject: Re: BorkAI
PostPosted: Mon Dec 17, 2012 2:12 pm 
Offline
Engineer
Engineer

Joined: Tue Feb 23, 2010 3:44 pm
Posts: 103
Hi,
I tried to play with your AI today and it builds some nice routes and makes good profit.
Then it had a little bit bad luck and a train crashed into a vehicle and it seems that it doesn't like that and crashed too.

I replaced the loop which doesn't work with

foreach(route in this.routes){

but it does only have a few routes stored, it seems. So I don't have a clue what to do exactly to fix this.

Here's the AI Debug window:

Attachment:
bork1.png [18.97 KiB]
Downloaded 10 times


Top
   
 Post subject: Re: BorkAI
PostPosted: Tue Dec 18, 2012 10:42 pm 
Offline
Engineer
Engineer

Joined: Tue Aug 16, 2011 1:26 am
Posts: 37
Steffl wrote:
Hi,
I tried to play with your AI today and it builds some nice routes and makes good profit.
Then it had a little bit bad luck and a train crashed into a vehicle and it seems that it doesn't like that and crashed too.

I replaced the loop which doesn't work with

foreach(route in this.routes){

but it does only have a few routes stored, it seems. So I don't have a clue what to do exactly to fix this.

Here's the AI Debug window:

Attachment:
bork1.png


Fixed !
Thanks for the bug report.
Now it should work as expected.

It seems that nobody ever had a vehicle crash. Or at least nobody ever reported it.
Even including myself ... :D


Top
   
 Post subject: Re: BorkAI
PostPosted: Tue Dec 18, 2012 11:29 pm 
Offline
Engineer
Engineer

Joined: Tue Feb 23, 2010 3:44 pm
Posts: 103
Nice :-)

Maybe nobody was able to play with your AI all the months because of the missing file in the last version. And nobody reported it... What a pity :-)


Top
   
 Post subject: Re: BorkAI
PostPosted: Fri Dec 21, 2012 2:29 pm 
Offline
Engineer
Engineer

Joined: Tue Feb 23, 2010 3:44 pm
Posts: 103
Hi,
it seems that nobody had the case that BorkAI didn't find a place for a depot, too.
I would suggest adding "if (buildableTiles.len()<1)return null;" between the existing code.

local buildableTiles = filter(tiles, isBuildable);
local path = findRoadPath([tile],buildableTiles);


Bye



Attachment:
bork2.png [18.84 KiB]
Downloaded 6 times



Edit:
I realised now: Isn't there an error in the error message? :-)


Top
   
 Post subject: Re: BorkAI
PostPosted: Mon Dec 24, 2012 1:40 am 
Offline
Engineer
Engineer

Joined: Tue Aug 16, 2011 1:26 am
Posts: 37
Fixed, thanks for the bug report :).

The fixed version is already on Bananas, together with passenger handling enabled by default.
There's a little bug (in some scenarios/configurations bus won't be used) that I fixed only after uploading the new version... I'l re-upload another one tomorrow.


Top
   
 Post subject: Re: BorkAI
PostPosted: Sun Mar 31, 2013 10:39 am 
Offline
Engineer
Engineer

Joined: Tue Aug 16, 2011 1:26 am
Posts: 37
I have released a new version.
The performance on big maps has greatly improved.
This means that now one can use BorkAI on a 2048x2048 map and expect it to do something :D


Top
   
 Post subject: Re: BorkAI
PostPosted: Sat Jun 01, 2013 6:04 pm 
Offline
Engineer
Engineer

Joined: Tue Feb 12, 2013 5:29 pm
Posts: 79
Found an bug.
it is caused by line 910, you put this in:
Code:
        log("WARN",1,"Route " + route.Name() + " has no engines for cargo " + AICargo.GetCargoLabel(route.cargo));

with that, it tries to find the index "Name" but since that does not exist in the api it crashes. ;(
screen below.
fix if possible :bow:


Attachments:
read.png [138.91 KiB]
Downloaded 1 time

_________________
Activity-absent for now.
PLEASE DO NOT REPLY TO MY MESSAGES ANYMORE!
Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 68 posts ]  Go to page 1 2 3 4 Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 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.