Page 1 of 2

MedievalAI (v3)

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

Re: MedievalAI

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

Re: MedievalAI

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

Re: MedievalAI

Posted: 29 Jun 2008 12:03
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.

Re: MedievalAI

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

Re: MedievalAI

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

Re: MedievalAI

Posted: 14 Aug 2008 07:25
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 :).

Re: MedievalAI (v1.0)

Posted: 15 Aug 2008 10:56
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? :)

Re: MedievalAI (v1.0)

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

Re: MedievalAI (v2.0)

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

Re: MedievalAI (v2.0)

Posted: 23 Jan 2009 08:45
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++)
		{
		
		}
	}

Re: MedievalAI (v2.0)

Posted: 23 Jan 2009 11:52
by Sir Bob
Thanks Yexo, forgot to finish that function. :oops:

New Version 2.

Re: MedievalAI (v2.0)

Posted: 23 Jan 2009 12:31
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.

Re: MedievalAI (v2.0)

Posted: 23 Jan 2009 23:25
by Sir Bob
Done. :wink:

Re: MedievalAI (v2.0)

Posted: 24 Jan 2009 11:42
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

Re: MedievalAI (v2.0)

Posted: 24 Jan 2009 12:18
by Sir Bob
Thanks Roujin, I'm trying to fix that at the moment :)

Re: MedievalAI (v2.0)

Posted: 24 Jan 2009 13:58
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 1898 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 219 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 :)

Re: MedievalAI (v2.0)

Posted: 24 Jan 2009 14:05
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

Re: MedievalAI (v2.0)

Posted: 24 Jan 2009 15:47
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 :)

Re: MedievalAI (v2.0)

Posted: 24 Jan 2009 22:52
by Sir Bob
Got that one too :wink: