Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pathfinding doesn't use h(n) #2457

Closed
andretchen0 opened this issue Jul 30, 2023 · 1 comment
Closed

Pathfinding doesn't use h(n) #2457

andretchen0 opened this issue Jul 30, 2023 · 1 comment
Assignees

Comments

@andretchen0
Copy link
Contributor

andretchen0 commented Jul 30, 2023

Meta: Not a bug, per se. Not a feature request. Should this go in "Discussions"?

I'm looking at HexGrid and Hex. Hex carries around a lot of state. One part of the state is f, g, h, pathparent used by pathfinding.

The path finding algo setup is similar to A*. It's got a a small twist for Creature size. The benefit of using A* over another algo (e.g., Djikstra) comes from the use of the heuristic h. From Wikipedia:

A* achieves better performance by using heuristics to guide its search.

But pathfinding.js doesn't actually use h, except to set it to 0. Here's an example for a very brief game (2 rounds, summoning 2 creatures and moving each creature):

Screenshot 2023-07-30 at 18 54 16

~6,000 assignments setting h to 0.

Ultimately, 6,000 unused assignments don't matter unless performance is affected.

But the keeping f, g, h on Hex leads to tightly coupled modules, and extra operations in pathfinding, Hex, and HexGrid to keep those attributes "clean".

On top of that, forcing callers to provide concrete Hexs, a concrete HexGrid, and a creature id isn't ultimately necessary and makes the algo resistant to testing.

So ...

So, I'm going to go ahead and work on a full rewrite here, unless there are objections.

@andretchen0 andretchen0 self-assigned this Jul 30, 2023
@andretchen0 andretchen0 changed the title Pathfinding doesn't use h(n) AStar Pathfinding doesn't use h(n) Jul 30, 2023
@andretchen0 andretchen0 changed the title AStar Pathfinding doesn't use h(n) Pathfinding doesn't use h(n) Jul 31, 2023
@andretchen0
Copy link
Contributor Author

andretchen0 commented Jul 31, 2023

Documenting things here:

HexGrid calls search in pathfinding.ts, but always with coordinates that don't exist in-game – (-2,-2). This essentially runs a shortest path tree algorithm. The algorithm is used to set the value of Hex.g, the cost of the path to get to a particular Hex. Hexs with a g below a certain threshold are then collected into an array and returned.

@FreezingMoon FreezingMoon locked and limited conversation to collaborators Aug 1, 2023
@DreadKnight DreadKnight converted this issue into discussion #2462 Aug 1, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant