ManevilleF / hexx

Hexagonal tools lib in rust
Apache License 2.0
276 stars 22 forks source link

Pathfinding algorithms should support costs for pairs of adjacent hexes rather than just hexes on their own. #128

Closed william-gooch closed 6 months ago

william-gooch commented 7 months ago

Is your feature request related to a problem? Please describe. I'm attempting to create an implementation of an RPG ruleset which works on hexagonal battlemaps. Each hex of terrain will have a given height, and moving up terrain takes extra movement. Therefore, when trying to find a path, going from lower to higher terrain will cost more movement than moving from higher to lower terrain.

Describe the solution you'd like I think it would be really useful if the a_star and field_of_movement algorithms took in pairs of adjacent hexes (i.e. previous and next hex along the path) to calculate the cost. This would also allow things like walls between hexes, without needing a full hex to act as an obstruction.

Describe alternatives you've considered One solution to the original problem is to just have the terrain height be the cost of a path, but this doesn't really work since it means that moving between levels of equal terrain costs more if it's higher up, rather than only costing the difference.

taylorhadden commented 6 months ago

+1 To this. I'm going to have to roll my own A* on this otherwise.

ManevilleF commented 6 months ago

This would be a good improvement, and easy to implement, I made the algorithms module mostly for example purposes but it would be good to have it fit more general purpose use cases.

I'll open a MR to support that

ManevilleF commented 6 months ago

@william-gooch @taylorhadden Could you check #130 ?