summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/util/Trail.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/ch/epfl/maze/util/Trail.java')
-rw-r--r--src/ch/epfl/maze/util/Trail.java79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/ch/epfl/maze/util/Trail.java b/src/ch/epfl/maze/util/Trail.java
new file mode 100644
index 0000000..351db8f
--- /dev/null
+++ b/src/ch/epfl/maze/util/Trail.java
@@ -0,0 +1,79 @@
1package ch.epfl.maze.util;
2
3import java.util.HashMap;
4import java.util.Map;
5
6/**
7 * A trail keeping track on positional markings.
8 *
9 * @author Pacien TRAN-GIRARD
10 */
11public class Trail {
12
13 public enum Marking {
14 NO_MARKING,
15 AVOID_MARKING,
16 NO_GO_MARKING;
17
18 public static Marking DEFAULT = NO_MARKING;
19 public static Marking[] ALL = new Marking[]{NO_MARKING, AVOID_MARKING, NO_GO_MARKING};
20
21 /**
22 * Returns the next Marking.
23 *
24 * @return The next Marking
25 */
26 public Marking getNext() {
27 switch (this) {
28 case NO_MARKING:
29 return AVOID_MARKING;
30 case AVOID_MARKING:
31 return NO_GO_MARKING;
32 case NO_GO_MARKING:
33 return NO_GO_MARKING;
34 default:
35 return AVOID_MARKING;
36 }
37 }
38 }
39
40 private final Map<Vector2D, Marking> trail;
41
42 /**
43 * Constructs a new blank Trail.
44 */
45 public Trail() {
46 this.trail = new HashMap<>();
47 }
48
49 /**
50 * Get the marking at the given position.
51 *
52 * @param position The positional Vector
53 * @return The Marking
54 */
55 public Marking getMarking(Vector2D position) {
56 Marking marking = this.trail.get(position);
57 return marking != null ? marking : Marking.DEFAULT;
58 }
59
60 /**
61 * Marks the given position with the given Marking.
62 *
63 * @param position The positional vector
64 * @param marking The Marking
65 */
66 public void markPosition(Vector2D position, Marking marking) {
67 this.trail.put(position, marking);
68 }
69
70 /**
71 * Marks the given position with the following Marking.
72 *
73 * @param position The positional vector
74 */
75 public void markPosition(Vector2D position) {
76 this.markPosition(position, this.getMarking(position).getNext());
77 }
78
79}