GithubHelp home page GithubHelp logo

Comments (6)

bgrins avatar bgrins commented on August 21, 2024

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.

papayaah avatar papayaah commented on August 21, 2024

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.

bgrins avatar bgrins commented on August 21, 2024

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.

papayaah avatar papayaah commented on August 21, 2024

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.

bgrins avatar bgrins commented on August 21, 2024

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.

papayaah avatar papayaah commented on August 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.