Ich hab kein Bock mehr

This commit is contained in:
joachimschmidt557 2019-03-25 21:32:51 +01:00
parent c331208620
commit 6838a34e0d
3 changed files with 42 additions and 11 deletions

View file

@ -55,6 +55,9 @@ public class Graph<T> {
return edge;
}
if (DEBUG)
System.out.println("??" + nodeA + " " + nodeB);
edge = new Edge<>(nodeA, nodeB);
this.edges.add(edge);
return edge;

View file

@ -11,7 +11,7 @@ import java.util.*;
public abstract class GraphAlgorithm<T> {
final static boolean DEBUG = true;
final static boolean DEBUG_2 = false;
final static boolean DEBUG_2 = true;
int n = 0;
@ -80,13 +80,17 @@ public abstract class GraphAlgorithm<T> {
Iterator<Node<T>> iter = availableNodes.iterator();
Iterator<Node<T>> minElemIter = availableNodes.iterator();
AlgorithmNode<T> minElem;
AlgorithmNode<T> tempElem;
Node<T> minNode;
AlgorithmNode<T> minAlgoNode;
Node<T> tempNode;
AlgorithmNode<T> tempAlgoNode;
if (iter.hasNext()) {
// Set minimum to first element
minElem = algorithmNodes.get(iter.next());
minNode = iter.next();
minAlgoNode = algorithmNodes.get(minNode);
minElemIter.next();
while (iter.hasNext()) {
@ -99,20 +103,24 @@ public abstract class GraphAlgorithm<T> {
System.out.flush();
}
tempElem = algorithmNodes.get(iter.next());
if (tempElem.value > 0) {
if (tempElem.value < minElem.value) {
tempNode = iter.next();
tempAlgoNode = algorithmNodes.get(tempNode);
if (tempAlgoNode.value > 0) {
if (tempAlgoNode.value < minAlgoNode.value) {
// New minimum
minElem = tempElem;
minElemIter = iter;
minNode = tempNode;
minAlgoNode = tempAlgoNode;
// Move minElemIter to the minimum
while (!minElemIter.next().equals(minNode)) {}
}
}
}
minElemIter.remove();
return minElem;
return minAlgoNode;
}
@ -169,12 +177,17 @@ public abstract class GraphAlgorithm<T> {
n.value = a;
n.previous = v;
System.out.println("--" + n + " " + n.previous);
}
}
}
v = getSmallestNode();
}
if (DEBUG_2)
System.out.println("Finished run");
}
/**
@ -190,6 +203,9 @@ public abstract class GraphAlgorithm<T> {
*/
public List<Edge<T>> getPath(Node<T> destination) {
if (DEBUG_2)
System.out.println("Enter getPath");
// Stage 1
ArrayList<Edge<T>> reversePath = new ArrayList<Edge<T>>();
@ -199,8 +215,13 @@ public abstract class GraphAlgorithm<T> {
while (!(prevNode.value == 0)) {
if (DEBUG_2)
System.out.println("Iteration");
AlgorithmNode<T> prevPrevNode = prevNode.previous;
if (prevNode.equals(prevPrevNode)) throw new IndexOutOfBoundsException();
if (prevPrevNode == null)
return null;
@ -211,6 +232,12 @@ public abstract class GraphAlgorithm<T> {
// Stage 2
Collections.reverse(reversePath);
if (DEBUG_2) {
System.out.println(reversePath);
System.out.println("Exit getPath");
}
return reversePath;
}

View file

@ -249,6 +249,7 @@ public class GameMap {
private List<Node<Castle>> allCastlesInRadius(Node<Castle> castle, List<Node<Castle>> allCastles, double r) {
return allCastles.stream()
.filter(x -> !x.equals(castle))
.filter(x -> x.getValue().distance(castle.getValue()) <= r)
.collect(Collectors.toList());