Skip to content
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

[Feature] Node cost #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

wlfio
Copy link

@wlfio wlfio commented Aug 24, 2020

Whilst working on my own project i found i wanted to include a cost into node, so that the pathing would avoid them if possible.

So I have implemented it and will let you decide if you want it. (this also addresses issue #14)

I have implemented it so that it is non breaking, as it only enables if the developer sets a previously non existant option.

0 = walkable
2 = walkable but not prefered
5 = not walkable

let myMatrix = [
  [0, 0, 2, 2, 2, 2, 0, 0],
  [0, 0, 2, 2, 2, 2, 0, 5],
  [0, 0, 5, 5, 0, 5, 5, 0],
  [0, 0, 5, 0, 0, 0, 5, 0],
  [0, 0, 0, 0, 0, 0, 5, 0],
  [5, 5, 5, 0, 5, 0, 5, 0],
  [0, 0, 0, 0, 5, 0, 5, 0],
  [0, 0, 5, 0, 0, 0, 0, 0]
];

this.aStarInstance = new AStarFinder({
  grid: {
    matrix: myMatrix,
    maxCost: 5,
  }
});

Examples:

I wanted the wires to avoid blocking the pins on the chips if possible to make it easier for later wire to path to them.

2020-08-24_00-45-35_firefox

So with my cost feature i added an extra cost to the nodes just above and below a chip. now it paths like this.

2020-08-24_00-44-50_firefox

But if it MUST go into a space because going around is impossible or far too costly it will

2020-08-24_00-46-04_firefox

Developers using the feature can set their own cost values to make things even les desirable if they wished, this could for instance be used in a game to avoid different types of terrain if possible, unless the path arround is far too long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants