A* : Clipping with variable cost

Started by
7 comments, last by DauntlessCrowd 18 years, 8 months ago
Hi, again, In A*, with clipping (moving diagonally) enabled, how can you calculate the cost for a tile with a variable cost? Non variable cost: Move up/down/left/right: cost = 1.414 diagonally: cost = ??; Is it like the cost + .414 or something? Thx in advance, Dauntless
Advertisement
What would you make the cost in your game? In order to do pathfinding you need to model the actual rules of your system. In other words, this isn't an AI problem, this a game rule problem.
Uhm, standard cost = 1, other costs can be specified by the user... (I'm making a 'universal' A*, which other people can use...)
Then you'll have to let the user specify. Some people may want to use 1.4 times the cost of the target square, some may use 1.5, some may specify an average of the two squares, and some may disallow diagonal movement altogether.

Again, this isn't a decision that should be made by the path-finder, this is a game rule decision.
I had decided to use 1.414 (sqrt(2)) , but I was just wondering how exactly i had to implement it. But I got it now, thanx for your help :).

Ps: there IS an option to turn clipping on or off :)
Simply have the user define a cost function given an interface you specify... and within your code, utilise a function pointer of the appropriate type to call that cost function. That way, your user can define any cost function they like. All you care about is the number they return.
Now i did it like this: multiply the cost of the node by 1.414 if it's diagonal. But you're saying that it's better if I give the user the ability to change that number?
Not only to change the number; as Timkin said, you should allow the user to enter a custom cost function/functor with access to the relevant information. The cost may depend on an arbitrary number of factors (for example terrain, weather, lighting, enemy movements, etc) - you can't take them all into account and hardcode them into your engine. The golden rule of libraries is to allow as much customization as possible.
Quote:Original post by Sharlin
Not only to change the number; as Timkin said, you should allow the user to enter a custom cost function/functor with access to the relevant information. The cost may depend on an arbitrary number of factors (for example terrain, weather, lighting, enemy movements, etc) - you can't take them all into account and hardcode them into your engine. The golden rule of libraries is to allow as much customization as possible.

The way it is now, people can set their own cost for evry node + set the extra cost for going diagonal... Is this enough? The user CAN make his own cost: he calculates it and assigns it to a tile using setCost();

Or isn't this enough? The library is also "opensource", zo anyone can change it if they want...

This topic is closed to new replies.

Advertisement