Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7605931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:17:22+00:00 2026-05-31T00:17:22+00:00

I am writing a cost path script for use on hexagonal maps. Currently I

  • 0

I am writing a cost path script for use on hexagonal maps. Currently I am in the “learning how to walk” phase of development.

In general terms the code works. I can reliably get from A to B. However, consider the following map:

enter image description here

Both the sequence 0406 -> 0405 -> 0505 and 0406 -> 0506 -> 0505 are valid. I would like to traverse and output BOTH paths.

My code follows:

public function walkMap($origCol, $origRow, $destCol, $destRow) {
    $curRow = $origRow;
    $curCol = $origCol;
    while (($curRow != $destRow) || ($curCol != $destCol)) {
        $newRow = self::getNextMove($curRow,$destRow);
        if ($newRow == $curRow) {
            $curCol = self::getNextMove($curCol,$destCol);
        } else {
            $curRow = $newRow;
        }
    }
}

private function getNextMove($cur,$dest) {
    if ($cur < $dest) {
        ++$cur;
    } else if ($cur > $dest) {
        --$cur;
    }
    return $cur;
}

My desired result is a numeric array of step => hexCoord showing the path taken. But I’m not sure how to adopt the above working code to intelligently branch, and having done that, how best to shape the output data structure…

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:17:23+00:00Added an answer on May 31, 2026 at 12:17 am

    I noticed that, at the moment, your path choice is simply “get to the right row, then get to the right column.” I realize that you’re still getting started, but you might want to think ahead about how you want to work cost into your paths and let that tell you about your data structure.

    For example, you can use Dijkstra’s algorithm to mark each point on your map with the least cost from that point to a given destination. Finding a path is then a matter of picking an origin and repeatedly moving to the neighboring hex with the least cost, building the path array that you want as you go. If there are two optimal paths at any point, you’ll see that as a hex with two minimally-cheap neighbors — you’d make a new copy of the path array for each and complete them independently. Taking that approach, you’d work with (and return) an array of path arrays.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Writing the code for the user authentication portion of a web site (including account
Writing documentation in html requires some code examples. What to do with characters that
I am writing a C program which has to use a 2D array to
Writing Scala code, I regularly encounter cases where I have processor functions that operate
I am writing code for a UPnP device to announce itself. I have no
I'm writing code to emulate a unit of work pattern in my winforms over
I'm writing some code that needs to work against an array of different database
I'm writing some code to handle an application invitation request (FB.ui, method = apprequests),
I'm currently writing a program where I need to run many simulations and speed
Possible Duplicate: Why not use Double or Float to represent currency? I'm writing a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.