|
@@ -7,7 +7,7 @@ import pathgame.tilemap.TileMap;
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
public class DijkstraMagic {
|
|
|
- private int townID = -1;
|
|
|
+ private int townID = 18;
|
|
|
private ArrayList<Coord> towns = new ArrayList<>();
|
|
|
private TileMap map;
|
|
|
private Node2D[][] weightMap;
|
|
@@ -16,16 +16,18 @@ public class DijkstraMagic {
|
|
|
public DijkstraMagic(TileMap map) {
|
|
|
this.map = map;
|
|
|
|
|
|
- //weightMap = new Node2D[map.getWidth()][map.getHeight()];
|
|
|
- weightMap = new Node2D[5][15];
|
|
|
+ weightMap = new Node2D[map.getWidth()][map.getHeight()];
|
|
|
+ //weightMap = new Node2D[5][15];
|
|
|
|
|
|
setup();
|
|
|
|
|
|
+ printWeightMap();
|
|
|
+
|
|
|
for(int i = 0; i < towns.size(); i++) {
|
|
|
doMagicforTown(i);
|
|
|
}
|
|
|
|
|
|
- //printDijkstraResult();
|
|
|
+ printDijkstraResult();
|
|
|
}
|
|
|
|
|
|
public ArrayList<ArrayList<SaleRoute>> getSalesPitch() {
|
|
@@ -179,7 +181,7 @@ public class DijkstraMagic {
|
|
|
private void setup() {
|
|
|
//find towns
|
|
|
//mock implementation
|
|
|
-
|
|
|
+ /*
|
|
|
//test start
|
|
|
towns.add(new Coord(0, 0));
|
|
|
towns.add(new Coord(2, 3));
|
|
@@ -192,21 +194,22 @@ public class DijkstraMagic {
|
|
|
//new test
|
|
|
towns.add(new Coord(1, 3));
|
|
|
towns.add(new Coord(1, 5));
|
|
|
- towns.add(new Coord(2, 8));
|
|
|
- towns.add(new Coord(0, 2));
|
|
|
- towns.add(new Coord(0, 5));
|
|
|
- towns.add(new Coord(0, 10));
|
|
|
- towns.add(new Coord(0, 14));
|
|
|
- towns.add(new Coord(1, 0));
|
|
|
- towns.add(new Coord(1, 7));
|
|
|
- towns.add(new Coord(1, 9));
|
|
|
- towns.add(new Coord(1, 11));
|
|
|
+
|
|
|
towns.add(new Coord(1, 14));
|
|
|
+ towns.add(new Coord(0, 10));
|
|
|
+ //towns.add(new Coord(2, 8));
|
|
|
+ //towns.add(new Coord(0, 2));
|
|
|
+ //towns.add(new Coord(0, 5));
|
|
|
+ //towns.add(new Coord(0, 14));
|
|
|
+ //towns.add(new Coord(1, 0));
|
|
|
+ //towns.add(new Coord(1, 7));
|
|
|
+ //towns.add(new Coord(1, 9));
|
|
|
+ //towns.add(new Coord(1, 11));*/
|
|
|
|
|
|
|
|
|
|
|
|
- weightMap[0][0] = new Node2D(1);
|
|
|
- weightMap[1][0] = new Node2D(5);
|
|
|
+ /*weightMap[0][0] = new Node2D(1);
|
|
|
+ weightMap[1][0] = new Node2D(1);
|
|
|
weightMap[2][0] = new Node2D(1);
|
|
|
weightMap[3][0] = new Node2D(5);
|
|
|
weightMap[4][0] = new Node2D(5);
|
|
@@ -224,7 +227,7 @@ public class DijkstraMagic {
|
|
|
weightMap[4][2] = new Node2D(1);
|
|
|
|
|
|
weightMap[0][3] = new Node2D(1);
|
|
|
- weightMap[1][3] = new Node2D(10);
|
|
|
+ weightMap[1][3] = new Node2D(1);
|
|
|
weightMap[2][3] = new Node2D(1);
|
|
|
weightMap[3][3] = new Node2D(1);
|
|
|
weightMap[4][3] = new Node2D(5);
|
|
@@ -236,7 +239,7 @@ public class DijkstraMagic {
|
|
|
weightMap[4][4] = new Node2D(5);
|
|
|
|
|
|
weightMap[0][5] = new Node2D(1);
|
|
|
- weightMap[1][5] = new Node2D(5);
|
|
|
+ weightMap[1][5] = new Node2D(1);
|
|
|
weightMap[2][5] = new Node2D(1);
|
|
|
weightMap[3][5] = new Node2D(5);
|
|
|
weightMap[4][5] = new Node2D(5);
|
|
@@ -248,13 +251,13 @@ public class DijkstraMagic {
|
|
|
weightMap[4][6] = new Node2D(1);
|
|
|
|
|
|
weightMap[0][7] = new Node2D(1);
|
|
|
- weightMap[1][7] = new Node2D(10);
|
|
|
+ weightMap[1][7] = new Node2D(1);
|
|
|
weightMap[2][7] = new Node2D(1);
|
|
|
weightMap[3][7] = new Node2D(1);
|
|
|
weightMap[4][7] = new Node2D(1);
|
|
|
|
|
|
weightMap[0][8] = new Node2D(1);
|
|
|
- weightMap[1][8] = new Node2D(10);
|
|
|
+ weightMap[1][8] = new Node2D(1);
|
|
|
weightMap[2][8] = new Node2D(1);
|
|
|
weightMap[3][8] = new Node2D(1);
|
|
|
weightMap[4][8] = new Node2D(5);
|
|
@@ -262,7 +265,7 @@ public class DijkstraMagic {
|
|
|
weightMap[0][9] = new Node2D(1);
|
|
|
weightMap[1][9] = new Node2D(1);
|
|
|
weightMap[2][9] = new Node2D(1);
|
|
|
- weightMap[3][9] = new Node2D(5);
|
|
|
+ weightMap[3][9] = new Node2D(1);
|
|
|
weightMap[4][9] = new Node2D(5);
|
|
|
|
|
|
weightMap[0][10] = new Node2D(1);
|
|
@@ -272,7 +275,7 @@ public class DijkstraMagic {
|
|
|
weightMap[4][10] = new Node2D(5);
|
|
|
|
|
|
weightMap[0][11] = new Node2D(1);
|
|
|
- weightMap[1][11] = new Node2D(10);
|
|
|
+ weightMap[1][11] = new Node2D(1);
|
|
|
weightMap[2][11] = new Node2D(1);
|
|
|
weightMap[3][11] = new Node2D(5);
|
|
|
weightMap[4][11] = new Node2D(1);
|
|
@@ -293,7 +296,7 @@ public class DijkstraMagic {
|
|
|
weightMap[1][14] = new Node2D(1);
|
|
|
weightMap[2][14] = new Node2D(1);
|
|
|
weightMap[3][14] = new Node2D(5);
|
|
|
- weightMap[4][14] = new Node2D(5);
|
|
|
+ weightMap[4][14] = new Node2D(5);*/
|
|
|
|
|
|
//test end
|
|
|
|
|
@@ -322,26 +325,23 @@ public class DijkstraMagic {
|
|
|
towns.add(new Coord(28, 10));*/
|
|
|
|
|
|
|
|
|
- /*for(int x = 0; x < map.getWidth(); x++) {
|
|
|
+ for(int x = 0; x < map.getWidth(); x++) {
|
|
|
for(int y = 0; y < map.getHeight(); y++) {
|
|
|
|
|
|
//actual implementation - find towns; townID needs to be set to correct value
|
|
|
|
|
|
- /*if(map.getTile(x, y).getId() == townID) {
|
|
|
+ if(map.getTile(x, y).getId() == townID) {
|
|
|
towns.add(new Coord(x, y));
|
|
|
- }*/
|
|
|
+ }
|
|
|
|
|
|
//translate map to weightMap
|
|
|
//TODO: boats
|
|
|
|
|
|
- /*PlayerAbilities test = new PlayerAbilities(0, 0, 0, 0, 0, 0, 0);
|
|
|
+ PlayerAbilities test = new PlayerAbilities("", 0, 0, 0, 0, 0, 0, 0);
|
|
|
|
|
|
weightMap[x][y] = new Node2D(map.getTile(x, y).getEnergyCost(test));
|
|
|
-
|
|
|
}
|
|
|
- }*/
|
|
|
-
|
|
|
- //printWeightMap();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void printDijkstraMap() {
|