MedievalAI (v3)

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
Sir Bob
Traffic Manager
Traffic Manager
Posts: 214
Joined: 07 Oct 2006 09:08
Location: Melbourne, Australia

MedievalAI (v3)

Post by Sir Bob »

Version 3 Released


---------------ORIGINAL POST---------------------

...doesn't work yet.

I am releasing what I have done of my AI so far for the purpose of helping fix a problem that I find a bit strange, but hopefully will be easy to fix.

In my .nut file at line 19, if the second parameter of BuildRoads is the variable declared in line 17 (or 15 for that matter) then it will freeze. If that line (19) is commented out then it works as it should, aside from not building roads.

Any help is appreciated.
Attachments
medievalai.tar
(67 KiB) Downloaded 559 times
Last edited by Sir Bob on 27 Jan 2009 00:06, edited 4 times in total.
Witty Signature!
Image
User avatar
saint
Engineer
Engineer
Posts: 45
Joined: 25 Dec 2005 23:01
Location: Australia

Re: MedievalAI

Post by saint »

There's an issue with your pathfinder somewhere so that should give you a place to start.

You can add the line "AIController.Sleep(1);" to the start of the while loop (line 190ish) so that OpenTTD doesn't lock up completely which should help for testing :wink:
This is my sig
User avatar
Ralph
Engineer
Engineer
Posts: 87
Joined: 21 Jun 2004 15:25

Re: MedievalAI

Post by Ralph »

Looks like an infinite loop in your pathfinder somewhere as the bus stop building works for me.

Edit: Weird, if I crash the pathfinder with an extra statement it builds both bus stops, but only builds one of its allowed to run.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: MedievalAI

Post by Yexo »

In the while loop within your pathfinder you have the following code:

Code: Select all

if(AITile.IsBuildable(i) && !closedList.HasItem(i) || AIRoad.IsRoadTile(i) ) {
This is:
1) Not what you want (If the tile is a road tile and in your closed list it'll still be searched).
2) A non-drive through road station is NOT a road tile and NOT buildable, so you'll never reach your goal tile. Because you have no code to check for a maximum route distance, your pathfinder will search the whole map for your goal tile, and that'll take a while :).

Please debug yourself next time, that can be as easy as adding

Code: Select all

			AIController.Sleep(1);
			AISign.BuildSign(currNode.location, ""+nextPos);
As the first lines in your while loop. You'd have spotted easily that the pathfinder found all tiles around the goal station but not the station itself.
reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: MedievalAI

Post by reylas »

Yexo wrote:In the while loop within your pathfinder you have the following code:

Code: Select all

if(AITile.IsBuildable(i) && !closedList.HasItem(i) || AIRoad.IsRoadTile(i) ) {
This is:
1) Not what you want (If the tile is a road tile and in your closed list it'll still be searched).
2) A non-drive through road station is NOT a road tile and NOT buildable, so you'll never reach your goal tile. Because you have no code to check for a maximum route distance, your pathfinder will search the whole map for your goal tile, and that'll take a while :).

Please debug yourself next time, that can be as easy as adding

Code: Select all

			AIController.Sleep(1);
			AISign.BuildSign(currNode.location, ""+nextPos);
As the first lines in your while loop. You'd have spotted easily that the pathfinder found all tiles around the goal station but not the station itself.
Another IsRoadTile on a station casualty I see. :) That got me as well, how I do it is walk the roads using IsRoadTile, but when I check the adjacent tiles for tiles to add to the open list, just check for IsRoadStationTile.

Or, If you know the tile of the location you are trying to go to or from, just check to see if you are trying to add that tile. No need to care about if a station is on it or not. You know it is since you built one there.

MarkS.
User avatar
Sir Bob
Traffic Manager
Traffic Manager
Posts: 214
Joined: 07 Oct 2006 09:08
Location: Melbourne, Australia

Re: MedievalAI

Post by Sir Bob »

OK thanks for the help guys, problem solved :) (if you're wondering, I just changed the start and end tiles to the tile outside the bus stop, I know this may not be the ideal solution, but I'm improving it bit by bit :)))

Stay tuned for a working release soon (hopefully).

(BTW, I do generally debug myself, this one just confused me a bit because that code had been working previously)
Witty Signature!
Image
User avatar
Sir Bob
Traffic Manager
Traffic Manager
Posts: 214
Joined: 07 Oct 2006 09:08
Location: Melbourne, Australia

Re: MedievalAI

Post by Sir Bob »

OK, there is now a working version of MedievalAI in the first post (for tournament inclusion please :))). I'm not expecting it to really challenge to any of the others yet, just want to see where it's at :).
Witty Signature!
Image
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: MedievalAI (v1.0)

Post by Zutty »

Nice work Sir Bob.

It looks like your using your own pathfinder, and I notice there is something in there to detect the current build-on-slopes setting. This is something that I really need to implement, but at the moment I'm using AIRoad.CanBuildConnectedRoadPartsHere(), which is a total cop-out! I couldn't get my own slope detectory thing working very well, so I just switched it off.

Do you have any tips? :)
PathZilla - A networking AI - Now with tram support.
User avatar
Sir Bob
Traffic Manager
Traffic Manager
Posts: 214
Joined: 07 Oct 2006 09:08
Location: Melbourne, Australia

Re: MedievalAI (v1.0)

Post by Sir Bob »

Do you mean with detecting build-on-slopes? For that I used:

Code: Select all

	if(AIGameSettings.IsValid("construction.build_on_slopes") && 
          AIGameSettings.GetValue("construction.build_on_slopes")) {
		AILog.Info("Can Build on Slopes");
		gameSettings.buildSlopes = true;
	}
If you ment with slope detection, I did something similar to you but not as neat :P. I check for which direction I'm coming from then what the next slope is. I actually had forgotten about my slopes a bit so this isn't implemented, but after checking for that I'm going to limit the directions it can turn in so as to avoid any problems with foundations and such. In fact you've just inspired me to fix up mine a bit!

EDIT: Forgot I had a new version.
Attachments
medievalai.tar
(103.5 KiB) Downloaded 214 times
Witty Signature!
Image
User avatar
Sir Bob
Traffic Manager
Traffic Manager
Posts: 214
Joined: 07 Oct 2006 09:08
Location: Melbourne, Australia

Re: MedievalAI (v2.0)

Post by Sir Bob »

Hey All!

Thought I should get a new version of MedievalAI out. (Available here and in-game content downloader)

At the moment the only major bug I know of is that you can only have one instance of it at a time, and I have no idea why. (Any idea why this might be devs?)

Sir Bob
Attachments
medievalai.tar
MedievalAI v2
(182 KiB) Downloaded 182 times
Witty Signature!
Image
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: MedievalAI (v2.0)

Post by Yexo »

Sir Bob wrote:At the moment the only major bug I know of is that you can only have one instance of it at a time, and I have no idea why. (Any idea why this might be devs?)
Yes, it's because of this code in your start function:

Code: Select all

	if (!AICompany.SetName("MedievalAI #1")) 
	{
		for(local i = 0; ; i++)
		{
		
		}
	}
User avatar
Sir Bob
Traffic Manager
Traffic Manager
Posts: 214
Joined: 07 Oct 2006 09:08
Location: Melbourne, Australia

Re: MedievalAI (v2.0)

Post by Sir Bob »

Thanks Yexo, forgot to finish that function. :oops:

New Version 2.
Attachments
medievalai.tar
New Version.
(180.5 KiB) Downloaded 185 times
Witty Signature!
Image
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: MedievalAI (v2.0)

Post by Roujin »

Regarding the content server, you may want to stick to the tags the other AI writers agreed on (i.e. singular: "bus", "truck" instead of "buses", "trucks"). ;)

It doesn't have a real purpose (afaik) right now, but I can imagine a filter option for that list to display only Items containing those keywords.. in fact I'm just gonna suggest this in the content service thread.
* @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
User avatar
Sir Bob
Traffic Manager
Traffic Manager
Posts: 214
Joined: 07 Oct 2006 09:08
Location: Melbourne, Australia

Re: MedievalAI (v2.0)

Post by Sir Bob »

Done. :wink:
Witty Signature!
Image
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: MedievalAI (v2.0)

Post by Roujin »

In a game with different AIs I just started, MedievalAI built two stations that don't fit together (A truck station near a forest, and a bus station in a town), and only outputs some cryptic messages in the AI Debug window...
Unnamed, 1951-02-04.png
(183.52 KiB) Downloaded 92 times

edit: I restarted it, and this time he built a faulty bus line again, but then a working truck line. This is the output of when he made the faulty bus line (only one bus stop)
Unnamed, 1951-03-18.png
(185.4 KiB) Downloaded 76 times
edit: after some time it again outputs stuff like in the first screenshot. Unfortunately I didn't see what it wrote before starting to write this "aT:C ..." stuff
* @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
User avatar
Sir Bob
Traffic Manager
Traffic Manager
Posts: 214
Joined: 07 Oct 2006 09:08
Location: Melbourne, Australia

Re: MedievalAI (v2.0)

Post by Sir Bob »

Thanks Roujin, I'm trying to fix that at the moment :)
Witty Signature!
Image
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: MedievalAI (v2.0)

Post by Zutty »

Hi Sir Bob,

Nice AI, though I note it seems not to be compatible with articulated road vehicles (using eGRVTS)...
mdvl-arvbug.png
mdvl-arvbug.png (221.75 KiB) Viewed 785 times
You can use AIEngine.IsArticulated() or build DTRSs to prevent this.

I also got a rather odd problem where the AI seemed to enter a very intensive, possibly infinte loop. The whiole game became very laggy and I saw this in the debug window...
mdvl-1965-bug.png
(289.84 KiB) Downloaded 65 times
mdvl-1965.sav
Saved in r15235 using MedievalAI v2 w/ av8
(93.5 KiB) Downloaded 167 times
It looks to me like its trying to connect that bus stop to the road but can;t because either A) the slopes are wrong or B) those buses are in the way.

Hope this helps :)
PathZilla - A networking AI - Now with tram support.
User avatar
Sir Bob
Traffic Manager
Traffic Manager
Posts: 214
Joined: 07 Oct 2006 09:08
Location: Melbourne, Australia

Re: MedievalAI (v2.0)

Post by Sir Bob »

Thanks for the feedback Zutty.

I've managed to fix the looping bug in my local version and I'm going to go back and double check my slope detection.

I'll use those checks to make sure I don't build aRV's just yet.

Looks like we'll need a new release soon 8)

Sir Bob
Witty Signature!
Image
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: MedievalAI (v2.0)

Post by TrueBrain »

Code: Select all

dbg: [ai] [1] [S] Your script made an error: division by zero
dbg: [ai] [1] [S] CALLSTACK
dbg: [ai] [1] [S] *FUNCTION [CheckForVehiclesNeeded()] MedievalAI.2.tar/medievalai.2/Vehicles.nut line [152]
dbg: [ai] [1] [S] *FUNCTION [Start()] MedievalAI.2.tar/medievalai.2/main.nut line [102]
Just so you know :)
The only thing necessary for the triumph of evil is for good men to do nothing.
User avatar
Sir Bob
Traffic Manager
Traffic Manager
Posts: 214
Joined: 07 Oct 2006 09:08
Location: Melbourne, Australia

Re: MedievalAI (v2.0)

Post by Sir Bob »

Got that one too :wink:
Witty Signature!
Image
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 6 guests