From 6838a34e0d9776b37e9b6bc09fe9e0b864aa3f68 Mon Sep 17 00:00:00 2001 From: joachimschmidt557 Date: Mon, 25 Mar 2019 21:32:51 +0100 Subject: [PATCH] Ich hab kein Bock mehr --- Projektgruppe_175/src/base/Graph.java | 5 +- .../src/base/GraphAlgorithm.java | 47 +++++++++++++++---- Projektgruppe_175/src/game/map/GameMap.java | 1 + 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/Projektgruppe_175/src/base/Graph.java b/Projektgruppe_175/src/base/Graph.java index dd98ac3..81261b9 100644 --- a/Projektgruppe_175/src/base/Graph.java +++ b/Projektgruppe_175/src/base/Graph.java @@ -54,7 +54,10 @@ public class Graph { if(edge != null) { return edge; } - + + if (DEBUG) + System.out.println("??" + nodeA + " " + nodeB); + edge = new Edge<>(nodeA, nodeB); this.edges.add(edge); return edge; diff --git a/Projektgruppe_175/src/base/GraphAlgorithm.java b/Projektgruppe_175/src/base/GraphAlgorithm.java index b7def6c..8b54dad 100644 --- a/Projektgruppe_175/src/base/GraphAlgorithm.java +++ b/Projektgruppe_175/src/base/GraphAlgorithm.java @@ -11,7 +11,7 @@ import java.util.*; public abstract class GraphAlgorithm { 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 { Iterator> iter = availableNodes.iterator(); Iterator> minElemIter = availableNodes.iterator(); - AlgorithmNode minElem; - AlgorithmNode tempElem; + + Node minNode; + AlgorithmNode minAlgoNode; + Node tempNode; + AlgorithmNode 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 { 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; } @@ -168,6 +176,8 @@ public abstract class GraphAlgorithm { n.value = a; n.previous = v; + + System.out.println("--" + n + " " + n.previous); } @@ -175,6 +185,9 @@ public abstract class GraphAlgorithm { } v = getSmallestNode(); } + + if (DEBUG_2) + System.out.println("Finished run"); } /** @@ -190,6 +203,9 @@ public abstract class GraphAlgorithm { */ public List> getPath(Node destination) { + if (DEBUG_2) + System.out.println("Enter getPath"); + // Stage 1 ArrayList> reversePath = new ArrayList>(); @@ -199,8 +215,13 @@ public abstract class GraphAlgorithm { while (!(prevNode.value == 0)) { + if (DEBUG_2) + System.out.println("Iteration"); + AlgorithmNode prevPrevNode = prevNode.previous; + if (prevNode.equals(prevPrevNode)) throw new IndexOutOfBoundsException(); + if (prevPrevNode == null) return null; @@ -211,6 +232,12 @@ public abstract class GraphAlgorithm { // Stage 2 Collections.reverse(reversePath); + + if (DEBUG_2) { + System.out.println(reversePath); + System.out.println("Exit getPath"); + } + return reversePath; } diff --git a/Projektgruppe_175/src/game/map/GameMap.java b/Projektgruppe_175/src/game/map/GameMap.java index 6622ba0..9ef6475 100644 --- a/Projektgruppe_175/src/game/map/GameMap.java +++ b/Projektgruppe_175/src/game/map/GameMap.java @@ -249,6 +249,7 @@ public class GameMap { private List> allCastlesInRadius(Node castle, List> allCastles, double r) { return allCastles.stream() + .filter(x -> !x.equals(castle)) .filter(x -> x.getValue().distance(castle.getValue()) <= r) .collect(Collectors.toList());