initial commit

This commit is contained in:
Johannes Schmelz 2024-06-25 18:53:44 +02:00
commit 506ce1f188
14 changed files with 164 additions and 0 deletions

7
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}

18
README.md Normal file
View File

@ -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).

Binary file not shown.

Binary file not shown.

BIN
bin/AriadneIterator.class Normal file

Binary file not shown.

BIN
bin/CreateSmallMaze.class Normal file

Binary file not shown.

Binary file not shown.

BIN
bin/Room.class Normal file

Binary file not shown.

BIN
lib/hamcrest-core-1.3.jar Normal file

Binary file not shown.

BIN
lib/junit-4.13.2.jar Normal file

Binary file not shown.

72
src/AriadneIterator.java Normal file
View File

@ -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<Room>{
private Room entry;
private Stack<Room> ariadnesThread;
private List<Room> 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();
}
}
}

16
src/CreateSmallMaze.java Normal file
View File

@ -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;
}
}

View File

@ -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());
}
}

28
src/Room.java Normal file
View File

@ -0,0 +1,28 @@
import java.util.HashSet;
import java.util.Set;
public class Room {
private String name;
private boolean minotaur;
private Set<Room> 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);
}
}