Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Mon Dec 17, 2018 4:04 am

All times are UTC




Post new topic  Reply to topic  [ 16 posts ] 
Author Message
PostPosted: Mon Aug 10, 2009 11:57 am 
Offline
Chairman
Chairman

Joined: Sat Jul 18, 2009 5:54 pm
Posts: 888
Hi all,
Recently I've been trying to make an AI on my own. My (far-to-achieve) ambition is to make some sort of remake of the old AI, I think that should be quite easy compared to building a really intelligent AI.
I'm a real amateur in programming, I use the library pathfinder according to the guidelines at http://wiki.openttd.org/AI:RoadPathfinder. In fact, I just copied the code. :)
So, my questions:
1) Is there some way to add a penalty for road-rail level crossings without modifying the code of the pathfinder?
2) I noticed that my pathfinder is slow compared to other AIs that use the library pathfinder (for example, Convoy and TransAI). So, is there some way to make the pathfinder faster? (again, without modifying the library code) I don't mind if the pathfinder doesn't find the optimal route.
3) How do you know that the pathinder failed to find a path? Is it OK to add a time limit?
I hope I will be able develop the AI for some alpha-release. Currently it chooses a service completely randomly, builds the two truck stations and then connects them todether. The next step for me is to build and start the vehicles. Of course my biggest problem will be exception handling, currently there is almost none.


Top
   
PostPosted: Mon Aug 10, 2009 12:12 pm 
Offline
Tycoon
Tycoon

Joined: Thu Dec 20, 2007 12:49 pm
Posts: 3653
Brumi wrote:
Hi all,
Recently I've been trying to make an AI on my own. My (far-to-achieve) ambition is to make some sort of remake of the old AI, I think that should be quite easy compared to building a really intelligent AI.
I'm a real amateur in programming, I use the library pathfinder according to the guidelines at http://wiki.openttd.org/AI:RoadPathfinder. In fact, I just copied the code. :)
So, my questions:
1) Is there some way to add a penalty for road-rail level crossings without modifying the code of the pathfinder?
Not yet, but a future version of the road pathfinder library will have such a penalty.
Quote:
3) How do you know that the pathinder failed to find a path? Is it OK to add a time limit?
The pathfinder returns false if there is more to search and null if there is no path.
Quote:
I hope I will be able develop the AI for some alpha-release. Currently it chooses a service completely randomly, builds the two truck stations and then connects them todether. The next step for me is to build and start the vehicles. Of course my biggest problem will be exception handling, currently there is almost none.

Good luck with your AI :)


Top
   
PostPosted: Mon Aug 10, 2009 12:15 pm 
Offline
Route Supervisor
Route Supervisor
User avatar

Joined: Fri May 18, 2007 12:47 pm
Posts: 485
Location: Oxford
Hi Brumi and good to see another AI developer.

Brumi wrote:
1) Is there some way to add a penalty for road-rail level crossings without modifying the code of the pathfinder?

Nothing I'm aware of. One thing you could do is ammend your road/rail builder so that when it encounters and existing road or rail it builds a bridge until it's past the offending item. It's not slick, nor very easy, but it's an option.

Brumi wrote:
2) I noticed that my pathfinder is slow compared to other AIs that use the library pathfinder (for example, Convoy and TransAI). So, is there some way to make the pathfinder faster? (again, without modifying the library code) I don't mind if the pathfinder doesn't find the optimal route.

If your and other peoples AI are all using the same library your results will be the same. The only way to speed it up is to run shorter distances with it. The other thought is the while loop you enter into whilst path finding. If it's got any extra tasks that would affect the speed of things.

Brumi wrote:
3) How do you know that the pathinder failed to find a path? Is it OK to add a time limit?

Wiki wrote:
FindPath returns false if it isn't finished with pathfinding. When it's done, it returns either the path it found or null to indicate no route exists.

It's perfectly fine to add a timer. I do the following:
Code:
local counter = 0;
local path = false;
//MAXIMUM_PATH_TRIES is a constant declared in main.nut
while (path == false && counter < MAXIMUM_PATH_TRIES) {
  path = pathfinder.FindPath(100);
  counter++;
  AIController.Sleep(1);
}

if(path == false){
    //Did not find path in time
}
if(path == null){
    //Could not find a path
}

_________________
Real Tycoons do it on Trains!

JAMI: Just Another Moronic Intelligence


Last edited by Xander on Mon Aug 10, 2009 12:19 pm, edited 1 time in total.

Top
   
PostPosted: Mon Aug 10, 2009 12:19 pm 
Offline
Tycoon
Tycoon

Joined: Thu Dec 20, 2007 12:49 pm
Posts: 3653
Xander wrote:
It's perfectly fine to add a timer. I do the following:
I hope that's not a copy/paste of your code, since you never update counter.


Top
   
PostPosted: Mon Aug 10, 2009 12:20 pm 
Offline
Route Supervisor
Route Supervisor
User avatar

Joined: Fri May 18, 2007 12:47 pm
Posts: 485
Location: Oxford
Yexo wrote:
Xander wrote:
It's perfectly fine to add a timer. I do the following:
I hope that's not a copy/paste of your code, since you never update counter.


fixed :P

_________________
Real Tycoons do it on Trains!

JAMI: Just Another Moronic Intelligence


Top
   
PostPosted: Mon Aug 10, 2009 12:29 pm 
Offline
Chairman
Chairman

Joined: Sat Jul 18, 2009 5:54 pm
Posts: 888
Thank you both.
Currently I can't promise anything, but I will try my best :) I'll be studying IT from September and I hope that won't take away all my time, instead it should help a lot (I hope we will learn about A*, I'm really interested in that, but the page on Wikipedia is still very high-level for me).


Top
   
PostPosted: Mon Aug 10, 2009 12:34 pm 
Offline
Route Supervisor
Route Supervisor
User avatar

Joined: Fri May 18, 2007 12:47 pm
Posts: 485
Location: Oxford
Brumi wrote:
Thank you both.
Currently I can't promise anything, but I will try my best :) I'll be studying IT from September and I hope that won't take away all my time, instead it should help a lot (I hope we will learn about A*, I'm really interested in that, but the page on Wikipedia is still very high-level for me).


ICT or Computer Science? What level (university or high school)?

_________________
Real Tycoons do it on Trains!

JAMI: Just Another Moronic Intelligence


Top
   
PostPosted: Mon Aug 10, 2009 12:49 pm 
Offline
Chairman
Chairman

Joined: Sat Jul 18, 2009 5:54 pm
Posts: 888
Xander wrote:
ICT or Computer Science? What level (university or high school)?

er... I don't know how it translates properly into English, something like 'Information Specialist Engineer', but I'm not sure about the branches. I'll be studying it at university.


Top
   
PostPosted: Mon Aug 10, 2009 12:57 pm 
Offline
Route Supervisor
Route Supervisor
User avatar

Joined: Fri May 18, 2007 12:47 pm
Posts: 485
Location: Oxford
Ah that's alright then. Over here we have Computer Science - which is programming and such and Information Communication Technology which is stupid.

You'll probably not cover anything as specialised as A* in your first semester but what you will learn are important theories and practices to use when programming :)

_________________
Real Tycoons do it on Trains!

JAMI: Just Another Moronic Intelligence


Top
   
PostPosted: Mon Aug 10, 2009 4:05 pm 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Fri Dec 19, 2008 5:03 am
Posts: 313
Location: Indonesia
Brumi wrote:
1) Is there some way to add a penalty for road-rail level crossings without modifying the code of the pathfinder?


Code:
import("pathfinder.road", "RoadPathFinder", 3);

class MyRoadPF extends RoadPathFinder {}
function MyRoadPF ::_Cost(path, new_tile, new_direction, self)
{
   local cost = ::RoadPathFinder._Cost(path, new_tile, new_direction, self);
   if (AITile.HasTransportType(new_tile, AITile.TRANSPORT_RAIL)) cost += your_cost;
   return cost;
}


then in your old :
Code:
local pathfinder = RoadPathFinder();

replace with :
Code:
local pathfinder = MyRoadPF();


That is what I've used in Trans :lol:

_________________
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image


Top
   
PostPosted: Tue Aug 11, 2009 4:20 am 
Offline
Tycoon
Tycoon

Joined: Sun Apr 08, 2007 4:07 am
Posts: 1884
hurray for inheritance :)

_________________
* @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


Top
   
PostPosted: Tue Aug 11, 2009 9:01 am 
Offline
Chairman
Chairman

Joined: Sat Jul 18, 2009 5:54 pm
Posts: 888
Thank you! :) I've never thought that it is that easy. I'll try it when I have time.


Top
   
PostPosted: Thu Sep 17, 2009 1:18 pm 
Offline
Chairman
Chairman

Joined: Sat Jul 18, 2009 5:54 pm
Posts: 888
I have a new issue with the road pathfinder:
Attachment:
pathfinder problem.png [36.07 KiB]
Downloaded 39 times

I made a 64x64 scenario with a town, a coal mine and a power station. Then I placed that rail line between the industries. AIs using the library pathfinder (e. g. SimpleAI, TransAI, MogulAI) fail to build a road here, with or without Fanioz's little modification to add a penalty for level crossings. It also failed if I didn't modify the default costs.
Any of you has an idea what causes this? ?(

EDIT: If I raise two little hills by the side of the railway, the pathfinder can find a path.


Top
   
PostPosted: Thu Sep 17, 2009 4:33 pm 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Fri Dec 19, 2008 5:03 am
Posts: 313
Location: Indonesia
It seems, that is because AITile.IsBuildable return false on each rail tile.
AFAIK, road pf3 has been optimized to build bridge on non flat tiles only. Thats why you got a bridge when you made 'hill'.
And with inheritance too, I beleive you can fix this for your AI firstly :D
Edit:
You need to change the behaviour of Road.Neighbours() and Road.GetTunnelsBridges()

_________________
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image


Top
   
PostPosted: Sat Sep 19, 2009 5:30 pm 
Offline
Chairman
Chairman

Joined: Sat Jul 18, 2009 5:54 pm
Posts: 888
Thank you. :)
The only thing I can say that I agree with Roujin:
Roujin wrote:
hurray for inheritance :)


Top
   
PostPosted: Fri Oct 30, 2009 10:37 am 
Offline
Engineer
Engineer

Joined: Sun Oct 25, 2009 9:56 am
Posts: 69
Location: Belgium
I changed the pathfinder library to add an extra cost for building over farm tiles and made a new tar file for it.

But reading this thread I notice I should have used inheritance instead. :) Thanks for the tip!

_________________
--------------------------------------------------
MailAI, a casual postal service for openTTD.
--------------------------------------------------


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 16 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000-2018 phpBB Limited

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2018.
Hosted by Zernebok Hosting.