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
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Post by Zuu »

I've looked a bit into it now, and it seams like when the game quits the AI get's controll over the player. See this output: (notice, I loaned some extra money as player to show that it is the player that get messed with.)

Code: Select all

 ./openttd -a "Zuu AI" -g                                                                                                                                           
ZuuAI::Start()
ManageLoan: Want to pay back
Company: LT Transportation Transport
balance: 100000
loan: 100000
max_balance: 40000
pay_back: 60000
new_loan: 40000
Successfully paid back loan
ZuuAI::Stop()
ManageLoan: Want to pay back
Company: Unnamed
balance: 130000
loan: 130000
max_balance: 40000
pay_back: 90000
new_loan: 40000
openttd: /home/leif/Spel/OpenTTD/noai/noai/src/ai/ai_threads.cpp:130: void AIThreadState::Suspend(int): Assertion `this->state == RUNNING' failed.
zsh: abort      ./openttd -a "Zuu AI" -g
The interesting part is that after Zuu::AI() my MangeLoan() gets called for company "Unnamed" which have the same balance as my player did have. Also anther interesting thing is that "ZuuAI::Start()" is not printed, which is printed in the very start of my Start()-function.


EDIT: Seeing that you plan to change the Start/Stop mechanism it might not be worth to look deeper into this.
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Post by TrueBrain »

Zuu wrote:(..)

* It would be nice if there was a distance-function for calculating the distance between two tiles that uses the same distance algorithm as the rest of OpenTTD. Motivation: When comparing towns to link together it is nice to use the same distance calculations as when the AI will earn profit for it's line.

(..)
Already planned. Will most likely be done this week :)

Let us know if your AI is worth showing :)
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

Post by TrueBrain »

Zuu wrote:I've looked a bit into it now, and it seams like when the game quits the AI get's controll over the player. See this output: (notice, I loaned some extra money as player to show that it is the player that get messed with.)

(..)

The interesting part is that after Zuu::AI() my MangeLoan() gets called for company "Unnamed" which have the same balance as my player did have. Also anther interesting thing is that "ZuuAI::Start()" is not printed, which is printed in the very start of my Start()-function.


EDIT: Seeing that you plan to change the Start/Stop mechanism it might not be worth to look deeper into this.
It in fact is a known problem to us. When Stop() is issued, it is assumed that you stop directly, no Sleep(), no DoCommands like SetLoan. This only is impossible to do in any design of an AI, unless you check all the time if Stop() is called. So it is flawed by design. Don't worry about it too much, we will fix it up before merging to the trunk :)
The only thing necessary for the triumph of evil is for good men to do nothing.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Post by Zuu »

TrueLight wrote:Let us know if your AI is worth showing :)
At some point yes, but currently it can only manage it's loan and I'm working on search for town-pairs with high population and a reasonable distance to connect with busses. For actually connecting the towns I think I need to wait for some more stuff to be implemented. Such as more information about if a tile contain a house or not, slope etc.

I really like the nice work with the noai-branch.


Something that I think would be good for debugging, which you might or not might have though of is to make it possible for an AI to place signs on the map.
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Post by TrueBrain »

Zuu wrote:(..)

* It would be nice if the Squirrel standard library "math" could be initialized so that AIs can use the abs-functions etc. See the documentation.

(..)
abs() is added now in latest SVN. The reason why we don't load up the math library of SQ, is that we have some hooks and patches to make everything safe over all the targets we support. We can't be sure the default functions of SQ are safe, and therefor they are disabled. So if you have such functions you would like to be added, feel free to post them here, or ask me (TrueBrain on IRC, in #openttd, OFTC.net) to add them.

[Edit TrueLight] Distances functions are now added too ;)
The only thing necessary for the triumph of evil is for good men to do nothing.
User avatar
Ailure
Route Supervisor
Route Supervisor
Posts: 435
Joined: 26 Apr 2005 19:06
Location: Sweden

Post by Ailure »

Sorry if I seem impatient, but I just never been excited over a openTTD as now, especially since I have a few weeks of free time right now too. :lol: But... what's currently left for the Win32 support? <<
User avatar
XeryusTC
Tycoon
Tycoon
Posts: 15415
Joined: 02 May 2005 11:05
Skype: XeryusTC
Location: localhost

Post by XeryusTC »

Win32 support isn't there ATM, but if you want I can stick a win32 executable to my post, it is a bit edited with some extra API though ;).
Don't panic - My YouTube channel - Follow me on twitter (@XeryusTC) - Play Tribes: Ascend - Tired of Dropbox? Try SpiderOak (use this link and we both get 1GB extra space)
Image
OpenTTD: manual #openttdcoop: blog | wiki | public server | NewGRF pack | DevZone
Image Image Image Image Image Image Image
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Post by Zuu »

Bug: When building RoadDepots and RoadStations facing N-W or S-E the depot/station will face in the opposite direction as you tell it to do.

I've made a demo-AI that demonstrates this.


To run use this command:

Code: Select all

./openttd -a "Bus AI" -g ai/bus/scenario.scn 
The main.nut.txt should be renamed to main.nut and placed in ai/bus. The scenario.scn-file should also be placed in ai/bus. (ai/bus have to be created)
Attachments
main.nut.txt
On Line 40 you can change in which direction the depot/station will be built. Set +/-1 on x OR +/-1 on y, but not both at the same time. It is +/-1 on y that causes the bug. +/- on x works fine.

You can just change BuildRoadStation to BuildRoadDepot if
(1.94 KiB) Downloaded 227 times
scenario.scn
Not necessary, but if you use it you don't have to make sure that the (by the AI) selected tile is clear and buildable.
(7.09 KiB) Downloaded 219 times
busAI.png
busAI.png (6.6 KiB) Viewed 5954 times
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Post by Zuu »

A fix to the bugs in BuildRoadStation and BuildRoadDepot


There is anther issue in the BuildRoad-function that is not solved in this patch. For the direction Y -1, the road is not built correctly, in the sense that it does not goes from center to center of the two tiles.


Edit: Removed a challenging language twist (in the post).

Edit2:
Attached an image that shows a test where I built roads like a star out from the tiles adjacent to the center and outwards. This test shows two things. The result is the same if you build independent of if the roads are built outwards or inwards. Secondly it shows that the S-W/S-E ends are built wrong.

For reference the code for generating the "star" is comes here:

Code: Select all

function BusAI::Road(center, direction)
{
    local tile = [null, null];
    tile[1] = this.map.GetTileIndex( this.map.GetTileX(center) + direction[0], this.map.GetTileY(center) + direction[1] );
    tile[0] = this.map.GetTileIndex( this.map.GetTileX(center) + 2*direction[0], this.map.GetTileY(center) + 2*direction[1] );

    this.road.BuildRoad(tile[0], tile[1]);
}
And in the ::Start() function:

Code: Select all

    local tile = this.map.GetTileIndex(25, 25);
    Road(tile, [1, 0]);
    Road(tile, [-1, 0]);
    Road(tile, [0, 1]);
    Road(tile, [0, -1]);
Attachments
fix.diff
(1.05 KiB) Downloaded 217 times
road_pattern.png
road_pattern.png (7.87 KiB) Viewed 5897 times
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Post by TrueBrain »

All problems reported above should be fixed now.
The only thing necessary for the triumph of evil is for good men to do nothing.
User avatar
Ailure
Route Supervisor
Route Supervisor
Posts: 435
Joined: 26 Apr 2005 19:06
Location: Sweden

Post by Ailure »

XeryusTC wrote:Win32 support isn't there ATM, but if you want I can stick a win32 executable to my post, it is a bit edited with some extra API though ;).
Well, I wouldn't mind any extra undocumented features. I wouldn't use them though. :P
User avatar
XeryusTC
Tycoon
Tycoon
Posts: 15415
Joined: 02 May 2005 11:05
Skype: XeryusTC
Location: localhost

Post by XeryusTC »

Ailure wrote:
XeryusTC wrote:Win32 support isn't there ATM, but if you want I can stick a win32 executable to my post, it is a bit edited with some extra API though ;).
Well, I wouldn't mind any extra undocumented features. I wouldn't use them though. :P
Ok, here we go.

[Edit TrueLight] As we are almost finished with official Win32 support, we kindly ask you to wait just a few more days, or send those binaries per PM or IRC. [/Edit]
Don't panic - My YouTube channel - Follow me on twitter (@XeryusTC) - Play Tribes: Ascend - Tired of Dropbox? Try SpiderOak (use this link and we both get 1GB extra space)
Image
OpenTTD: manual #openttdcoop: blog | wiki | public server | NewGRF pack | DevZone
Image Image Image Image Image Image Image
User avatar
Ailure
Route Supervisor
Route Supervisor
Posts: 435
Joined: 26 Apr 2005 19:06
Location: Sweden

Post by Ailure »

Thank you. After downloading pthreadGC2.dll as well, I got it to work. I go and play around with noAI a bit and see what I come up with. :P
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Post by Zuu »

Bug: "AIVehicle" class was not registered properly. Fix is attached.
Attachments
fix_vehicle.diff
(689 Bytes) Downloaded 199 times
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Post by Zuu »

It seams like it is impossible to find an (road)engine for any cargo. I made a test-ai that for all cargos looks for an engine with reliability >= 0 for each cargo type.

Code: Select all

./openttd -a "Bug AI" -g
Output:

Code: Select all

BugAI::Start()
cargo with id=0 and name=PASS is a valid cargo
 - Did NOT found a valid engine for this cargo
cargo with id=1 and name=COAL is a valid cargo
 - Did NOT found a valid engine for this cargo
cargo with id=2 and name=MAIL is a valid cargo
 - Did NOT found a valid engine for this cargo
cargo with id=3 and name=OIL_ is a valid cargo
 - Did NOT found a valid engine for this cargo
cargo with id=4 and name=LVST is a valid cargo
 - Did NOT found a valid engine for this cargo
cargo with id=5 and name=GOOD is a valid cargo
 - Did NOT found a valid engine for this cargo
cargo with id=6 and name=GRAI is a valid cargo
 - Did NOT found a valid engine for this cargo
cargo with id=7 and name=WOOD is a valid cargo
 - Did NOT found a valid engine for this cargo
cargo with id=8 and name=IORE is a valid cargo
 - Did NOT found a valid engine for this cargo
cargo with id=9 and name=STEL is a valid cargo
 - Did NOT found a valid engine for this cargo
cargo with id=10 and name=VALU is a valid cargo
 - Did NOT found a valid engine for this cargo
Attachments
main.nut.txt
Make a directory bin/ai/bug, and place this file there. And remove the .txt too. :)
(2.19 KiB) Downloaded 189 times
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Post by TrueBrain »

Win32 support is now done. The API for making road AIs is done. Or anyway, the basics are. So, you should be able to start with your first AI. Of course important parts like pathfinders and simple tilelist filters are missing, which will be added in the next few weeks. But, the basics are there. So, if you like, download the upcoming binaries (should be there this week), and start building your AI. Report any problems here. Also if you have function requests feel free to post them. Just remind yourself that we might not agree, or already plan to do that. Have fun!
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

Post by TrueBrain »

Zuu wrote:It seams like it is impossible to find an (road)engine for any cargo. I made a test-ai that for all cargos looks for an engine with reliability >= 0 for each cargo type.
(..)
Now fixed :)
The only thing necessary for the triumph of evil is for good men to do nothing.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Post by Zuu »

It would be nice if there where a way to get the direction of a road station. The reason why this would be nice is that I want to find the road tile from which busses/trucks enter/exits from the station. Reason for that is that it makes no sense to connect two station-tiles with road if one can not make sure their entrances are reachable from the new built connection.

Two possible functions:
?? GetDirection(TileIndex station)
or
TileIndex GetFrontTile(TileIndex station)


I think the later would be easier to use in my case. Both because it makes less code for me and because I don't want to do bit-magic if I can avoid it. It also makes sense to use the concept of front-tile both when building the station and when acquiring information about the station.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Post by Zuu »

AIOrder-bug.

Orders are not added properly.


AI + scenario that demonstrates the bug are attached.

Code: Select all

./openttd -a "Bus AI" -g ai/bus/scenario.scn
Attachments
scenario.scn
(7.09 KiB) Downloaded 202 times
main.nut.txt
(3.1 KiB) Downloaded 252 times
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Post by TrueBrain »

Zuu wrote:AIOrder-bug.

Orders are not added properly.


AI + scenario that demonstrates the bug are attached.

Code: Select all

./openttd -a "Bus AI" -g ai/bus/scenario.scn
Fixed in SVN.
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 5 guests