NoAI Branch - An AI Framework

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

User avatar
Ralph
Engineer
Engineer
Posts: 87
Joined: 21 Jun 2004 15:25

Re: NoAI Branch - An AI Framework

Post by Ralph »

TrueLight wrote:Also, if you need Exist() in the first please, a Binary Heap is not what you need :) Binary Heap is to sort, and find the lowest value :) If you want to avoid double entries, I suggest using AIList, or create an other kind of list :) Binary Heap is _not_ your friend (Exist() is always O(n)). If you use it for any AyStar alike routine, I suggest looking at the AyStar library ;) Hehe :)
I have not sat down and worked out the numbers, but using an Exist() to prevent duplicate entries on your open list 'feels' like it should be quicker, as those duplicates will soon add up. If you fetch the node that exists you can also take the opportunity to update the g cost and parent node if it turns out to be shorter. I typically found my open list to contain at maximum ~500 nodes, so its not really in the territory that looping over the list a few times is going to break the bank.

I would test both behaviours, but it seems the latest build has broken my pathfinder...
User avatar
Ralph
Engineer
Engineer
Posts: 87
Joined: 21 Jun 2004 15:25

Re: NoAI Branch - An AI Framework

Post by Ralph »

reylas wrote:
Ok, so is there anyway to tell if a tile has a foundation on it? According to the slope of the tile, I should be able to build, but I cannot. In code the only way I can tell I cannot build is to build and then fail. That is tough since I really need to build to the north east but my program found the south east tile first. There has to be some way of seeing before hand that that tile is not connectable by slope. A pathfinder will need that.

MarkS
For houses: Not that I can think of.
For Roads: Get the slope, and check which adjacent tiles it is connected to with AreRoadTilesConnected, then combine the information to determine if that road layout on that slope would require foundations (look for road running, parallel to the slope, etc), roads and slopes are not a trivial problem, it took me much trail and error to get it right.
Finaldeath
Engineer
Engineer
Posts: 72
Joined: 09 Apr 2006 23:49
Location: UK
Contact:

Re: NoAI Branch - An AI Framework

Post by Finaldeath »

Yeah, I am going to have fun on slopes once I get around to it. Will add info to the wiki once I get some code going.

Considering this very very important information, can the API be updated to reflect it?

Needs a comment like "The exact height of a tile returned is the northern corner point of a tile, the slope directions must be used to check weather a flat building will be on this level exactly or +/- 1 of this level height." or something. I think. I am not sure, but I guess actually it will only ever be up to 1 higher (a north point being lower then any of the rest).

Perhaps some function to return the highest point of all 4 corners would remove the unnecessary need to check every corner, and it's slope type, just to get the highest point, since for simple applications like "Build a bus depot" you only need the highest height to check against nearby roads to see if it connects etc. GetHighestHeight() perhaps.

Only a quick idea, it might be that the actual code to get the highest point is easier then I imagine. I'm mainly working on water AI right now ;)
Finaldeath
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: NoAI Branch - An AI Framework

Post by Zutty »

Finaldeath wrote:...I'm mainly working on water AI right now ;)
Oooooh. That sounds challenging. Does it build canals or terraform to connect stuff to water, or just use resources that are already on the coast. Tell us more! :D
PathZilla - A networking AI - Now with tram support.
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

Ralph wrote:
TrueLight wrote:Also, if you need Exist() in the first please, a Binary Heap is not what you need :) Binary Heap is to sort, and find the lowest value :) If you want to avoid double entries, I suggest using AIList, or create an other kind of list :) Binary Heap is _not_ your friend (Exist() is always O(n)). If you use it for any AyStar alike routine, I suggest looking at the AyStar library ;) Hehe :)
I have not sat down and worked out the numbers, but using an Exist() to prevent duplicate entries on your open list 'feels' like it should be quicker, as those duplicates will soon add up. If you fetch the node that exists you can also take the opportunity to update the g cost and parent node if it turns out to be shorter. I typically found my open list to contain at maximum ~500 nodes, so its not really in the territory that looping over the list a few times is going to break the bank.

I would test both behaviours, but it seems the latest build has broken my pathfinder...
How a Binary Heap works is totally unrelated to what you expect it to do :) Exist() is a O(n) for Binary Heap, as it is a Priority Queue, and can only tell you very quick what the lowest value is, nothing else. Most other actions are O(n). If you want fast Exist() action, you need other tree (RedBlack?). However, for A* this is not important.

There is no need to check if a value is in your Open-list, and update any f-value if needed. What you do, is just put duplicated nodes in the tree, no problem what so ever. As here the Closed-list comes in. As soon as you pop an item from the Open-list, you check if it is in the Closed-list. If so, ignore the item, and find the next one. This way there is no need to use any Exist() on the Open-list (just on the Closed-list, which should NOT be a Binary Heap). That is how A* is intended to work. For example, at any time in your Open-list those values can exist:

Code: Select all

 Value Tile
  1       2356
  2       2356
  6       2356
  9       2357
As you can see, '2356' is 3 times in the list. No problem, his value '1' is pop'd first, and the other two are ignored when ever they are used. Yes, the Open-list will be bigger than you are used to, but it is the most efficient approach. Also, because of how the A* algorithm works, it ALWAYS finds the shortest route to any tile, so don't worry about it being added many times; as soon it is pop'd from the Open-list, you can be very sure that the path to that tile is most efficient via that way. But now I am explaining how A* works ...

Anyway, I think I now told more about how A* works than I intended, and also how one should handle an Open-list and Closed-list. I strongly suggest to read some real documentation about A* implementation, and you will see :) (not 'you' as one person, but 'you' in general) To summarize it once more: using Exist() on Open-list: not needed. Using Exist() of Binary Heap: bad idea! Use other tree-type if you require this action.
The only thing necessary for the triumph of evil is for good men to do nothing.
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: NoAI Branch - An AI Framework

Post by Zutty »

Zutty wrote:Just a quick one for the devs... I'm getting inconsistent results from AITile.IsBuildable() on coast tiles. This really feels like a bug to me, as the result is unpredictable. Mostly it returns false for any land tile that borders with water, but sometimes it returns true for no apparent reason. There can be a long stretch of coast tiles in a line, and one out of twenty will be buildable at random!

Ideally I'd like IsBuildable() to return true for coast tiles with nothing on them (it would be helpful for bridge building), but just having consistent results will be a start!

Is this a bug? Can we have it fixed? Is it already fixed?! (I'm still using r13326)

Thanks.
I'm sorry to bump my own post, but I don't suppose anyone can answer this question can they? :) Its kind of blocking my development at the moment.

Its hard keeping track of stuff in just a single thread. That new forum will be very handy.
PathZilla - A networking AI - Now with tram support.
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

Zutty wrote: Its hard keeping track of stuff in just a single thread. That new forum will be very handy.
Post such comments in the thread created for that ;)
The only thing necessary for the triumph of evil is for good men to do nothing.
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

Zutty wrote:I'm sorry to bump my own post, but I don't suppose anyone can answer this question can they? :) Its kind of blocking my development at the moment.
It is fixed now, and in 5 hours and 25 minutes in the binaries that will produced by then :)
The only thing necessary for the triumph of evil is for good men to do nothing.
wilco_moerman
Engineer
Engineer
Posts: 70
Joined: 05 Jun 2008 15:51

Re: NoAI Branch - An AI Framework

Post by wilco_moerman »

TrueLight wrote:
Zutty wrote:I'm sorry to bump my own post, but I don't suppose anyone can answer this question can they? :) Its kind of blocking my development at the moment.
It is fixed now, and in 5 hours and 25 minutes in the binaries that will produced by then :)
any more news on the crashes related to start_ai?
Nunc dimittis servum tuum Domine secundum verbum tuum in pace
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

wilco_moerman wrote: any more news on the crashes related to start_ai?
We can't reproduce the problem, so that is a problem :) Would you be able to join IRC? Or else can you give a detailed description of what you are doing? (what, when, how, like: start OpenTTD, create a new game, open console, type this, and that, and then: BOOM!). Tnx :)
The only thing necessary for the triumph of evil is for good men to do nothing.
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: NoAI Branch - An AI Framework

Post by Zutty »

TrueLight wrote:
Zutty wrote:I'm sorry to bump my own post, but I don't suppose anyone can answer this question can they? :) Its kind of blocking my development at the moment.
It is fixed now, and in 5 hours and 25 minutes in the binaries that will produced by then :)
You're a god! :bow:
PathZilla - A networking AI - Now with tram support.
wilco_moerman
Engineer
Engineer
Posts: 70
Joined: 05 Jun 2008 15:51

Re: NoAI Branch - An AI Framework

Post by wilco_moerman »

TrueLight wrote:
wilco_moerman wrote: any more news on the crashes related to start_ai?
We can't reproduce the problem, so that is a problem :)
:)
Would you be able to join IRC? Or else can you give a detailed description of what you are doing? (what, when, how, like: start OpenTTD, create a new game, open console, type this, and that, and then: BOOM!). Tnx :)
1.) I start openttd by executing openttd.exe (in Windows 2000)
2.) I start a new game
3.) on the console, I type "start_ai wrightai" (and wrightai starts to work)
4.) In the ai-debug window, I press "reload AI" and BOOM!
4b.) more formally, the BOOM should be described as:

"Microsoft Visual C++ Runtime Library
Program: F:\tjip-challenge\OTTD-win32-noai-r13474-noai\openttd.exe
abnormal program termination"

this is in r13474 (downloaded yesterday). The same happens when I start a server and press reload. If I start the server and just let it run until it resets itself and automatically starts the AI, the game also crashes
edit: I also get the crash when i start an AI at the console and then try to exit the game!

in an older binary (r13355) the game only sometimes crashes on reload. If i continue to press reload, it crashes (after perhaps 10 or 20 or 30 reloads).
edit: Here the game doesn't crash when I try to close it after I have started an AI.



Is this enough information? Could it be something that is specific to win2k for instance? I was able to recreate this error on another pc (albeit with the same win2k distribution on it. I don't have any other operating systems here).
Last edited by wilco_moerman on 12 Jun 2008 11:34, edited 4 times in total.
Nunc dimittis servum tuum Domine secundum verbum tuum in pace
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

GeekToo wrote:Update of Convoy:

(..)

Lots of things have improved since the previous version, and I realise lots of things still have to be done.
I ran it through the tournament system, the results are online .. impressive :) You won from both AviatorAI and WrightAI :)

http://devs.openttd.org/~noai/tournament/
The only thing necessary for the triumph of evil is for good men to do nothing.
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: NoAI Branch - An AI Framework

Post by Zutty »

Wow! That IS impressive, considering that aircraft are at a natural advantage to buses in OpenTTD. Congratulations GeekToo :D You've set the bar!

Edit: Hey Truelight can we get RalphsAI into the tournament also?
PathZilla - A networking AI - Now with tram support.
User avatar
Ralph
Engineer
Engineer
Posts: 87
Joined: 21 Jun 2004 15:25

Re: NoAI Branch - An AI Framework

Post by Ralph »

Zutty wrote:Wow! That IS impressive, considering that aircraft are at a natural advantage to buses in OpenTTD. Congratulations GeekToo :D You've set the bar!

Edit: Hey Truelight can we get RalphsAI into the tournament also?
Mine is currently not working, seems AITile.IsBuildable is returning false on roads now..

Is this the intended behavior from now on?
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

Ralph wrote: Mine is currently not working, seems AITile.IsBuildable is returning false on roads now..

Is this the intended behavior from now on?
yes.
The only thing necessary for the triumph of evil is for good men to do nothing.
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: NoAI Branch - An AI Framework

Post by Zutty »

Ralph wrote:
Zutty wrote:Wow! That IS impressive, considering that aircraft are at a natural advantage to buses in OpenTTD. Congratulations GeekToo :D You've set the bar!

Edit: Hey Truelight can we get RalphsAI into the tournament also?
Mine is currently not working, seems AITile.IsBuildable is returning false on roads now..

Is this the intended behavior from now on?
Damn! If its any consolation, I need to spend tonight adjusting my AI to cope with this change too!!

I like this new feature though, as it forces me to formalise the traversal of existing roads.
PathZilla - A networking AI - Now with tram support.
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

This was the original thread as in OpenTTD Development forum. It is now locked, and the required topics are copied to new topics in this forum, allowing clear conversation. This is left here to refer back to.

To post new topics, go here: http://www.tt-forums.net/viewforum.php?f=65
The only thing necessary for the triumph of evil is for good men to do nothing.
Locked

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 38 guests