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 » 29 Jun 2008 11:03

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 478 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 » 29 Jun 2008 11:44

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 » 29 Jun 2008 11:56

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: 3653
Joined: 20 Dec 2007 12:49

Re: MedievalAI

Post by Yexo » 29 Jun 2008 12:03

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 » 29 Jun 2008 13:24

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 » 30 Jun 2008 01:27

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 » 14 Aug 2008 07:25

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 » 15 Aug 2008 10:56

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 » 15 Aug 2008 11:21

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 145 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 » 23 Jan 2009 03:35

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 102 times
Witty Signature!
Image

Yexo
Tycoon
Tycoon
Posts: 3653
Joined: 20 Dec 2007 12:49

Re: MedievalAI (v2.0)

Post by Yexo » 23 Jan 2009 08:45

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 » 23 Jan 2009 11:52

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

New Version 2.
Attachments
medievalai.tar
New Version.
(180.5 KiB) Downloaded 107 times
Witty Signature!
Image

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

Re: MedievalAI (v2.0)

Post by Roujin » 23 Jan 2009 12:31

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 » 23 Jan 2009 23:25

Done. :wink:
Witty Signature!
Image

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

Re: MedievalAI (v2.0)

Post by Roujin » 24 Jan 2009 11:42

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 » 24 Jan 2009 12:18

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 » 24 Jan 2009 13:58

Hi Sir Bob,

Nice AI, though I note it seems not to be compatible with articulated road vehicles (using eGRVTS)...
mdvl-arvbug.png
(221.75 KiB) Downloaded 67 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 94 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 » 24 Jan 2009 14:05

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: 1312
Joined: 31 May 2004 09:21

Re: MedievalAI (v2.0)

Post by TrueBrain » 24 Jan 2009 15:47

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 » 24 Jan 2009 22:52

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 4 guests