Skip to content

Commit

Permalink
Add annotation (#6)
Browse files Browse the repository at this point in the history
Co-authored-by: zentox <[email protected]>
  • Loading branch information
zentox and zentox authored Aug 29, 2023
1 parent 68d9306 commit 4f7a4c5
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/main/java/h06/Main.java
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand All @@ -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);
}
}
3 changes: 3 additions & 0 deletions src/main/java/h06/problems/MazeSolver.java
Original file line number Diff line number Diff line change
@@ -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 {
}
6 changes: 6 additions & 0 deletions src/main/java/h06/problems/MazeSolverIterative.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/h06/problems/MazeSolverRecursive.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)) {
Expand All @@ -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);
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/h06/problems/ProblemSolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import h06.world.DirectionVector;
import h06.world.World;
import org.tudalgo.algoutils.student.annotation.DoNotTouch;

import java.awt.Point;

Expand All @@ -10,6 +11,7 @@
*
* @author Nhan Huynh
*/
@DoNotTouch
public interface ProblemSolver {

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/h06/ui/MazeVisualizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,6 +15,7 @@
*
* @author Nhan Huynh
*/
@DoNotTouch
public class MazeVisualizer implements ProblemVisualizer {

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/h06/ui/ProblemVisualizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -11,6 +12,7 @@
*
* @author Nhan Huynh
*/
@DoNotTouch
public interface ProblemVisualizer {

/**
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/h06/world/DirectionVector.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package h06.world;

import org.tudalgo.algoutils.student.annotation.StudentImplementationRequired;

import java.awt.Point;

/**
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/h06/world/Field.java
Original file line number Diff line number Diff line change
@@ -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 {

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/h06/world/Wall.java
Original file line number Diff line number Diff line change
@@ -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 {

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/h06/world/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import fopbot.Field;
import fopbot.FieldEntity;
import org.tudalgo.algoutils.student.annotation.StudentImplementationRequired;

import java.awt.Point;

Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 4f7a4c5

Please sign in to comment.