Finish 3.1.2

This commit is contained in:
joachimschmidt557 2019-02-16 14:17:12 +01:00
parent 526d15f2c7
commit 6102da73fa
2 changed files with 63 additions and 15 deletions

View file

@ -154,15 +154,26 @@ public class GameMap {
private void generateEdges() {
List<Node<Castle>> castleNodes = castleGraph.getNodes();
/*
for (int i = 0; i < castleNodes.size(); i++) {
if (i == castleNodes.size() - 1)
castleGraph.addEdge(castleNodes.get(i), castleNodes.get(0));
else
castleGraph.addEdge(castleNodes.get(i), castleNodes.get(i+1));
}*/
if (castleNodes.isEmpty())
return;
// Stage 1
List<Node<Castle>> remainingCastles = new ArrayList<Node<Castle>>(castleNodes);
Node<Castle> castleToConnect = remainingCastles.remove(0);
while (!remainingCastles.isEmpty()) {
Node<Castle> nearestCastle = nearestCastle(castleToConnect, remainingCastles);
castleGraph.addEdge(castleToConnect, nearestCastle);
castleToConnect = nearestCastle;
remainingCastles.remove(castleToConnect);
}
final double radius = 300.0;
// Stage 2
final double radius = 170.0;
for (Node<Castle> cast : castleNodes) {
for (Node<Castle> c : allCastlesInRadius(cast, castleNodes, radius))
@ -171,6 +182,16 @@ public class GameMap {
}
private Node<Castle> nearestCastle(Node<Castle> castle, List<Node<Castle>> allCastles) {
return allCastles.stream()
.min((x, y) -> Double.compare(
castle.getValue().distance(x.getValue()),
castle.getValue().distance(y.getValue())))
.get();
}
private List<Node<Castle>> allCastlesInRadius(Node<Castle> castle, List<Node<Castle>> allCastles, double r) {
return allCastles.stream()