BorkAI

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

marco.r
Engineer
Engineer
Posts: 37
Joined: 16 Aug 2011 01:26

BorkAI

Post by marco.r » 29 Aug 2011 01:26

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.

Brumi
President
President
Posts: 904
Joined: 18 Jul 2009 17:54

Re: BorkAI

Post by Brumi » 29 Aug 2011 11:39

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.

marco.r
Engineer
Engineer
Posts: 37
Joined: 16 Aug 2011 01:26

Re: BorkAI

Post by marco.r » 29 Aug 2011 12:31

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.

marco.r
Engineer
Engineer
Posts: 37
Joined: 16 Aug 2011 01:26

Re: BorkAI

Post by marco.r » 01 Oct 2011 00: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.

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: BorkAI

Post by Zuu » 01 Oct 2011 06:49

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)

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: BorkAI

Post by Zuu » 08 Nov 2011 23:08

An issue that seem to relate to your AI has been found. See this thread: http://www.tt-forums.net/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)

Yexo
Tycoon
Tycoon
Posts: 3653
Joined: 20 Dec 2007 12:49

Re: BorkAI

Post by Yexo » 08 Nov 2011 23:22

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.

Yexo
Tycoon
Tycoon
Posts: 3653
Joined: 20 Dec 2007 12:49

Re: BorkAI

Post by Yexo » 10 Nov 2011 19:42

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.

marco.r
Engineer
Engineer
Posts: 37
Joined: 16 Aug 2011 01:26

Re: BorkAI

Post by marco.r » 12 Nov 2011 15:34

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.

marco.r
Engineer
Engineer
Posts: 37
Joined: 16 Aug 2011 01:26

Re: BorkAI

Post by marco.r » 14 Nov 2011 01:55

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).

Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: BorkAI

Post by Kogut » 29 Oct 2012 13:40

crashy crash
Attachments
crash.PNG
crash.PNG (7.57 KiB) Viewed 14197 times
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD

marco.r
Engineer
Engineer
Posts: 37
Joined: 16 Aug 2011 01:26

Re: BorkAI

Post by marco.r » 04 Dec 2012 22:33

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.

krinn
Transport Coordinator
Transport Coordinator
Posts: 336
Joined: 29 Dec 2010 19:36

Re: BorkAI

Post by krinn » 05 Dec 2012 00:06

Have a look at http://dev.openttdcoop.org/
Never failed me, and as you will see, many openttd projects :)

Steffl
Engineer
Engineer
Posts: 103
Joined: 23 Feb 2010 15:44

Re: BorkAI

Post by Steffl » 17 Dec 2012 14:12

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:
bork1.png
(18.97 KiB) Downloaded 10 times

marco.r
Engineer
Engineer
Posts: 37
Joined: 16 Aug 2011 01:26

Re: BorkAI

Post by marco.r » 18 Dec 2012 22:42

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:
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

Steffl
Engineer
Engineer
Posts: 103
Joined: 23 Feb 2010 15:44

Re: BorkAI

Post by Steffl » 18 Dec 2012 23:29

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 :-)

Steffl
Engineer
Engineer
Posts: 103
Joined: 23 Feb 2010 15:44

Re: BorkAI

Post by Steffl » 21 Dec 2012 14:29

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


bork2.png
(18.84 KiB) Downloaded 6 times

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

marco.r
Engineer
Engineer
Posts: 37
Joined: 16 Aug 2011 01:26

Re: BorkAI

Post by marco.r » 24 Dec 2012 01:40

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.

marco.r
Engineer
Engineer
Posts: 37
Joined: 16 Aug 2011 01:26

Re: BorkAI

Post by marco.r » 31 Mar 2013 10:39

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

Phrossi_TTD
Engineer
Engineer
Posts: 79
Joined: 12 Feb 2013 17:29

Re: BorkAI

Post by Phrossi_TTD » 01 Jun 2013 18:04

Found an bug.
it is caused by line 910, you put this in:

Code: Select all

        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!

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 12 guests