commit 506ce1f18898a4c36c6f9f2194ea1bd2a7efa77e Author: peet Date: Tue Jun 25 18:53:44 2024 +0200 initial commit diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e112a70 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..7c03a53 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +## Getting Started + +Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. + +## Folder Structure + +The workspace contains two folders by default, where: + +- `src`: the folder to maintain sources +- `lib`: the folder to maintain dependencies + +Meanwhile, the compiled output files will be generated in the `bin` folder by default. + +> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. + +## Dependency Management + +The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). diff --git a/bin/AriadneIterator$Accomplished.class b/bin/AriadneIterator$Accomplished.class new file mode 100644 index 0000000..c6b1df2 Binary files /dev/null and b/bin/AriadneIterator$Accomplished.class differ diff --git a/bin/AriadneIterator$Starting.class b/bin/AriadneIterator$Starting.class new file mode 100644 index 0000000..f417687 Binary files /dev/null and b/bin/AriadneIterator$Starting.class differ diff --git a/bin/AriadneIterator.class b/bin/AriadneIterator.class new file mode 100644 index 0000000..cfa941b Binary files /dev/null and b/bin/AriadneIterator.class differ diff --git a/bin/CreateSmallMaze.class b/bin/CreateSmallMaze.class new file mode 100644 index 0000000..433f5c8 Binary files /dev/null and b/bin/CreateSmallMaze.class differ diff --git a/bin/CreateSmallMazeTest.class b/bin/CreateSmallMazeTest.class new file mode 100644 index 0000000..97e7665 Binary files /dev/null and b/bin/CreateSmallMazeTest.class differ diff --git a/bin/Room.class b/bin/Room.class new file mode 100644 index 0000000..60d01bc Binary files /dev/null and b/bin/Room.class differ diff --git a/lib/hamcrest-core-1.3.jar b/lib/hamcrest-core-1.3.jar new file mode 100644 index 0000000..9d5fe16 Binary files /dev/null and b/lib/hamcrest-core-1.3.jar differ diff --git a/lib/junit-4.13.2.jar b/lib/junit-4.13.2.jar new file mode 100644 index 0000000..6da55d8 Binary files /dev/null and b/lib/junit-4.13.2.jar differ diff --git a/src/AriadneIterator.java b/src/AriadneIterator.java new file mode 100644 index 0000000..e12e23b --- /dev/null +++ b/src/AriadneIterator.java @@ -0,0 +1,72 @@ +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Stack; + +public class AriadneIterator implements Iterator{ + private Room entry; + private Stack ariadnesThread; + private List visited; + + private State currentstate; + + public AriadneIterator(Room entry) { + this.entry = entry; + } + + + @Override + public boolean hasNext() { + return cs.hasNext(); + } + + @Override + public Room next() { + return ariadnesThread.peek(); + } + + public void stepRetreating() { + ariadnesThread.pop(); + } + + public boolean hasMinotaur() { + return ariadnesThread.peek().getMinotaur(); + } + + public void step() { + currentstate.step(); + } + + public void init() { + ariadnesThread = new Stack<>(); + ariadnesThread.push(entry); + visited = new ArrayList<>(); + visited.add(entry); + currentstate = new Starting(); + } + + private class Starting implements State { + @Override + public void step() { + init(); + } + + @Override + public boolean hasNext() { + return false; + } + } + + private class Accomplished implements State { + @Override + public void step() { + stepRetreating(); + } + + public boolean hasNext() { + return !ariadnesThread.empty(); + } + } + + +} diff --git a/src/CreateSmallMaze.java b/src/CreateSmallMaze.java new file mode 100644 index 0000000..7e609cd --- /dev/null +++ b/src/CreateSmallMaze.java @@ -0,0 +1,16 @@ +public class CreateSmallMaze { + + + public static Room createSmallMaze() { + Room a = new Room("a2"); + Room b = new Room("b2"); + b.addReachable(a); + a = new Room("b1"); + a.setMinotaur(true); + a.addReachable(b); + b = new Room("a1"); + b.addReachable(a); + + return b; + } +} diff --git a/src/CreateSmallMazeTest.java b/src/CreateSmallMazeTest.java new file mode 100644 index 0000000..d4e34dd --- /dev/null +++ b/src/CreateSmallMazeTest.java @@ -0,0 +1,23 @@ +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class CreateSmallMazeTest { + + Room entry = CreateSmallMaze.createSmallMaze(); + + @Test + public void testSmallMaze() { + AriadneIterator iter = new AriadneIterator(entry); + + // Erstes next ruft nur init() auf sodass wir nun mit dem Iterator arbeiten können + iter.next(); + + + assertEquals("a2", iter.next().getName()); + assertEquals("b2", iter.next().getName()); + assertEquals("b1", iter.next().getName()); + assertEquals("b2", iter.next().getName()); + assertEquals("a2", iter.next().getName()); + } +} diff --git a/src/Room.java b/src/Room.java new file mode 100644 index 0000000..ee6ea7d --- /dev/null +++ b/src/Room.java @@ -0,0 +1,28 @@ +import java.util.HashSet; +import java.util.Set; + +public class Room { + private String name; + private boolean minotaur; + + private Set reachable; + + public Room(String name) { + this.name = name; + minotaur = false; + reachable = new HashSet<>(); + } + + public void setMinotaur(boolean v) { + minotaur = v; + } + + public void setName(String name) { + this.name = name; + } + + public void addReachable(Room room) { + reachable.add(room); + room.addReachable(this); + } +}