BorkAI
Moderator: OpenTTD Developers
BorkAI
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 )
* 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 .
* 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
* 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.
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 )
* 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 .
* 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
* 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.
Re: BorkAI
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.
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.
Re: BorkAI
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.
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.
Re: BorkAI
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.
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.
Re: BorkAI
The setting to enable/disable buses and mail could be made a tri-state setting.
- Off
- Climate dependent
- On
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: BorkAI
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.
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)
Junctioneer (a traffic intersection simulator)
Re: BorkAI
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.
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.
Re: BorkAI
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.
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.
Re: BorkAI
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.
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.
Re: BorkAI
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).
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).
Re: BorkAI
crashy crash
- Attachments
-
- crash.PNG (7.57 KiB) Viewed 21830 times
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
Re: BorkAI
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 )
Hopefully
Thanks for reporting the error.
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 )
Hopefully
Thanks for reporting the error.
Re: BorkAI
Have a look at http://dev.openttdcoop.org/
Never failed me, and as you will see, many openttd projects
Never failed me, and as you will see, many openttd projects
Re: BorkAI
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:
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:
Re: BorkAI
Fixed !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:
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 ...
Re: BorkAI
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
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
Re: BorkAI
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
Edit:
I realised now: Isn't there an error in the error message?
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
Edit:
I realised now: Isn't there an error in the error message?
Re: BorkAI
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.
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.
Re: BorkAI
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
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
-
- Engineer
- Posts: 79
- Joined: 12 Feb 2013 17:29
Re: BorkAI
Found an bug.
it is caused by line 910, you put this in:
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
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));
screen below.
fix if possible
- Attachments
-
- read.png
- (138.91 KiB) Downloaded 1 time
Activity-absent for now.
PLEASE DO NOT REPLY TO MY MESSAGES ANYMORE!
PLEASE DO NOT REPLY TO MY MESSAGES ANYMORE!
Who is online
Users browsing this forum: No registered users and 1 guest