Skip to main content
added 270 characters in body
Source Link
Day Trip
  • 75
  • 1
  • 9

I want to code some basic pathfinding for my bot in Java. Below is a 2D grid representation of the 3D world. 0s being the places you can go, and 1s being the places that you cannot go.

int[][] data = {
            {0, 0, 0, 0, 0},
            {0, 0, 1, 0, 1},
            {1, 0, 0, 1, 1},
            {0, 0, 0, 1, 0},
            {1, 1, 0, 0, 1}
    };

How can I write a simple pathfinder in Java, where if I say that I'm currently at (2D coords) and I want to go to (2D coords), it will generate the shortest path there. I don't need a fancy cost system, because each move will have the same cost, and each 1 will have the same danger level. There are already some posts about this online that I've seen, but most of them look a little too overkill for my simple project.

EDIT: The cost can be decided by how many moves are necessary to get to the player. The best path is the shortest; least moves necessary. In the best case scenario, the path finder will return a list of all the coordinates I have to walk on to get to the target.

Thank you for all the help!

I want to code some basic pathfinding for my bot in Java. Below is a 2D grid representation of the 3D world. 0s being the places you can go, and 1s being the places that you cannot go.

int[][] data = {
            {0, 0, 0, 0, 0},
            {0, 0, 1, 0, 1},
            {1, 0, 0, 1, 1},
            {0, 0, 0, 1, 0},
            {1, 1, 0, 0, 1}
    };

How can I write a simple pathfinder in Java, where if I say that I'm currently at (2D coords) and I want to go to (2D coords), it will generate the shortest path there. I don't need a fancy cost system, because each move will have the same cost, and each 1 will have the same danger level. There are already some posts about this online that I've seen, but most of them look a little too overkill for my simple project.

Thank you for all the help!

I want to code some basic pathfinding for my bot in Java. Below is a 2D grid representation of the 3D world. 0s being the places you can go, and 1s being the places that you cannot go.

int[][] data = {
            {0, 0, 0, 0, 0},
            {0, 0, 1, 0, 1},
            {1, 0, 0, 1, 1},
            {0, 0, 0, 1, 0},
            {1, 1, 0, 0, 1}
    };

How can I write a simple pathfinder in Java, where if I say that I'm currently at (2D coords) and I want to go to (2D coords), it will generate the shortest path there. I don't need a fancy cost system, because each move will have the same cost, and each 1 will have the same danger level. There are already some posts about this online that I've seen, but most of them look a little too overkill for my simple project.

EDIT: The cost can be decided by how many moves are necessary to get to the player. The best path is the shortest; least moves necessary. In the best case scenario, the path finder will return a list of all the coordinates I have to walk on to get to the target.

Thank you for all the help!

Source Link
Day Trip
  • 75
  • 1
  • 9

Java Simple 2D Grid Pathfinding

I want to code some basic pathfinding for my bot in Java. Below is a 2D grid representation of the 3D world. 0s being the places you can go, and 1s being the places that you cannot go.

int[][] data = {
            {0, 0, 0, 0, 0},
            {0, 0, 1, 0, 1},
            {1, 0, 0, 1, 1},
            {0, 0, 0, 1, 0},
            {1, 1, 0, 0, 1}
    };

How can I write a simple pathfinder in Java, where if I say that I'm currently at (2D coords) and I want to go to (2D coords), it will generate the shortest path there. I don't need a fancy cost system, because each move will have the same cost, and each 1 will have the same danger level. There are already some posts about this online that I've seen, but most of them look a little too overkill for my simple project.

Thank you for all the help!