solved Task 8.2
This commit is contained in:
parent
92d6188c38
commit
46e1516a5a
|
@ -1,9 +1,29 @@
|
||||||
package ch.zhaw.ads;
|
package ch.zhaw.ads;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
public class LabyrinthServer implements CommandExecutor {
|
public class LabyrinthServer implements CommandExecutor {
|
||||||
ServerGraphics g = new ServerGraphics();
|
ServerGraphics g = new ServerGraphics();
|
||||||
|
|
||||||
public Graph<DijkstraNode, Edge> createGraph(String s) {
|
public Graph<DijkstraNode, Edge> createGraph(String s) {
|
||||||
|
Graph<DijkstraNode, Edge> graph = new AdjListGraph<>(DijkstraNode.class, Edge.class);
|
||||||
|
String[] lines = s.split("\n");
|
||||||
|
Arrays.asList(lines).forEach(s1 -> {
|
||||||
|
String[] nodes = s1.split(" ");
|
||||||
|
try {
|
||||||
|
int x1 = Integer.parseInt(nodes[0].split("-")[0]);
|
||||||
|
int x2 = Integer.parseInt(nodes[1].split("-")[0]);
|
||||||
|
int y1 = Integer.parseInt(nodes[0].split("-")[1]);
|
||||||
|
int y2 = Integer.parseInt(nodes[1].split("-")[1]);
|
||||||
|
double distance = Math.abs(x1-x2) + Math.abs(y1-y2);
|
||||||
|
graph.addEdge(nodes[0], nodes[1], distance);
|
||||||
|
graph.addEdge(nodes[1], nodes[0], distance);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return graph;
|
||||||
// TODO implement 8.2
|
// TODO implement 8.2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +33,7 @@ public class LabyrinthServer implements CommandExecutor {
|
||||||
|
|
||||||
private boolean search(DijkstraNode current, DijkstraNode ziel) {
|
private boolean search(DijkstraNode current, DijkstraNode ziel) {
|
||||||
// TODO implement 8.4
|
// TODO implement 8.4
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// search and draw result
|
// search and draw result
|
||||||
|
|
Loading…
Reference in New Issue