From 46e1516a5af167513ca3dececa92bd2006d2f2e5 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Tue, 8 Nov 2022 12:40:03 +0100 Subject: [PATCH] solved Task 8.2 --- src/ch/zhaw/ads/LabyrinthServer.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/ch/zhaw/ads/LabyrinthServer.java b/src/ch/zhaw/ads/LabyrinthServer.java index bb5ef6d..a272fe8 100644 --- a/src/ch/zhaw/ads/LabyrinthServer.java +++ b/src/ch/zhaw/ads/LabyrinthServer.java @@ -1,9 +1,29 @@ package ch.zhaw.ads; +import java.util.Arrays; +import java.util.Vector; + public class LabyrinthServer implements CommandExecutor { ServerGraphics g = new ServerGraphics(); public Graph createGraph(String s) { + Graph 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 } @@ -13,6 +33,7 @@ public class LabyrinthServer implements CommandExecutor { private boolean search(DijkstraNode current, DijkstraNode ziel) { // TODO implement 8.4 + return false; } // search and draw result