So I've been trying to plan out a turn-based strategy game, and was thinking about unit movement, with suggestion options to a player and to handle a computer player's choices. I was thinking of using a simple A* method to find the shortest route to the desired space. Since a space can be advantageous or problematic, would just adding an extra variable to the heuristic help in avoiding certain regions and moving towards others? For example, assuming a unit can move say 10 spaces a turn, and units could potentially be hiding in specific terrain, a unit would want to walk around the terrain a unit can hide in (like woods), so they don't run into a dangerous space. Would just rating the movement cost higher for that space be enough?
Pathfinding in a TBS
Probably, although they would rarely take a shortcut through such terrain then, choosing to take the long way around. If the target space is in the terrain, they will probably search a much larger number of spaces before they find the correct route as well. Maybe you want to adjust the terrain cost based on how many dangerous units are available to the opponent that can use the cover?
The current idea is I have a map that has a few terrain elements units can hide in during FoW. I'm trying to come up with a way to traverse around those spaces, instead of walking through them (walking through could trigger either a surprise attack or a full halt of the unit that is moving). Enemy unit count and units able to hide in that terrain is not known.
Well yeah, just give the terrain a high movement cost then, they will avoid it then if there is a less expensive route available.
If the goal space is inside that terrain though you probably want to reduce the movement cost penalty for the terrain of that type which is connected to the goal?
I think a function that creates a "terrain evaluation" would work for adding an additional value to the movement cost. Keep the terrain danger value but add in a negative due to it being a goal space.
Thanks for the advice. I'll have to see how things pan out as I go.
Don't reduce the value of all the terrain that is the same type as the goal though... either the terrain of the same type that is connected to the goal (floodfill), or maybe based on the distance from the goal as well, so you try to path through as little terrain of that type as possible to reach the goal.
Reducing just the goal space and no others is useless since if there is a finite cost the A* algorithm will find the path to the goal; it will just search more and more nodes trying to find it. You probably want to give a negligible cost to all spaces right next to the goal though so if you are right next to it in your search you go that way first.
Reducing just the goal space and no others is useless since if there is a finite cost the A* algorithm will find the path to the goal; it will just search more and more nodes trying to find it. You probably want to give a negligible cost to all spaces right next to the goal though so if you are right next to it in your search you go that way first.
That's a good point. I guess I wasn't thinking that part through all the way. That's why we plan things out, right?