Comments (6)
It should be possible to modify the neighbors function here: https://github.com/bgrins/javascript-astar/blob/master/astar.js#L98
Something like this:
if (diagonals) {
// SW
if(grid[x-1] && grid[x-1][y-1]) {
ret.push(grid[x-1][y-1]);
}
// SE
if(grid[x+1] && grid[x+1][y-1]) {
ret.push(grid[x+1][y-1]);
}
// NW
if(grid[x-1] && grid[x-1][y+1]) {
ret.push(grid[x-1][y+1]);
}
// NE
if(grid[x+1] && grid[x+1][y+1]) {
ret.push(grid[x+1][y+1]);
}
}
If you want to assign different weights to the diagonal paths that would be a different story, but should be doable as well.
Is this what you were thinking of?
from javascript-astar.
i guess so - here's a screenshot: http://d.pr/mCCr
So right now this character just walks NW, NE, SW, SE. I want him to be ablet to move the other 4 directions.
Would just adding your code snippet work right off the bat?
Regarding weight - as long as the character is able to get there utilizing 8 directional movements I'm fine without applying different weights.
On Mar 23, 2012, at 11:33 AM, Brian Grinstead wrote:
It should be possible to modify the neighbors function here: https://github.com/bgrins/javascript-astar/blob/master/astar.js#L98
Something like this:
if (diagonals) {
// SW
if(grid[x-1] && grid[x-1][y-1]) {
ret.push(grid[x-1][y-1]);
}// SE
if(grid[x+1] && grid[x+1][y-1]) {
ret.push(grid[x+1][y-1]);
}// NW
if(grid[x-1] && grid[x-1][y+1]) {
ret.push(grid[x-1][y+1]);
}// NE
if(grid[x+1] && grid[x+1][y+1]) {
ret.push(grid[x+1][y+1]);
}}
If you want to assign different weights to the diagonal paths that would be a different story, but should be doable as well.
Is this what you were thinking of?
Reply to this email directly or view it on GitHub:
#8 (comment)
from javascript-astar.
It might work straight out - I haven't tested that code (I just wrote it up in the preview box), but that idea should be all that you need.
RE: NW, NE, SW, SE - those would be the diagonal directions in a grid like this: http://briangrinstead.com/files/astar/. They would appear to be N S E W in your isometric map because of the angle.
Go ahead and try to add it in just like that and let me know how it works out for you. I wouldn't mind adding it into master as an optional parameter to the search.
from javascript-astar.
Thanks so much for helping out! I wouldn't be trying it out right away yet but if i do, I will make sure to let you know if its working.
On Mar 23, 2012, at 8:43 PM, Brian Grinstead wrote:
It might work straight out - I haven't tested that code (I just wrote it up in the preview box), but that idea should be all that you need.
RE: NW, NE, SW, SE - those would be the diagonal directions in a grid like this: http://briangrinstead.com/files/astar/. They would appear to be N S E W in your isometric map because of the angle.
Go ahead and try to add it in just like that and let me know how it works out for you. I wouldn't mind adding it into master as an optional parameter to the search.
Reply to this email directly or view it on GitHub:
#8 (comment)
from javascript-astar.
This is now in the main branch. Just add a true parameter onto the main search to allow 8 directional movement
astar.search(graph.nodes, start, end, true)
from javascript-astar.
wow thanks so much!
that's very helpful.
On May 7, 2012, at 10:24 PM, Brian Grinstead wrote:
This is now in the main branch. Just add a true parameter onto the main search to allow 8 directional movement
astar.search(graph.nodes, start, end, true)
Reply to this email directly or view it on GitHub:
#8 (comment)
from javascript-astar.
Related Issues (20)
- algorithm fails for a particular case - cell marked with magenta color (PFA image) HOT 2
- Any way to make diagonal paths less free? HOT 6
- A star for the metro HOT 1
- Cannot handle returning to previously visited grid locations HOT 3
- Can't find a path after a few search HOT 3
- Generating new map forgets diagonal path is selected
- Publish to npm HOT 3
- Diagonal heuristic computes square root of 2 every time it is used HOT 1
- Pathing randomly fails after first search. Pathfinder doesn't reset closed nodes after search is complete. HOT 3
- fewest turns HOT 1
- Getting error in browser HOT 2
- performance gains in guarding calls to sinkdown with if (n > 0)? HOT 1
- help!!! Getting error in wechat game HOT 2
- how to design a heuristic function for non-grid unidirectional gragh?
- New Graph is switching x and y values of my array items HOT 1
- the grid[1][2], which number does it correspond to?
- Revert this PR
- Reversed A Star? HOT 2
- Limiting number of squares moved HOT 1
- Grid Array HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from javascript-astar.