summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/ch/epfl/maze/util')
-rw-r--r--src/ch/epfl/maze/util/Action.java149
-rw-r--r--src/ch/epfl/maze/util/Direction.java445
-rw-r--r--src/ch/epfl/maze/util/LabyrinthGenerator.java1032
-rw-r--r--src/ch/epfl/maze/util/Statistics.java357
-rw-r--r--src/ch/epfl/maze/util/Vector2D.java426
5 files changed, 1185 insertions, 1224 deletions
diff --git a/src/ch/epfl/maze/util/Action.java b/src/ch/epfl/maze/util/Action.java
index 491627f..25509a4 100644
--- a/src/ch/epfl/maze/util/Action.java
+++ b/src/ch/epfl/maze/util/Action.java
@@ -4,98 +4,91 @@ package ch.epfl.maze.util;
4 * Immutable action that encapsulates a choice made by an animal and information 4 * Immutable action that encapsulates a choice made by an animal and information
5 * about it, such as if it was successful or not, and if the animal will die 5 * about it, such as if it was successful or not, and if the animal will die
6 * <i>while</i> performing it. 6 * <i>while</i> performing it.
7 *
8 */ 7 */
9 8
10public final class Action { 9public final class Action {
11 10
12 /* variables defining the action */ 11 /* variables defining the action */
13 private final Direction mDirection; 12 private final Direction mDirection;
14 private final boolean mSuccess; 13 private final boolean mSuccess;
15 private final boolean mDies; 14 private final boolean mDies;
16 15
17 /** 16 /**
18 * Constructs a successful action of an animal towards a specified 17 * Constructs a successful action of an animal towards a specified
19 * direction, that does not die between two squares. 18 * direction, that does not die between two squares.
20 * 19 *
21 * @param dir 20 * @param dir Direction towards which the action needs to be performed
22 * Direction towards which the action needs to be performed 21 */
23 */
24 22
25 public Action(Direction dir) { 23 public Action(Direction dir) {
26 if (dir != null) { 24 if (dir != null) {
27 mDirection = dir; 25 mDirection = dir;
28 } else { 26 } else {
29 mDirection = Direction.NONE; 27 mDirection = Direction.NONE;
30 } 28 }
31 mSuccess = true; 29 mSuccess = true;
32 mDies = false; 30 mDies = false;
33 } 31 }
34 32
35 /** 33 /**
36 * Constructs an action of an animal towards a specified direction, with a 34 * Constructs an action of an animal towards a specified direction, with a
37 * specified success, that does not die between two squares. 35 * specified success, that does not die between two squares.
38 * 36 *
39 * @param dir 37 * @param dir Direction towards which the action needs to be performed
40 * Direction towards which the action needs to be performed 38 * @param successful Determines whether this action was successful
41 * @param successful 39 */
42 * Determines whether this action was successful
43 */
44 40
45 public Action(Direction dir, boolean successful) { 41 public Action(Direction dir, boolean successful) {
46 mDirection = dir; 42 mDirection = dir;
47 mSuccess = successful; 43 mSuccess = successful;
48 mDies = false; 44 mDies = false;
49 } 45 }
50 46
51 /** 47 /**
52 * Constructs an action of an animal towards a specified direction, with a 48 * Constructs an action of an animal towards a specified direction, with a
53 * specified success, and that also specifies if the animal dies between two 49 * specified success, and that also specifies if the animal dies between two
54 * squares. 50 * squares.
55 * 51 *
56 * @param dir 52 * @param dir Direction towards which the action needs to be performed
57 * Direction towards which the action needs to be performed 53 * @param successful Determines whether this action was successful
58 * @param successful 54 * @param dies Determines whether the action will die between two squares
59 * Determines whether this action was successful 55 */
60 * @param dies
61 * Determines whether the action will die between two squares
62 */
63 56
64 public Action(Direction dir, boolean successful, boolean dies) { 57 public Action(Direction dir, boolean successful, boolean dies) {
65 mDirection = dir; 58 mDirection = dir;
66 mSuccess = successful; 59 mSuccess = successful;
67 mDies = dies; 60 mDies = dies;
68 } 61 }
69 62
70 /** 63 /**
71 * Retrieves the direction towards which the action shall move. 64 * Retrieves the direction towards which the action shall move.
72 * 65 *
73 * @return Direction of the action 66 * @return Direction of the action
74 */ 67 */
75 68
76 public Direction getDirection() { 69 public Direction getDirection() {
77 return mDirection; 70 return mDirection;
78 } 71 }
79 72
80 /** 73 /**
81 * Determines if the action was successful or not. 74 * Determines if the action was successful or not.
82 * 75 *
83 * @return <b>true</b> if the action was successful, <b>false</b> otherwise 76 * @return <b>true</b> if the action was successful, <b>false</b> otherwise
84 */ 77 */
85 78
86 public boolean isSuccessful() { 79 public boolean isSuccessful() {
87 return mSuccess; 80 return mSuccess;
88 } 81 }
89 82
90 /** 83 /**
91 * Determines if the animal performing the action dies while moving from a 84 * Determines if the animal performing the action dies while moving from a
92 * square to another. 85 * square to another.
93 * 86 *
94 * @return <b>true</b> if the action dies between two squares, <b>false</b> 87 * @return <b>true</b> if the action dies between two squares, <b>false</b>
95 * otherwise 88 * otherwise
96 */ 89 */
97 90
98 public boolean diesBetweenSquares() { 91 public boolean diesBetweenSquares() {
99 return mDies; 92 return mDies;
100 } 93 }
101} 94}
diff --git a/src/ch/epfl/maze/util/Direction.java b/src/ch/epfl/maze/util/Direction.java
index a75ba7f..e8c0993 100644
--- a/src/ch/epfl/maze/util/Direction.java
+++ b/src/ch/epfl/maze/util/Direction.java
@@ -4,232 +4,227 @@ package ch.epfl.maze.util;
4 * Directions that an animal can take to move. They represent the four cardinal 4 * Directions that an animal can take to move. They represent the four cardinal
5 * points ({@code DOWN, UP, RIGHT, LEFT}) from the frame of reference of the 5 * points ({@code DOWN, UP, RIGHT, LEFT}) from the frame of reference of the
6 * labyrinth, plus a default one : {@code NONE}. 6 * labyrinth, plus a default one : {@code NONE}.
7 *
8 */ 7 */
9 8
10public enum Direction { 9public enum Direction {
11 DOWN, UP, RIGHT, LEFT, NONE; 10 DOWN, UP, RIGHT, LEFT, NONE;
12 11
13 /** 12 /**
14 * Returns the integer value of the direction 13 * Returns the integer value of the direction
15 * 14 *
16 * @return Integer value of the direction 15 * @return Integer value of the direction
17 */ 16 */
18 17
19 public int intValue() { 18 public int intValue() {
20 switch (this) { 19 switch (this) {
21 case DOWN: 20 case DOWN:
22 return 0; 21 return 0;
23 22
24 case UP: 23 case UP:
25 return 1; 24 return 1;
26 25
27 case RIGHT: 26 case RIGHT:
28 return 2; 27 return 2;
29 28
30 case LEFT: 29 case LEFT:
31 return 3; 30 return 3;
32 31
33 case NONE: 32 case NONE:
34 default: 33 default:
35 return 4; 34 return 4;
36 } 35 }
37 } 36 }
38 37
39 /** 38 /**
40 * Converts the direction into an orthonormal vector, when possible. 39 * Converts the direction into an orthonormal vector, when possible.
41 * 40 *
42 * @return Orthonormal {@code Vector2D} that represents the direction. 41 * @return Orthonormal {@code Vector2D} that represents the direction.
43 */ 42 */
44 43
45 public Vector2D toVector() { 44 public Vector2D toVector() {
46 switch (this) { 45 switch (this) {
47 case DOWN: 46 case DOWN:
48 return new Vector2D(0, 1); 47 return new Vector2D(0, 1);
49 48