From 4f3fb4c0d937b35752e7c16e8556145e62f7e373 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Tue, 8 Nov 2022 13:58:24 +0100 Subject: [PATCH] Add code for creating a labyrinth graph --- .../ch/nuth/zhaw/exbox/LabyrinthServer.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/src/main/java/ch/nuth/zhaw/exbox/LabyrinthServer.java b/app/src/main/java/ch/nuth/zhaw/exbox/LabyrinthServer.java index a2184ee..15660b1 100644 --- a/app/src/main/java/ch/nuth/zhaw/exbox/LabyrinthServer.java +++ b/app/src/main/java/ch/nuth/zhaw/exbox/LabyrinthServer.java @@ -1,10 +1,28 @@ package ch.nuth.zhaw.exbox; +import java.io.BufferedReader; +import java.io.StringReader; + public class LabyrinthServer implements CommandExecutor { ServerGraphics g = new ServerGraphics(); public Graph createGraph(String s) { // TODO implement 8.2 + Graph graph = new AdjListGraph<>(DijkstraNode.class, Edge.class); + + try { + try (BufferedReader reader = new BufferedReader(new StringReader(s))) { + String currentLine; + + while ((currentLine = reader.readLine()) != null) { + String[] elements = currentLine.split(" "); + graph.addEdge(elements[0], elements[1], 0); + } + } + } catch (Throwable e) { + } + + return graph; } public void drawLabyrinth(Graph graph) { @@ -13,6 +31,7 @@ public class LabyrinthServer implements CommandExecutor { private boolean search(DijkstraNode current, DijkstraNode ziel) { // TODO implement 8.4 + return false; } // search and draw result