Convoy: train support testversion

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
GeekToo
President
President
Posts: 950
Joined: 03 Jun 2007 22:22

Convoy: train support testversion

Post by GeekToo » 23 May 2008 22:23

TrueLight wrote:[
Now show us your AI and let us enjoy the moment too :)
OK, here it is: Convoy (the bus loving AI)

Features:
-Uses buses only
-Pathfinding is 'curvy', straight roads would be better performancewise, but I don't like having only straight roads
-Completely written in Squirrel, no patches

Installation:
-Compatible with r13219 (thanks for solving the passenger class problem)
-Since this week it is possible to use the tarloader to load the AI, so installation is extremely easy:
copy the tar to the bin/ai directory ( no need to untar ). Ready!
-Start openttd.
-To set up a battle load a scenario, or a new game ( if you're battling with Wright, choose a very flat map )
-Press the ` key (left of 1), and enter start_ai WrightAI <enter>, start_ai Convoy <enter>
-Press the ` again to close the console

Have fun !


I've chosen an iterative approach: first create a working AI that is playable, although many parts are not optimal.
So there's a rather long todo list still, but the AI should already be nice to compete against.

ToDo:
-Improve pathfinder: A* is not completely implemented, shorter routes on the openlist are disregarded
-Improve pathfinding on slopes, sometimes connections on slopes are failing
-Improve town coverage, only one station per town is build, add intratown lines
-Optimize time performance
-Line building: currently only unused towns are connected, which is ok for the first few years, but after that, no unused towns can be found, and connections between lines must be added
- more comments, use some requires
-etc etc

Goals:
-My goal is not to create the best performing AI financially (I'm not taking part in any challenge), but to create an AI that human players like to play against. So remarks about the gameplay are welcome.
-Second goal: To improve my Object Oriention skills. I am pretty experienced in plain C programming, but in OO programming I consider myself a novice. So any comments on how to improve the OO design would be highly appreciated, I might learn a thing or two. And the best way to learn is to start doing it.

Licence:
Don't know much about that, GNU GPL is fine I think. Meaning: feel free to use or modify any of my code ( a link would be nice ), or better, improve and republish it. I think it is be possible to create a nice AI by the OTTD community, using the best open source practices.
I thank TrueLight and Zuu: I re-used some functions of Wright and Clueless ( if that's a problem, I'll rewrite them, and yeah, I know, I should have asked beforehand :mrgreen: )

The last version is available here: http://www.tt-forums.net/viewtopic.php?p=764906#p764906 , don't use the ones below anymore, they're obsolete because of API changes

Train support test version: http://www.tt-forums.net/viewtopic.php?p=787094#p787094
Attachments
Convoy.tar
Convoy v1.1
(40 KiB) Downloaded 3123 times
Convoy.tar
(30 KiB) Downloaded 984 times
Last edited by GeekToo on 05 May 2009 19:30, edited 19 times in total.

Mchl
Director
Director
Posts: 611
Joined: 05 Jan 2007 15:50
Location: Poland
Contact:

Re: NoAI Branch - An AI Framework

Post by Mchl » 24 May 2008 13:09

GeekToo wrote:
TrueLight wrote:[
Now show us your AI and let us enjoy the moment too :)
OK, here it is: Convoy (the bus loving AI)
Performs quite well actually.
It does have a tendency to buy too much buses per line. It seems that it buys as much of them, as it is necessary to transport expected passengers available. It doesn't take into account, that bus stations have limited throughput. It results in bus queues ob both ends of line, which isn't very economical i suppose.

And I got one SQ error so far:
NoAI wrote: dbg: [ai] [3] Your script made an error: the index '0' does not exist
dbg: [ai] [3]
dbg: [ai] [3] *FUNCTION [ManageVehicles()] convoy/main.nut line [977]
dbg: [ai] [3] *FUNCTION [Start()] convoy/main.nut line [866]
dbg: [ai] [3]
dbg: [ai] [3] [@ITERATOR@] 17
dbg: [ai] [3] [line_it] INSTANCE
dbg: [ai] [3] [@INDEX@] 16
dbg: [ai] [3] [this] INSTANCE
dbg: [ai] [3] 31200
dbg: [ai] [3] [S]
  • INSTANCE
    dbg: [ai] [3] [S] [this] INSTANCE


--edit--
And another one (same game)
NoAI wrote: dbg: [ai] [4] [S] Your script made an error: the index '0' does not exist
dbg: [ai] [4] [S]
dbg: [ai] [4] [S] *FUNCTION [ManageVehicles()] convoy/main.nut line [977]
dbg: [ai] [4] [S] *FUNCTION [Start()] convoy/main.nut line [866]
dbg: [ai] [4] [S]
dbg: [ai] [4] [S] [@ITERATOR@] 16
dbg: [ai] [4] [S] [line_it] INSTANCE
dbg: [ai] [4] [S] [@INDEX@] 15
dbg: [ai] [4] [S] [this] INSTANCE
dbg: [ai] [4] [S] 25600
dbg: [ai] [4] [S]
  • INSTANCE
    dbg: [ai] [4] [S] [this] INSTANCE


In both cases it was after '[INFO] Extra buses needed'

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 » 24 May 2008 21:04

GeekToo wrote:I thank TrueLight and Zuu: I re-used some functions of Wright and Clueless ( if that's a problem, I'll rewrite them, and yeah, I know, I should have asked beforehand :mrgreen: )
Sure, use what you find usefull. Glad you found use for some of the code I written. Even if some parts of it is rather outdated, as it was written about a year ago except for being brought up date to the extent that it runs a few times. The ManageLoan function looks familiar, do you remember any other parts you've used?


So actually its time to say happy birthday to NoAI. This thread was started 13 March last year. But then Truelight, Rubidium and possible some more of the devs have spent time on NoAI before it was announced. But I say happy late birth day NoAI :bow: :D
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

User avatar
GeekToo
President
President
Posts: 950
Joined: 03 Jun 2007 22:22

Re: NoAI Branch - An AI Framework

Post by GeekToo » 25 May 2008 00:06

Finaldeath wrote:It just for some reason only used 3 of it's built routes and swarmed them with buses, which is a bit odd, when it had 100,000 in the bank (with still a 510,000 loan that is)
I changed the code, so half the amount of buses will go to one town, and the other half go to the other. About the issue that lines are not used, a savegame or scenario would be nice.

Mchl wrote:
Performs quite well actually.
Thanks
Mchl wrote: It does have a tendency to buy too much buses per line. It seems that it buys as much of them, as it is necessary to transport expected passengers available. It doesn't take into account, that bus stations have limited throughput. It results in bus queues ob both ends of line, which isn't very economical i suppose.
Like I said above, I've now changed the code, so buses will be sent to both towns. The queuing is alright I guess, as long as the complete road is not filled, the buses do queue the first time, but once all buses have completed their route, the distance they keep is optimal.
Mchl wrote: dbg: [ai] [3] Your script made an error: the index '0' does not exist
dbg: [ai] [3]
dbg: [ai] [3] *FUNCTION [ManageVehicles()] convoy/main.nut line [977]


Thanks for the feedback, it was a bug, I've solved it. I'll post an update soon.

Roujin wrote:One thing I noticed is that the AI does not correct its errors.. e.g. if some connection on a slope failed, or it was interrupted by some other player (I tried that on purpose :P)

It just plans its route from A to B, once it found a nice plan, starts to build it, but doesn't check if it actually succeeds at building it. So if you e.g. buy a piece of land somewhere on the route the AI planned, it will build the whole route, minus that tile, then build its buses and so on..

In my opinion it should after finishing building, and from time to time make a check if its route is still connected.


You're right, it's not very fault tolerant at the moment. I spent this night on improving that. Should be better on the next update.
BTW, thanks for updating the wiki, nice template, and I was pleasantly surprised to see Convoy there half a day after publishing.

Zuu wrote: The ManageLoan function looks familiar, do you remember any other parts you've used?

Actually I don't. But I did remember that when I entered this project, and started programming my AI, about half a year ago, Clueless and Wright were the only AI's around, and I studied them, and learned a lot from them. Then I did a patch for the extra zoom level graphics, and did leave my AI for a while. But recently I picked it up again, that's why I don't remember exactly. But, even if my code does not contain much Clueless code any more, the 'thank you' is well deserved, cause it was one of my inspiration sources :) .

Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: NoAI Branch - An AI Framework

Post by Roujin » 25 May 2008 07:42

GeekToo wrote:[...]BTW, thanks for updating the wiki, nice template, and I was pleasantly surprised to see Convoy there half a day after publishing.
[...]
Sure, feel free to add any information :) Actually after downloading your AI, I wanted to download more (that is, all AIs that have been made up until now) and watch them compete. So I started going back in this thread, but got fed up after some pages.. then I thought there should be a place where all released and available AIs are listed.
And the wiki seems the best place for me to do that ;)
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage

Mchl
Director
Director
Posts: 611
Joined: 05 Jan 2007 15:50
Location: Poland
Contact:

Re: NoAI Branch - An AI Framework

Post by Mchl » 25 May 2008 12:57

GeekToo: I've found you a theme song for Convoy ;)
http://www.youtube.com/watch?v=r-VcU89usjM

User avatar
GeekToo
President
President
Posts: 950
Joined: 03 Jun 2007 22:22

Re: NoAI Branch - An AI Framework

Post by GeekToo » 25 May 2008 21:41

I've updated Convoy ( download in my previous post: http://www.tt-forums.net/viewtopic.php?p=693171#p693171)

-solved the bug reported by Mchl ( btw nice theme, we should build an AVI player in OTTD :D )
-improved the way buses take their initial route: one half to one station, the others to the other station. This improves the queing
(reported by Mchl and FinalDeath)
-improved the loan management, it continues building when it has money, instead of waiting a couple of hundred ticks
-added some improvements to the pathfinding
-added error handling during pathfinding, so the trick Roujin reported ( buying land, while the AI is building roads, should be solved).
I've not worked on the route checking yet, so football stadiums still are a problem. I have to find a way to solve this elegantly.

Overall, the performance is about 30 percent better, I ran a test against wright, and managed to stay ahead of it at least 3 years (
then I stopped the test)

Thanks for the feedback guys, keep it coming! There's a lot to improve still

TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1312
Joined: 31 May 2004 09:21

NoAI Branch - An AI Framework

Post by TrueBrain » 08 Jun 2008 23:22

GeekToo wrote:
Or anyway, I pressed the Download link on the wiki page, I assumed it pointed to 1.1
Depends on when you pressed it, I updated the link yesterday or friday
Well, I downloaded it a few hours ago, so I had the latest ;)
The only thing necessary for the triumph of evil is for good men to do nothing.

User avatar
GeekToo
President
President
Posts: 950
Joined: 03 Jun 2007 22:22

Convoy, a Road AI

Post by GeekToo » 11 Jun 2008 22:29

Update of Convoy:

Recent developments ( especially the different behaviour of IsBuildable ) did make the pathfinding of the previous Convoys pretty useless ( as is: not able to find a route ). I tried integrating the BinHeap of the library, as it was better coded than my version ( that is, being a much more pure Container class), but unfortunately, the performance was a lot worse than in my previous Convoy version. Main reason: the Exists function, which does compare a complete node. Suggestion to the devs: add an id to the Insert parameter list.
So for now, I still use my own BinHeap.

Lots of things have improved since the previous version, and I realise lots of things still have to be done.
Attachments
Convoy.tar
(40 KiB) Downloaded 278 times

TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1312
Joined: 31 May 2004 09:21

Re: NoAI Branch - An AI Framework

Post by TrueBrain » 12 Jun 2008 11:21

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 » 12 Jun 2008 11:43

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
paullb
Traffic Manager
Traffic Manager
Posts: 129
Joined: 19 May 2008 13:11

Re: Convoy- a Road AI

Post by paullb » 15 Jun 2008 23:27

I was running Convoy against my bus-based AI, Jinjaba (Jinjaba Is Not Just Another Bus AI) and I was neck-and-neck with Convoy for overall score.

However, despite building significantly less busses, I was much more profitable. As a result, I think you might have too many busses on your routes. See attached.
Attachments
Unnamed, 3rd Nov 1970.png
(42.16 KiB) Downloaded 303 times

TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1312
Joined: 31 May 2004 09:21

Re: Convoy- a Road AI

Post by TrueBrain » 16 Jun 2008 00:09

paullb wrote:I was running Convoy against my bus-based AI, Jinjaba (Jinjaba Is Not Just Another Bus AI) and I was neck-and-neck with Convoy for overall score.

However, despite building significantly less busses, I was much more profitable. As a result, I think you might have too many busses on your routes. See attached.
Beautiful name for an AI, really :) Very nice ;) Either way, if you want your AI battling in the tournament system, but want to keep your code private, feel free to PM me the code. I will never give out any part of the source without your explicit permission. Might be nice to see how it does against all others :)
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: Convoy- a Road AI

Post by wilco_moerman » 16 Jun 2008 13:45

I noticed that Convoy has a peculiar bug. Sometimes if a large and a small* town are close by, and Convoy tries to connect both, then the following can happen:

suppose A is a small town, B is a big town and the distance between them is 13, then Convoy tries to build a bus station in A, but it check all tiles within a square of 30 for highest acceptance (15 tiles in all directions). But the highest acceptance in that square is actually in town B[/b] because it is bigger! So it builds a station in B (while thinking it is building it in A) then tries to connect this new station with the exit point in A, which then fails, and then tries to build a station in B, which also fails because there is already a station too close by.

I noticed this one when I tried to figure out why a certain line couldn't be built. My debug code said that building a station in B had failed, but when I looked at the map, there actually was a station in B, but no station in A. After some pondering I came up with the above explanation, and a suitable fix (valuate the list for potential bus station tiles with IsWithinTownInfuluence of town A)


-------------------
* I modified Convoy a bit for testing, and let it connect two nearby towns without taking into account the populations. But if it did, it would just take longer for the same bug to occur.
Nunc dimittis servum tuum Domine secundum verbum tuum in pace

wilco_moerman
Engineer
Engineer
Posts: 70
Joined: 05 Jun 2008 15:51

Re: Convoy- a Road AI

Post by wilco_moerman » 16 Jun 2008 13:47

TrueLight wrote:(..)
Either way, if you want your AI battling in the tournament system, but want to keep your code private, feel free to PM me the code. I will never give out any part of the source without your explicit permission. Might be nice to see how it does against all others :)
You don't happen to participate in the tjip-challenge yourself? :D If I have a rudimentary AI in the next few weeks, I might want to try it in the tournament without giving away its "secrets"
Nunc dimittis servum tuum Domine secundum verbum tuum in pace

TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1312
Joined: 31 May 2004 09:21

Re: Convoy- a Road AI

Post by TrueBrain » 16 Jun 2008 13:57

wilco_moerman wrote:
TrueLight wrote:(..)
Either way, if you want your AI battling in the tournament system, but want to keep your code private, feel free to PM me the code. I will never give out any part of the source without your explicit permission. Might be nice to see how it does against all others :)
You don't happen to participate in the tjip-challenge yourself? :D If I have a rudimentary AI in the next few weeks, I might want to try it in the tournament without giving away its "secrets"
I already stated that in an other topic, both Rubidium and I do not participate in the TJIP challenge, for well, exactly this reason :) So we assure you that your source-code would be kept very private, and never be shared without your approval. Screenshots of the minimap how ever, will be made, so if you don't want to share that info, I guess you are out of luck ;)

Ps: our tournament system in no way represent the system TJIP might be using, so a win on our tournament system doesn't guarantee anything on the TJIP challenge ;) "behaalde resultaten uit het verleden bieden geen garantie voor de toekomst" (sorry of lack of translation :))
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: Convoy- a Road AI

Post by wilco_moerman » 16 Jun 2008 14:02

TrueLight wrote:(..)

I already stated that in an other topic, both Rubidium and I do not participate in the TJIP challenge, for well, exactly this reason :)
must have missed that one.
So we assure you that your source-code would be kept very private, and never be shared without your approval. Screenshots of the minimap how ever, will be made, so if you don't want to share that info, I guess you are out of luck ;)
I can't imagine why... but perhaps someone will create an AI which reveals tactical information in the minimap? We will see :)
Ps: our tournament system in no way represent the system TJIP might be using, so a win on our tournament system doesn't guarantee anything on the TJIP challenge ;)
but it is good to know at least something about the strength of my AI
"behaalde resultaten uit het verleden bieden geen garantie voor de toekomst" (sorry of lack of translation :))
is goed hoor, ik zal er rekening mee houden 8)
Nunc dimittis servum tuum Domine secundum verbum tuum in pace

reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: Convoy- a Road AI

Post by reylas » 16 Jun 2008 14:46

wilco_moerman wrote: After some pondering I came up with the above explanation, and a suitable fix (valuate the list for potential bus station tiles with IsWithinTownInfuluence of town A)

That is the problem. My AI has that problem as well, and I asked that question. IsWithinTownInfluence will still be valid in townA even though it is closer (or attached to a road) in townB. Only way I know around that now is to have an IsConnected private function that checks if there is a path.

MarkS

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

Re: Convoy- a Road AI

Post by Ralph » 16 Jun 2008 15:44

reylas wrote:
wilco_moerman wrote: After some pondering I came up with the above explanation, and a suitable fix (valuate the list for potential bus station tiles with IsWithinTownInfuluence of town A)

That is the problem. My AI has that problem as well, and I asked that question. IsWithinTownInfluence will still be valid in townA even though it is closer (or attached to a road) in townB. Only way I know around that now is to have an IsConnected private function that checks if there is a path.

MarkS
I solved this problem by staring on the town tile then adding all road tiles that are in the towns influence and their adjacent tiles, then choosing one of these to build a but stop on. So far it has always worked, even when towns are already connected by another player. Only disadvantage is its probably a bit more expensive than just using a large rectangle around the town.

User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: Convoy- a Road AI

Post by Zutty » 16 Jun 2008 16:13

reylas wrote:
wilco_moerman wrote: After some pondering I came up with the above explanation, and a suitable fix (valuate the list for potential bus station tiles with IsWithinTownInfuluence of town A)

That is the problem. My AI has that problem as well, and I asked that question. IsWithinTownInfluence will still be valid in townA even though it is closer (or attached to a road) in townB. Only way I know around that now is to have an IsConnected private function that checks if there is a path.

MarkS
IsWithinTownInfluence seems to work fine for me.

Ralph - I think your solution sounds better to me, as it will allow for larger towns.
PathZilla - A networking AI - Now with tram support.

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 2 guests