|
@@ -1,33 +1,38 @@
|
|
|
package pathgame.algorithm;
|
|
|
|
|
|
-
|
|
|
-import pathgame.gameplay.PlayerAbilities;
|
|
|
import pathgame.tilemap.TileMap;
|
|
|
+import pathgame.tilemap.TileType;
|
|
|
import pathgame.tilemap.Tiles;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import pathgame.gameplay.Player;
|
|
|
|
|
|
public class DijkstraMagic {
|
|
|
- private int townID = Tiles.TOWN.getId();
|
|
|
- private int startID = Tiles.HOME_TOWN.getId();
|
|
|
+ private int TOWN_ID = Tiles.TOWN.getId();
|
|
|
+ private int START_ID = Tiles.HOME_TOWN.getId();
|
|
|
+ private int PORT_ID = Tiles.PORT.getId();
|
|
|
+ private int WATER_WEIGHT;
|
|
|
private ArrayList<Coord> towns = new ArrayList<>();
|
|
|
+ private ArrayList<Coord> ports = new ArrayList<>();
|
|
|
private TileMap map;
|
|
|
private Node2D[][] weightMap;
|
|
|
private ArrayList<ArrayList<SaleRoute>> salesPitch = new ArrayList<>();
|
|
|
|
|
|
- public DijkstraMagic(TileMap map) {
|
|
|
+ public DijkstraMagic(TileMap map, Player player) {
|
|
|
this.map = map;
|
|
|
|
|
|
weightMap = new Node2D[map.getWidth()][map.getHeight()];
|
|
|
-
|
|
|
|
|
|
- setup();
|
|
|
+ setup(player);
|
|
|
|
|
|
printWeightMap();
|
|
|
|
|
|
+ for(int i = 0; i < ports.size(); i++) {
|
|
|
+ doMagic(i, false);
|
|
|
+ }
|
|
|
+
|
|
|
for(int i = 0; i < towns.size(); i++) {
|
|
|
- doMagicforTown(i);
|
|
|
+ doMagic(i, true);
|
|
|
}
|
|
|
|
|
|
printDijkstraResult();
|
|
@@ -37,12 +42,18 @@ public class DijkstraMagic {
|
|
|
return salesPitch;
|
|
|
}
|
|
|
|
|
|
- private void doMagicforTown(int fromIndex) {
|
|
|
- if(fromIndex != 0) {
|
|
|
- resetWeightMap();
|
|
|
+ private void doMagic(int fromIndex, boolean forTown) {
|
|
|
+ resetWeightMap();
|
|
|
+
|
|
|
+ Coord origin;
|
|
|
+
|
|
|
+ if(forTown) {
|
|
|
+ origin = towns.get(fromIndex);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ origin = ports.get(fromIndex);
|
|
|
}
|
|
|
|
|
|
- Coord origin = towns.get(fromIndex);
|
|
|
int posX = origin.getX(), posY = origin.getY();
|
|
|
|
|
|
weightMap[posX][posY].setCostSoFar(0);
|
|
@@ -64,111 +75,171 @@ public class DijkstraMagic {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- dijkstraOnTile(tileQ.get(leastIndex).getX(), tileQ.get(leastIndex).getY(), tileQ, leastIndex);
|
|
|
- }
|
|
|
+ Coord c = tileQ.get(leastIndex);
|
|
|
|
|
|
- makeListForPitch(fromIndex);
|
|
|
+ if(weightMap[c.getX()][c.getY()].isBlocked() && forTown) {
|
|
|
+ tileQ.remove(leastIndex);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ dijkstraForTownOrPort(tileQ.get(leastIndex).getX(), tileQ.get(leastIndex).getY(), tileQ, leastIndex, forTown);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(forTown) {
|
|
|
+ makeListForPitch(fromIndex);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ addPortsPaths(fromIndex);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
- private void makeListForPitch(int fromIndex) {
|
|
|
- ArrayList<SaleRoute> listForPitch = new ArrayList<>();
|
|
|
-
|
|
|
- for(int i = fromIndex+1; i < towns.size(); i++) {
|
|
|
- ArrayList<Coord> listForRoute = new ArrayList<>();
|
|
|
-
|
|
|
- Coord curPos = new Coord(towns.get(i).getX(), towns.get(i).getY());
|
|
|
+ private void dijkstraForTownOrPort(int posX, int posY, ArrayList<Coord> tileQ, int qIndex, boolean forTown) {
|
|
|
+ int prevCost = weightMap[posX][posY].getCostSoFar();
|
|
|
|
|
|
- int totalCost = weightMap[curPos.getX()][curPos.getY()].getCostSoFar();
|
|
|
+ if(posX < weightMap.length-1) {
|
|
|
+ adjacent(posX+1, posY, prevCost, 'w', null, -1, tileQ, forTown);
|
|
|
+ }
|
|
|
+ if(posX > 0) {
|
|
|
+ adjacent(posX-1, posY, prevCost, 'e', null, -1, tileQ, forTown);
|
|
|
+ }
|
|
|
+ if(posY < weightMap[0].length-1) {
|
|
|
+ adjacent(posX, posY+1, prevCost, 'n', null, -1, tileQ, forTown);
|
|
|
+ }
|
|
|
+ if(posY > 0) {
|
|
|
+ adjacent(posX, posY-1, prevCost, 's', null, -1, tileQ, forTown);
|
|
|
+ }
|
|
|
|
|
|
- while(true) {
|
|
|
- char dir = weightMap[curPos.getX()][curPos.getY()].getPrevOfPath();
|
|
|
+ if(forTown) {
|
|
|
+ if(weightMap[posX][posY].hasExtraPaths()) {
|
|
|
+ ArrayList<ExtraPath> extraPaths = weightMap[posX][posY].getExtraPaths();
|
|
|
|
|
|
- listForRoute.add(new Coord(curPos.getX(), curPos.getY()));
|
|
|
+ for(int i = 0; i < extraPaths.size(); i++) {
|
|
|
+ ExtraPath path = extraPaths.get(i);
|
|
|
|
|
|
- if(dir == 'n') {
|
|
|
- curPos.changeY(-1);
|
|
|
- }
|
|
|
- else if(dir == 'e') {
|
|
|
- curPos.changeX(1);
|
|
|
- }
|
|
|
- else if(dir == 's') {
|
|
|
- curPos.changeY(1);
|
|
|
- }
|
|
|
- else if(dir == 'w') {
|
|
|
- curPos.changeX(-1);
|
|
|
- }
|
|
|
- else {
|
|
|
- break;
|
|
|
+ adjacent(path.getDestX(), path.getDestY(), prevCost, '\0', path, i, tileQ, forTown);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- listForPitch.add(new SaleRoute(listForRoute, totalCost));
|
|
|
}
|
|
|
|
|
|
- salesPitch.add(listForPitch);
|
|
|
+ tileQ.remove(qIndex);
|
|
|
}
|
|
|
|
|
|
- private void dijkstraOnTile(int posX, int posY, ArrayList<Coord> tileQ, int qIndex) {
|
|
|
- int prevCost = weightMap[posX][posY].getCostSoFar();
|
|
|
+ private void adjacent(int posX, int posY, int prevCost, char dir, ExtraPath boatPath, int extraInd, ArrayList<Coord> tileQ, boolean forTown) {
|
|
|
+ if(forTown) {
|
|
|
+ if(!weightMap[posX][posY].isBlocked()) {
|
|
|
+ adjacentCalc(posX, posY, prevCost, dir, boatPath, extraInd, tileQ, forTown);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ TileType type = weightMap[posX][posY].getType();
|
|
|
|
|
|
- if(posX < weightMap.length-1) {
|
|
|
- checkNeighbor(posX + 1, posY, prevCost, 'w');
|
|
|
+ if(type == TileType.SHALLOW_WATER || type == TileType.DEEP_WATER || type == TileType.PORT) {
|
|
|
+ adjacentCalc(posX, posY, prevCost, dir, null, -1, tileQ, forTown);
|
|
|
+ }
|
|
|
}
|
|
|
- if(posX > 0) {
|
|
|
- checkNeighbor(posX - 1, posY, prevCost, 'e');
|
|
|
+ }
|
|
|
+
|
|
|
+ private void adjacentCalc(int posX, int posY, int prevCost, char dir, ExtraPath extraPath, int extraInd, ArrayList<Coord> tileQ, boolean forTown) {
|
|
|
+ int newCost = prevCost;
|
|
|
+ if(forTown) {
|
|
|
+ if(extraPath == null) {
|
|
|
+ newCost += weightMap[posX][posY].getWeight();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ newCost += extraPath.getPathWeight();
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
- if(posY < weightMap[0].length-1) {
|
|
|
- checkNeighbor(posX, posY + 1, prevCost, 'n');
|
|
|
+ else {
|
|
|
+ newCost += WATER_WEIGHT;
|
|
|
}
|
|
|
- if(posY > 0) {
|
|
|
- checkNeighbor(posX, posY - 1, prevCost, 's');
|
|
|
+
|
|
|
+ if(newCost < weightMap[posX][posY].getCostSoFar()) {
|
|
|
+ weightMap[posX][posY].setCostSoFar(newCost);
|
|
|
+ if(extraPath == null) {
|
|
|
+ weightMap[posX][posY].setPrevOfPath(dir);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ weightMap[posX][posY].setPrevBoatPath(0);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if(weightMap[posX][posY].hasExtraPaths()) {
|
|
|
-
|
|
|
+ if(!weightMap[posX][posY].isQAdded()) {
|
|
|
+ weightMap[posX][posY].setQAdded(true);
|
|
|
+ tileQ.add(new Coord(posX, posY));
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- tileQ.remove(qIndex);
|
|
|
+ private void addPortsPaths(int fromIndex) {
|
|
|
+ Coord origin = ports.get(fromIndex);
|
|
|
|
|
|
- if(posX < weightMap.length-1) {
|
|
|
- if(!weightMap[posX+1][posY].isQAdded()) {
|
|
|
- weightMap[posX+1][posY].setQAdded(true);
|
|
|
- tileQ.add(new Coord(posX+1, posY));
|
|
|
+ for(int i = fromIndex+1; i < ports.size(); i++) {
|
|
|
+ Coord nextPort = ports.get(i);
|
|
|
+
|
|
|
+ if(weightMap[nextPort.getX()][nextPort.getY()].getCostSoFar() < Integer.MAX_VALUE) {
|
|
|
+
|
|
|
+
|
|
|
+ int pathWeight = weightMap[nextPort.getX()][nextPort.getY()].getCostSoFar();
|
|
|
+ ArrayList<Coord> pathCoords = new ArrayList<>();
|
|
|
+
|
|
|
+ makePathCoords(false, new Coord(nextPort.getX(), nextPort.getY()), pathCoords);
|
|
|
+
|
|
|
+ weightMap[origin.getX()][origin.getY()].addExtraPath(nextPort, pathWeight, pathCoords);
|
|
|
+ weightMap[nextPort.getX()][nextPort.getY()].addExtraPath(origin, pathWeight, pathCoords);
|
|
|
}
|
|
|
}
|
|
|
- if(posX > 0) {
|
|
|
- if(!weightMap[posX-1][posY].isQAdded()) {
|
|
|
- weightMap[posX-1][posY].setQAdded(true);
|
|
|
- tileQ.add(new Coord(posX-1, posY));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void makePathCoords(boolean forTown, Coord curPos, ArrayList<Coord> coordList) {
|
|
|
+ while(true) {
|
|
|
+ char dir = weightMap[curPos.getX()][curPos.getY()].getPrevOfPath();
|
|
|
+ int extraInd = weightMap[curPos.getX()][curPos.getY()].getPrevBoatPath();
|
|
|
+ coordList.add(new Coord(curPos.getX(), curPos.getY()));
|
|
|
+
|
|
|
+ if(dir == 'n') {
|
|
|
+ curPos.changeY(-1);
|
|
|
}
|
|
|
- }
|
|
|
- if(posY < weightMap[0].length-1) {
|
|
|
- if(!weightMap[posX][posY+1].isQAdded()) {
|
|
|
- weightMap[posX][posY+1].setQAdded(true);
|
|
|
- tileQ.add(new Coord(posX, posY+1));
|
|
|
+ else if(dir == 'e') {
|
|
|
+ curPos.changeX(1);
|
|
|
}
|
|
|
- }
|
|
|
- if(posY > 0) {
|
|
|
- if(!weightMap[posX][posY-1].isQAdded()) {
|
|
|
- weightMap[posX][posY-1].setQAdded(true);
|
|
|
- tileQ.add(new Coord(posX, posY-1));
|
|
|
+ else if(dir == 's') {
|
|
|
+ curPos.changeY(1);
|
|
|
+ }
|
|
|
+ else if(dir == 'w') {
|
|
|
+ curPos.changeX(-1);
|
|
|
+ }
|
|
|
+ else if(extraInd != -1 && forTown) {
|
|
|
+ ExtraPath extraPath = weightMap[curPos.getX()][curPos.getY()].getExtraPaths().get(extraInd);
|
|
|
+
|
|
|
+ curPos.setCoord(extraPath.getDestX(), extraPath.getDestY());
|
|
|
+ coordList.addAll(extraPath.getPathCoords());
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if(weightMap[posX][posY].hasExtraPaths()) {
|
|
|
-
|
|
|
+ if(!forTown) {
|
|
|
+ coordList.remove(0);
|
|
|
+ coordList.remove(coordList.size()-1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void checkNeighbor(int posX, int posY, int prevCost, char origin) {
|
|
|
- int newCost = prevCost + weightMap[posX][posY].getWeight();
|
|
|
+ private void makeListForPitch(int fromIndex) {
|
|
|
+ ArrayList<SaleRoute> listForPitch = new ArrayList<>();
|
|
|
|
|
|
- if(newCost < weightMap[posX][posY].getCostSoFar()) {
|
|
|
- weightMap[posX][posY].setCostSoFar(newCost);
|
|
|
- weightMap[posX][posY].setPrevOfPath(origin);
|
|
|
+ for(int i = fromIndex+1; i < towns.size(); i++) {
|
|
|
+ ArrayList<Coord> listForRoute = new ArrayList<>();
|
|
|
+ Coord curPos = new Coord(towns.get(i).getX(), towns.get(i).getY());
|
|
|
+ int totalCost = weightMap[curPos.getX()][curPos.getY()].getCostSoFar();
|
|
|
+
|
|
|
+ makePathCoords(true, curPos, listForRoute);
|
|
|
+
|
|
|
+ listForPitch.add(new SaleRoute(listForRoute, totalCost));
|
|
|
}
|
|
|
+
|
|
|
+ salesPitch.add(listForPitch);
|
|
|
}
|
|
|
|
|
|
private void resetWeightMap() {
|
|
@@ -176,176 +247,38 @@ public class DijkstraMagic {
|
|
|
for (int y = 0; y < weightMap[0].length; y++) {
|
|
|
weightMap[x][y].setCostSoFar(Integer.MAX_VALUE);
|
|
|
weightMap[x][y].setQAdded(false);
|
|
|
- weightMap[x][y].setPrevOfPath('0');
|
|
|
+ weightMap[x][y].setPrevOfPath('\0');
|
|
|
+ weightMap[x][y].setPrevBoatPath(-1);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void setup() {
|
|
|
+ private void setup(Player player) {
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- towns.add(new Coord(0, 0));
|
|
|
- towns.add(new Coord(2, 3));
|
|
|
- towns.add(new Coord(4, 1));
|
|
|
- towns.add(new Coord(0, 4));
|
|
|
- towns.add(new Coord(4, 7));
|
|
|
- towns.add(new Coord(2, 5));
|
|
|
- towns.add(new Coord(3, 9));
|
|
|
- towns.add(new Coord(1, 8));
|
|
|
-
|
|
|
- towns.add(new Coord(1, 3));
|
|
|
- towns.add(new Coord(1, 5));
|
|
|
-
|
|
|
- towns.add(new Coord(1, 14));
|
|
|
- towns.add(new Coord(0, 10));
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- weightMap[1][0] = new Node2D(1);
|
|
|
- weightMap[2][0] = new Node2D(1);
|
|
|
- weightMap[3][0] = new Node2D(5);
|
|
|
- weightMap[4][0] = new Node2D(5);
|
|
|
-
|
|
|
- weightMap[0][1] = new Node2D(1);
|
|
|
- weightMap[1][1] = new Node2D(10);
|
|
|
- weightMap[2][1] = new Node2D(1);
|
|
|
- weightMap[3][1] = new Node2D(5);
|
|
|
- weightMap[4][1] = new Node2D(1);
|
|
|
-
|
|
|
- weightMap[0][2] = new Node2D(1);
|
|
|
- weightMap[1][2] = new Node2D(10);
|
|
|
- weightMap[2][2] = new Node2D(1);
|
|
|
- weightMap[3][2] = new Node2D(1);
|
|
|
- weightMap[4][2] = new Node2D(1);
|
|
|
-
|
|
|
- weightMap[0][3] = new Node2D(1);
|
|
|
- weightMap[1][3] = new Node2D(1);
|
|
|
- weightMap[2][3] = new Node2D(1);
|
|
|
- weightMap[3][3] = new Node2D(1);
|
|
|
- weightMap[4][3] = new Node2D(5);
|
|
|
-
|
|
|
- weightMap[0][4] = new Node2D(1);
|
|
|
- weightMap[1][4] = new Node2D(1);
|
|
|
- weightMap[2][4] = new Node2D(1);
|
|
|
- weightMap[3][4] = new Node2D(5);
|
|
|
- weightMap[4][4] = new Node2D(5);
|
|
|
-
|
|
|
- weightMap[0][5] = new Node2D(1);
|
|
|
- weightMap[1][5] = new Node2D(1);
|
|
|
- weightMap[2][5] = new Node2D(1);
|
|
|
- weightMap[3][5] = new Node2D(5);
|
|
|
- weightMap[4][5] = new Node2D(5);
|
|
|
-
|
|
|
- weightMap[0][6] = new Node2D(1);
|
|
|
- weightMap[1][6] = new Node2D(10);
|
|
|
- weightMap[2][6] = new Node2D(1);
|
|
|
- weightMap[3][6] = new Node2D(5);
|
|
|
- weightMap[4][6] = new Node2D(1);
|
|
|
-
|
|
|
- weightMap[0][7] = new Node2D(1);
|
|
|
- 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(1);
|
|
|
- weightMap[2][8] = new Node2D(1);
|
|
|
- weightMap[3][8] = new Node2D(1);
|
|
|
- weightMap[4][8] = new Node2D(5);
|
|
|
-
|
|
|
- weightMap[0][9] = new Node2D(1);
|
|
|
- weightMap[1][9] = new Node2D(1);
|
|
|
- weightMap[2][9] = new Node2D(1);
|
|
|
- weightMap[3][9] = new Node2D(1);
|
|
|
- weightMap[4][9] = new Node2D(5);
|
|
|
-
|
|
|
- weightMap[0][10] = new Node2D(1);
|
|
|
- weightMap[1][10] = new Node2D(5);
|
|
|
- weightMap[2][10] = new Node2D(1);
|
|
|
- weightMap[3][10] = new Node2D(5);
|
|
|
- weightMap[4][10] = new Node2D(5);
|
|
|
-
|
|
|
- weightMap[0][11] = new Node2D(1);
|
|
|
- weightMap[1][11] = new Node2D(1);
|
|
|
- weightMap[2][11] = new Node2D(1);
|
|
|
- weightMap[3][11] = new Node2D(5);
|
|
|
- weightMap[4][11] = new Node2D(1);
|
|
|
-
|
|
|
- weightMap[0][12] = new Node2D(1);
|
|
|
- weightMap[1][12] = new Node2D(10);
|
|
|
- weightMap[2][12] = new Node2D(1);
|
|
|
- weightMap[3][12] = new Node2D(1);
|
|
|
- weightMap[4][12] = new Node2D(1);
|
|
|
-
|
|
|
- weightMap[0][13] = new Node2D(1);
|
|
|
- weightMap[1][13] = new Node2D(10);
|
|
|
- weightMap[2][13] = new Node2D(1);
|
|
|
- weightMap[3][13] = new Node2D(1);
|
|
|
- weightMap[4][13] = new Node2D(5);
|
|
|
-
|
|
|
- weightMap[0][14] = new Node2D(1);
|
|
|
- weightMap[1][14] = new Node2D(1);
|
|
|
- weightMap[2][14] = new Node2D(1);
|
|
|
- weightMap[3][14] = new Node2D(5);
|
|
|
- weightMap[4][14] = new Node2D(5);*/
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- towns.add(new Coord(30, 29));
|
|
|
- towns.add(new Coord(41, 20));
|
|
|
- towns.add(new Coord(42, 24));
|
|
|
- towns.add(new Coord(26, 41));
|
|
|
-
|
|
|
- towns.add(new Coord(39, 26));
|
|
|
- towns.add(new Coord(16, 8));
|
|
|
- towns.add(new Coord(6, 27));
|
|
|
- towns.add(new Coord(26, 7));
|
|
|
- towns.add(new Coord(28, 13));
|
|
|
-
|
|
|
- towns.add(new Coord(49, 4));
|
|
|
- towns.add(new Coord(34, 47));
|
|
|
- towns.add(new Coord(20, 20));
|
|
|
- towns.add(new Coord(43, 32));
|
|
|
- towns.add(new Coord(43, 21));
|
|
|
-
|
|
|
- towns.add(new Coord(3, 43));
|
|
|
- towns.add(new Coord(34, 8));
|
|
|
- towns.add(new Coord(30, 17));
|
|
|
- towns.add(new Coord(35, 49));
|
|
|
- towns.add(new Coord(28, 10));*/
|
|
|
-
|
|
|
|
|
|
for(int x = 0; x < map.getWidth(); x++) {
|
|
|
for(int y = 0; y < map.getHeight(); y++) {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if(map.getTile(x, y).getId() == townID || map.getTile(x, y).getId() == startID) {
|
|
|
+ if(map.getTile(x, y).getId() == TOWN_ID || map.getTile(x, y).getId() == START_ID) {
|
|
|
towns.add(new Coord(x, y));
|
|
|
}
|
|
|
+ else if(map.getTile(x, y).getId() == PORT_ID) {
|
|
|
+ ports.add(new Coord(x, y));
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- Player p = new Player();
|
|
|
- p.setAbilities(PlayerAbilities.NORMAL);
|
|
|
+ weightMap[x][y] = new Node2D(map.getTile(x, y).getEnergyCost(player));
|
|
|
+ weightMap[x][y].setType(map.getTile(x, y).getType());
|
|
|
|
|
|
- weightMap[x][y] = new Node2D(map.getTile(x, y).getEnergyCost(p));
|
|
|
+ if(map.getTile(x, y).isBlockingMovement(player)) {
|
|
|
+ weightMap[x][y].setBlocked(true);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ player.switchSailing();
|
|
|
+
|
|
|
+ WATER_WEIGHT = Tiles.SHALLOW_WATER.getEnergyCost(player);
|
|
|
+
|
|
|
+ player.switchSailing();
|
|
|
}
|
|
|
|
|
|
private void printDijkstraMap() {
|
|
@@ -389,7 +322,20 @@ public class DijkstraMagic {
|
|
|
private void printWeightMap() {
|
|
|
for(int y = 0; y < weightMap[0].length; y++) {
|
|
|
for(int x = 0; x < weightMap.length; x++) {
|
|
|
- System.out.print(weightMap[x][y].getWeight() + " ");
|
|
|
+ int cost = weightMap[x][y].getWeight();
|
|
|
+ TileType type = weightMap[x][y].getType();
|
|
|
+ if(type == TileType.PORT) {
|
|
|
+ System.out.print("P ");
|
|
|
+ }
|
|
|
+ else if(type == TileType.SHALLOW_WATER) {
|
|
|
+ System.out.print("s ");
|
|
|
+ }
|
|
|
+ else if(type == TileType.DEEP_WATER) {
|
|
|
+ System.out.print("d ");
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ System.out.print(cost + " ");
|
|
|
+ }
|
|
|
}
|
|
|
System.out.println();
|
|
|
}
|