diff --git a/src/main/java/h06/Main.java b/src/main/java/h06/Main.java index bcb69d7..cd09936 100644 --- a/src/main/java/h06/Main.java +++ b/src/main/java/h06/Main.java @@ -1,5 +1,14 @@ package h06; +import h06.problems.MazeSolverRecursive; +import h06.problems.ProblemSolver; +import h06.ui.MazeVisualizer; +import h06.ui.ProblemVisualizer; +import h06.world.DirectionVector; +import h06.world.World; + +import java.awt.Point; + /** * Main entry point in executing the program. */ @@ -12,5 +21,35 @@ public class Main { */ public static void main(String[] args) { System.out.println("Hello World!"); + + World world = new World(5, 5); + Point start = new Point(2, 0); + Point end = new Point(2, 4); + DirectionVector direction = DirectionVector.UP; + + world.placeWall(0, 0, false); + world.placeWall(0, 1, false); + world.placeWall(0, 2, false); + world.placeWall(0, 3, false); + world.placeWall(1, 3, false); + world.placeWall(1, 4, false); + world.placeWall(2, 0, false); + world.placeWall(3, 1, false); + world.placeWall(3, 3, false); + + world.placeWall(1, 1, true); + world.placeWall(2, 0, true); + world.placeWall(2, 1, true); + world.placeWall(2, 2, true); + world.placeWall(3, 1, true); + world.placeWall(3, 3, true); + world.placeWall(4, 2, true); + + + ProblemVisualizer visualizer = new MazeVisualizer(); + ProblemSolver solver = new MazeSolverRecursive(); + visualizer.init(world); + visualizer.show(); + visualizer.run(solver, start, end, direction); } } diff --git a/src/main/java/h06/problems/MazeSolver.java b/src/main/java/h06/problems/MazeSolver.java index a809de8..cd4692c 100644 --- a/src/main/java/h06/problems/MazeSolver.java +++ b/src/main/java/h06/problems/MazeSolver.java @@ -1,9 +1,12 @@ package h06.problems; +import org.tudalgo.algoutils.student.annotation.DoNotTouch; + /** * A solver for a maze. * * @author Nhan Huynh */ +@DoNotTouch public interface MazeSolver extends ProblemSolver { } diff --git a/src/main/java/h06/problems/MazeSolverIterative.java b/src/main/java/h06/problems/MazeSolverIterative.java index 29f3c2a..9cf635e 100644 --- a/src/main/java/h06/problems/MazeSolverIterative.java +++ b/src/main/java/h06/problems/MazeSolverIterative.java @@ -2,6 +2,8 @@ import h06.world.DirectionVector; import h06.world.World; +import org.tudalgo.algoutils.student.annotation.DoNotTouch; +import org.tudalgo.algoutils.student.annotation.StudentImplementationRequired; import java.awt.Point; @@ -16,9 +18,11 @@ public class MazeSolverIterative implements MazeSolver { /** * Constructs an iterative maze solver. */ + @DoNotTouch public MazeSolverIterative() { } + @StudentImplementationRequired @Override public DirectionVector nextStep(World world, Point p, DirectionVector d) { DirectionVector next = d.rotate270(); @@ -31,6 +35,7 @@ public DirectionVector nextStep(World world, Point p, DirectionVector d) { return d; } + @StudentImplementationRequired @Override public int numberOfSteps(World world, Point s, Point e, DirectionVector d) { int steps = 0; @@ -45,6 +50,7 @@ public int numberOfSteps(World world, Point s, Point e, DirectionVector d) { return steps; } + @StudentImplementationRequired @Override public Point[] solve(World world, Point s, Point e, DirectionVector d) { int size = numberOfSteps(world, s, e, d); diff --git a/src/main/java/h06/problems/MazeSolverRecursive.java b/src/main/java/h06/problems/MazeSolverRecursive.java index 24c3772..ea072b5 100644 --- a/src/main/java/h06/problems/MazeSolverRecursive.java +++ b/src/main/java/h06/problems/MazeSolverRecursive.java @@ -2,6 +2,8 @@ import h06.world.DirectionVector; import h06.world.World; +import org.tudalgo.algoutils.student.annotation.DoNotTouch; +import org.tudalgo.algoutils.student.annotation.StudentImplementationRequired; import java.awt.Point; @@ -16,14 +18,17 @@ public class MazeSolverRecursive implements MazeSolver { /** * Constructs a recursive maze solver. */ + @DoNotTouch public MazeSolverRecursive() { } + @StudentImplementationRequired @Override public DirectionVector nextStep(World world, Point p, DirectionVector d) { return !world.isBlocked(p, d.rotate270()) ? d.rotate270() : nextStep(world, p, d.rotate90()); } + @StudentImplementationRequired @Override public int numberOfSteps(World world, Point s, Point e, DirectionVector d) { if (s.equals(e)) { @@ -33,6 +38,7 @@ public int numberOfSteps(World world, Point s, Point e, DirectionVector d) { return 1 + numberOfSteps(world, next.getMovement(s), e, next); } + @StudentImplementationRequired @Override public Point[] solve(World world, Point s, Point e, DirectionVector d) { int size = numberOfSteps(world, s, e, d); @@ -51,6 +57,7 @@ public Point[] solve(World world, Point s, Point e, DirectionVector d) { * @param path the path calculated so far from s to p * @param index the index of the next free spot in path */ + @StudentImplementationRequired private void solveHelper(World world, Point p, Point e, DirectionVector d, Point[] path, int index) { if (p.equals(e)) { path[index] = p; diff --git a/src/main/java/h06/problems/ProblemSolver.java b/src/main/java/h06/problems/ProblemSolver.java index 4d6b3ca..c8643e1 100644 --- a/src/main/java/h06/problems/ProblemSolver.java +++ b/src/main/java/h06/problems/ProblemSolver.java @@ -2,6 +2,7 @@ import h06.world.DirectionVector; import h06.world.World; +import org.tudalgo.algoutils.student.annotation.DoNotTouch; import java.awt.Point; @@ -10,6 +11,7 @@ * * @author Nhan Huynh */ +@DoNotTouch public interface ProblemSolver { /** diff --git a/src/main/java/h06/ui/MazeVisualizer.java b/src/main/java/h06/ui/MazeVisualizer.java index 7807f57..babb4db 100644 --- a/src/main/java/h06/ui/MazeVisualizer.java +++ b/src/main/java/h06/ui/MazeVisualizer.java @@ -5,6 +5,7 @@ import h06.problems.ProblemSolver; import h06.world.DirectionVector; import h06.world.World; +import org.tudalgo.algoutils.student.annotation.DoNotTouch; import java.awt.Color; import java.awt.Point; @@ -14,6 +15,7 @@ * * @author Nhan Huynh */ +@DoNotTouch public class MazeVisualizer implements ProblemVisualizer { /** diff --git a/src/main/java/h06/ui/ProblemVisualizer.java b/src/main/java/h06/ui/ProblemVisualizer.java index 710d122..3c17cb7 100644 --- a/src/main/java/h06/ui/ProblemVisualizer.java +++ b/src/main/java/h06/ui/ProblemVisualizer.java @@ -3,6 +3,7 @@ import h06.problems.ProblemSolver; import h06.world.DirectionVector; import h06.world.World; +import org.tudalgo.algoutils.student.annotation.DoNotTouch; import java.awt.Point; @@ -11,6 +12,7 @@ * * @author Nhan Huynh */ +@DoNotTouch public interface ProblemVisualizer { /** diff --git a/src/main/java/h06/world/DirectionVector.java b/src/main/java/h06/world/DirectionVector.java index 3383b5a..814423e 100644 --- a/src/main/java/h06/world/DirectionVector.java +++ b/src/main/java/h06/world/DirectionVector.java @@ -1,5 +1,7 @@ package h06.world; +import org.tudalgo.algoutils.student.annotation.StudentImplementationRequired; + import java.awt.Point; /** @@ -59,6 +61,7 @@ public enum DirectionVector { * * @return the direction vector counterclockwise to this direction vector */ + @StudentImplementationRequired public DirectionVector rotate270() { return this == UP ? LEFT : this == LEFT ? DOWN : this == DOWN ? RIGHT : UP; } @@ -68,6 +71,7 @@ public DirectionVector rotate270() { * * @return the direction vector clockwise to this direction vector */ + @StudentImplementationRequired public DirectionVector rotate90() { if (this == UP) { return RIGHT; diff --git a/src/main/java/h06/world/Field.java b/src/main/java/h06/world/Field.java index e41c3cc..8fa74b2 100644 --- a/src/main/java/h06/world/Field.java +++ b/src/main/java/h06/world/Field.java @@ -1,12 +1,14 @@ package h06.world; import fopbot.FieldEntity; +import org.tudalgo.algoutils.student.annotation.DoNotTouch; /** * A field in a world which can contains entities. * * @author Nhan Huynh */ +@DoNotTouch public class Field { /** diff --git a/src/main/java/h06/world/Wall.java b/src/main/java/h06/world/Wall.java index 9b538db..b990b28 100644 --- a/src/main/java/h06/world/Wall.java +++ b/src/main/java/h06/world/Wall.java @@ -1,12 +1,14 @@ package h06.world; import fopbot.FieldEntity; +import org.tudalgo.algoutils.student.annotation.DoNotTouch; /** * A wall with orientation. * * @author Nhan Huynh */ +@DoNotTouch public class Wall extends FieldEntity { /** diff --git a/src/main/java/h06/world/World.java b/src/main/java/h06/world/World.java index 49da027..05aa32e 100644 --- a/src/main/java/h06/world/World.java +++ b/src/main/java/h06/world/World.java @@ -2,6 +2,7 @@ import fopbot.Field; import fopbot.FieldEntity; +import org.tudalgo.algoutils.student.annotation.StudentImplementationRequired; import java.awt.Point; @@ -126,6 +127,7 @@ public boolean isBlocked(int x, int y, boolean horizontal) { * @param d the direction vector to add to the point * @return {@code true} if the position is blocked, {@code false} otherwise */ + @StudentImplementationRequired public boolean isBlocked(Point p, DirectionVector d) { // Outside if (isOutside(p, d)) {