package ch.epfl.maze.util; import java.util.HashMap; import java.util.Map; /** * A trail keeping track on positional markings. * * @author Pacien TRAN-GIRARD */ public class Trail { public enum Marking { NO_MARKING, AVOID_MARKING, NO_GO_MARKING; public static final Marking DEFAULT = NO_MARKING; public static final Marking[] ALL = new Marking[]{NO_MARKING, AVOID_MARKING, NO_GO_MARKING}; /** * Returns the next Marking. * * @return The next Marking */ public Marking getNext() { switch (this) { case NO_MARKING: return AVOID_MARKING; case AVOID_MARKING: return NO_GO_MARKING; case NO_GO_MARKING: return NO_GO_MARKING; default: return AVOID_MARKING; } } } private final Map trail; /** * Constructs a new blank Trail. */ public Trail() { this.trail = new HashMap<>(); } /** * Get the marking at the given position. * * @param position The positional Vector * @return The Marking */ public Marking getMarking(Vector2D position) { Marking marking = this.trail.get(position); return marking != null ? marking : Marking.NO_MARKING; } /** * Marks the given position with the given Marking. * * @param position The positional vector * @param marking The Marking */ public void markPosition(Vector2D position, Marking marking) { this.trail.put(position, marking); } /** * Marks the given position with the following Marking. * * @param position The positional vector */ public void markPosition(Vector2D position) { this.markPosition(position, this.getMarking(position).getNext()); } }