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

Locked
dynaxo
Engineer
Engineer
Posts: 30
Joined: 25 Dec 2004 11:51
Location: Germany

Re: NoAI Branch - An AI Framework

Post by dynaxo »

GeekToo wrote: I'm running on Gentoo Linux, has anyone seen this before, or is it my script?
No, I also do have this problem and it even occurs with the wrightai script. Also I had problems with debugging noai-ottd with kdevelop. It often crashed while singlestepping.
And when closing openttd it shows "Speicherzugriffsfehler" which means that an error occurred while accessing memory.
By the way: I'm running it on debian linux.
Frnz.nl
Engineer
Engineer
Posts: 3
Joined: 07 Sep 2007 18:49
Location: Gelderland, the Netherlands

Re: NoAI Branch - An AI Framework

Post by Frnz.nl »

I seem to have a problem with building bus stations next to a road tile. When I build the station with the front facing to the road. It won't connect to the road like it would do if you place a station like that as a player. I've attached a screenshot as an example.

I've already tried to use AIRoad::BuildRoad(); and AIRoad::BuildRoadFull();. Both functions obviously return false when I try to use them to connect my station to the roadtile laying next to the station.

I'm stuck on this for some time now :? Am I missing something here?

(and ofcourse thanks for the devs of NoAI for this neat piece of software ;))
Attachments
busstation.png
busstation.png (27.98 KiB) Viewed 3896 times
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: NoAI Branch - An AI Framework

Post by Rubidium »

"Easiest" way out for now is using the "trick" that you can build over half road tiles, i.e. you build the road before you build the station (and the station is build over a half road tile).
Frnz.nl
Engineer
Engineer
Posts: 3
Joined: 07 Sep 2007 18:49
Location: Gelderland, the Netherlands

Re: NoAI Branch - An AI Framework

Post by Frnz.nl »

Thanx a lot that solved the problem :D
Altough I thought I tried something like that, but I guess this is the way we've got to learn :wink:
User avatar
GeekToo
Tycoon
Tycoon
Posts: 961
Joined: 03 Jun 2007 22:22

Re: NoAI Branch - An AI Framework

Post by GeekToo »

While working on the bus AI, I have got a problem, that I don't know how to solve.

I am trying to create a function that gets the tiles where a station can be build, next to a road tile. Input is tile, which is the tileindex of a tile where a station needs to be build, e.g. the location of a town. After I have created a list of the tiles that are buildable, and next to a road, and sorted to the distance of the given tile, I want to find the TileIndex of the first tile, so I can find out where the road next to this tile is, and build a station in the right direction. But I don't know how to find the TileIndex of a tile in the list, so maybe I overlooked something. Any help on this is appreciated.
( The function is not finished, I still have to add a check whether the tile is a road etc, but that does not seem to be a problem)

Code: Select all

	local tl=AITileList();
        local x=this.map.GetTileX(tile);
        local y=this.map.GetTileY(tile);
	
        tl.AddRectangle(this.map.GetTileIndex(x-10,y-10),this.map.GetTileIndex(x+10,y+10));
        if (tl.Count())
        {
	   /* search for buildable tiles in 400 tiles around the given tile */
           tl.Valuate(AITileListBuildable());
           tl.KeepValue(1);
           if (tl.Count())
           {
               /* find all tiles in the resulting list that are next to a road tile */
                tl.Valuate(AITileListNeighbourRoadCount());	
                tl.KeepAboveValue(0);
           }
           if (tl.Count())
           {
                /* sort the tile in distance to the give tile */
                tl.Valuate(AITileListDistanceManhattanToTile (tile);
                tl.Sort(SORT_BY_VALUE, true);
                local aitile = tl.Begin();

********    TileIndex of aitile? **********

            }
        }
Frnz.nl
Engineer
Engineer
Posts: 3
Joined: 07 Sep 2007 18:49
Location: Gelderland, the Netherlands

Re: NoAI Branch - An AI Framework

Post by Frnz.nl »

I solved this by doing a new check for the tile in which you want to build the station. Probably not the best way to do so, but it works for me.

Code: Select all

/*First I made a tilelist containing all the adjacent tiles for the tile on which you want to build the station.*/

local adjacentTiles = AITileList();
adjacentTiles.AddRectangle(tile - this.map.GetTileIndex(1,1), tile + this.map.GetTileIndex(1,1));
i = 0;

/*Loop through all adjacent tiles*/

for(tile2 = adjacentTiles.Begin(); adjacentTiles.HasNext(); tile2 = adjacentTiles.Next()) {

	/*'i % 2 == 1' makes sure that we only check every other tile*/

	if(this.road.IsRoadTile(tile2) && i % 2 == 1) {
		/*need this road to connect station to the road, thnx Rubidium*/
		this.road.BuildRoad(tile2, tile);
		
		/*Build station*/
		this.road.BuildRoadStation(tile, tile2, false, false);
	}
	i++;
}
In a 3x3 square the 'i % 2 == 1' makes sure we only check the north, south, east and west tiles for a roadtile.

Code: Select all

. x .
x . x
. x .
PS
this.road is an instance of AIRoad
User avatar
GeekToo
Tycoon
Tycoon
Posts: 961
Joined: 03 Jun 2007 22:22

Re: NoAI Branch - An AI Framework

Post by GeekToo »

Thanks frnz.nl

Your example pointed me in the right direction:

I assumed that:
aitile = tl.Begin();
would make aitile an AITile object(of which you can not get the location), but your code showed it is actually a TileIndex.

@developers:

After that was clear, I had problems with creating an ascending list, sorted by value

tl.Valuate(AITileListDistanceManhattanToTile (tile));
tl.Sort(AITileList.SORT_BY_VALUE, true);

At first I assumed I did something wrong, I could not get it working the way I wanted. After some investigation, I propose the following patch( seems like a copy-paste bug). It did make it work for me.

Code: Select all

Index: src/ai/api/ai_abstractlist.cpp
===================================================================
--- src/ai/api/ai_abstractlist.cpp      (revision 11072)
+++ src/ai/api/ai_abstractlist.cpp      (working copy)
@@ -300,8 +300,8 @@
                        break;

                case SORT_BY_VALUE:
-                       if (ascending) this->sorter = new AIAbstractListSorterItemAscending(this);
-                       else           this->sorter = new AIAbstractListSorterItemDescending(this);
+                       if (ascending) this->sorter = new AIAbstractListSorterValueAscending(this);
+                       else           this->sorter = new AIAbstractListSorterValueDescending(this);
                        break;

                default:

Attachments
sort.diff
(609 Bytes) Downloaded 57 times
msan
Engineer
Engineer
Posts: 1
Joined: 02 Oct 2007 18:48

Re: NoAI Branch - An AI Framework

Post by msan »

Hi!
It seems that branch development is frozen now... :( Am I right?
I think that the idea of framework is great and the present code is great too. Will development be continued and interface for train building be implemented?
Thanks.
dynaxo
Engineer
Engineer
Posts: 30
Joined: 25 Dec 2004 11:51
Location: Germany

Re: NoAI Branch - An AI Framework

Post by dynaxo »

It indeed seems as if the development is frozen. For curiosity I downloaded the noai source and played a bit with it. Maybe I'll work on this further if I find the time for this.

Changelog:
- merged the noai source with the latest trunk code
- changed 'SkipVehicleOrder' to 'SkipToVehicleOrder' in AIVehicle
- added 'MoveOder' to AIOrder
- added 'RaiseTile' and 'LowerTile' to AITile, you're now able to terraform

Latest sourcecode:
http://homepages.uni-paderborn.de/leise/noai.tar.gz

Binary for linux (I compiled it on my debian etch system, I'm not sure if it will work on other linuxes):
http://homepages.uni-paderborn.de/leise ... oai.tar.gz

Doxygen documentation:
http://homepages.uni-paderborn.de/leise/doxygen/
As you may presently yourself be fully made aware of, my grammar sucks
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: NoAI Branch - An AI Framework

Post by Rubidium »

I think it is best to leave the "syncing" out of your diffs, especially if you would like them to be applied.

Furthermore diffs/patches are much more likely to get applied as it is much easier to actually applies them.

AFAIK NoAI is kinda frozen due to:
a) temporary lack of interest and time of the developers.
b) the fact that it really looks like nobody is actually writing nice AIs with it.

Though you can easily keep it alive by further extending the API of NoAI ;)
dynaxo
Engineer
Engineer
Posts: 30
Joined: 25 Dec 2004 11:51
Location: Germany

Re: NoAI Branch - An AI Framework

Post by dynaxo »

Rubidium wrote:I think it is best to leave the "syncing" out of your diffs, especially if you would like them to be applied.
That depends on the fact if noai is frozen or if it's dead. If it's only frozen you're right, if it's dead the noai source on the server never gets synced. After some months it might be hard to sync it to the trunk, especially if I have to change something in the openttd code.
Rubidium wrote: b) the fact that it really looks like nobody is actually writing nice AIs with it.
Well, a few people did. I think the main problem is that railways aren't supported yet. I'm not sure if I can add it because truelight wrote it's "really hard to do correctly" but I might try. Also I'll try to clean out my AI so I can make it public.
As you may presently yourself be fully made aware of, my grammar sucks
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: NoAI Branch - An AI Framework

Post by Rubidium »

dynaxo wrote:That depends on the fact if noai is frozen or if it's dead.
As long as NoAI on the SVN server is synced e very few hundred revisions (max about 300-500 I guess), it is not dead but frozen; there is at that moment still enough interest in NoAI to keep it alive.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: NoAI Branch - An AI Framework

Post by Zuu »

Rubidium wrote: b) the fact that it really looks like nobody is actually writing nice AIs with it.
Well, a few people did. I think the main problem is that railways aren't supported yet. I'm not sure if I can add it because truelight wrote it's "really hard to do correctly" but I might try. Also I'll try to clean out my AI so I can make it public.[/quote]

I don't think lack railways is a major hold back. Yes some might turn around when they see there is no railway stuff implemented. However I think people interested of developing AIs find it challenging enough to develop an road AI.

Myself I had some serious plans for a air-only AI that would use more advanced planing and statistics than Clueless did. But I figured that I rather spend my time on getting my degree than writing on an AI that might or might not get used.


But some thoughts:
* The game only need to have data sources for current values of things you want to keep track of. Just write your own code to get mean-values with your desired method. (such as new_mean := old_mean*0.98 + curr_value * 0.02; )
* It would be nice to be able to acquire the current aircraft-queue length of an airport.
* I think the amount of waiting passengers is already implemented.

* Using aircraft queue and amount of waiting passengers and geometric data you could balance your aircraft force pretty good, as you can keep track of needs, capacity limits and profit (long routes rather than short ones).
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
dynaxo
Engineer
Engineer
Posts: 30
Joined: 25 Dec 2004 11:51
Location: Germany

Re: NoAI Branch - An AI Framework

Post by dynaxo »

@Rubidium
ok, if someone really syncs it from time to time I'll switch to patches.

@Zuu
I already created an air-only AI. It builds airports in every city, calculates a route via Hamilton-Cycle and fills the route until it is saturated.But I have to rewrite it as I noticed that an orderlist can have a maximum of only 40(?) entries. Maybe I will raise that limit.
* It would be nice to be able to acquire the current aircraft-queue length of an airport.
I also thought of that. I'll try to implement it.
* I think the amount of waiting passengers is already implemented.
Yes indeed. It's AIStation::GetCargoWaiting(...)
As you may presently yourself be fully made aware of, my grammar sucks
User avatar
glx
OpenTTD Developer
OpenTTD Developer
Posts: 622
Joined: 02 Dec 2005 15:43
Location: Drancy(93) - France
Contact:

Re: NoAI Branch - An AI Framework

Post by glx »

dynaxo wrote:But I have to rewrite it as I noticed that an orderlist can have a maximum of only 40(?) entries. Maybe I will raise that limit.
This limit has been removed in r11184 in trunk, and NoAI is currently synced to r11220.
dynaxo
Engineer
Engineer
Posts: 30
Joined: 25 Dec 2004 11:51
Location: Germany

Re: NoAI Branch - An AI Framework

Post by dynaxo »

That's really great, I didn't notice that.
But when I looked into the code I couldn't find any check for an upper boundary. Nevertheless I tested my AI on the noai-code. My ai added 266 stations to my orderlist. But when I looked into the orderlist only 11 orders where in it. 266 - 11 = 255!.
That's not a problem for me as I can program my AI to this boundary. But a normal user could get angry if he ever adds more than 255 orders :)
Is this problem known?
As you may presently yourself be fully made aware of, my grammar sucks
dynaxo
Engineer
Engineer
Posts: 30
Joined: 25 Dec 2004 11:51
Location: Germany

Re: NoAI Branch - An AI Framework

Post by dynaxo »

I put my patches and the doxygen-docu onto my (crappy) website:
http://homepages.uni-paderborn.de/leise/

There you'll also find my AI I use for playing and testing.
As you may presently yourself be fully made aware of, my grammar sucks
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain »

I have added your SkipToVehicleOrder patch, but with the other 2 I have a problem...

With the MoveOrder one, I don't understand the comment:

+ * @note The target order will move one place down in the orderlist
+ * if you move the order upwards else it'll move it one place down

Can you maybe make a more clear comment there?

About the Lower and Raise tile: it doesn't work for Squirrel scripts (our main goal), as the SLOPE_XXX aren't defined there. You really have to define those too. If you can do that in your patch, I see no problems to add them.

Also, please do use 'svn diff', and not some custom diff command.. tnx ;)
The only thing necessary for the triumph of evil is for good men to do nothing.
svetovoi
Engineer
Engineer
Posts: 87
Joined: 12 Oct 2007 14:07

Re: NoAI Branch - An AI Framework

Post by svetovoi »

TrueLight wrote: About the Lower and Raise tile
Maybe create new class "AITerraformer" for it?
This class could also manage all terrain related stuff, such as preparing ground for stations.
As I notice dynaxo overambitiousAI and WrightAI just searching for flat rectangle big enough to place an airport, while AITerraformer may be able to create this big flat rectangle (and do other usefull things)
User avatar
saint
Engineer
Engineer
Posts: 45
Joined: 25 Dec 2005 23:01
Location: Australia

Re: NoAI Branch - An AI Framework

Post by saint »

Zuu wrote:
dynaxo wrote:
Rubidium wrote: b) the fact that it really looks like nobody is actually writing nice AIs with it.
Well, a few people did. I think the main problem is that railways aren't supported yet. I'm not sure if I can add it because truelight wrote it's "really hard to do correctly" but I might try. Also I'll try to clean out my AI so I can make it public.
I don't think lack railways is a major hold back. Yes some might turn around when they see there is no railway stuff implemented. However I think people interested of developing AIs find it challenging enough to develop an road AI.

Myself I had some serious plans for a air-only AI that would use more advanced planing and statistics than Clueless did. But I figured that I rather spend my time on getting my degree than writing on an AI that might or might not get used.
Just thought I'd add to this.

I've played around with a road based AI and gotten to the stage of creating several reasonably spaced bus-stops within the same town (having adequate population) only to find the profit wasn't there for the distance travelled. It was quite a challenge to get there too from having to learn the language (coming from a C/Java/VB (v6 and 2005)/PHP background this wasn't too bad), less documentation than I would have liked, few examples, lack of time and so on. If/when I do continue (which I would like to :wink: ), it seems that a reasonable framework/helpers to do the basics such as in Clueless (impressive work Zuu!) is a must in all AI's, adding to the work we need to do to ensure the rest of the AI is easier to code.

Railways would be nice to give a boost to profits but I can appreciate the (potential?) difficulty in getting it to work. Congrats to TrueLight and others for all the work for NoAI so far :D
This is my sig
Locked

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 35 guests