From 655ac88f4e73b2df532a451aedf5a561ea1b0d2c Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 21 Nov 2015 10:36:18 +0100 Subject: Import project structure --- src/ch/epfl/maze/util/Action.java | 101 +++++ src/ch/epfl/maze/util/Direction.java | 235 ++++++++++++ src/ch/epfl/maze/util/LabyrinthGenerator.java | 533 ++++++++++++++++++++++++++ src/ch/epfl/maze/util/Statistics.java | 197 ++++++++++ src/ch/epfl/maze/util/Vector2D.java | 228 +++++++++++ 5 files changed, 1294 insertions(+) create mode 100644 src/ch/epfl/maze/util/Action.java create mode 100644 src/ch/epfl/maze/util/Direction.java create mode 100644 src/ch/epfl/maze/util/LabyrinthGenerator.java create mode 100644 src/ch/epfl/maze/util/Statistics.java create mode 100644 src/ch/epfl/maze/util/Vector2D.java (limited to 'src/ch/epfl/maze/util') diff --git a/src/ch/epfl/maze/util/Action.java b/src/ch/epfl/maze/util/Action.java new file mode 100644 index 0000000..491627f --- /dev/null +++ b/src/ch/epfl/maze/util/Action.java @@ -0,0 +1,101 @@ +package ch.epfl.maze.util; + +/** + * Immutable action that encapsulates a choice made by an animal and information + * about it, such as if it was successful or not, and if the animal will die + * while performing it. + * + */ + +public final class Action { + + /* variables defining the action */ + private final Direction mDirection; + private final boolean mSuccess; + private final boolean mDies; + + /** + * Constructs a successful action of an animal towards a specified + * direction, that does not die between two squares. + * + * @param dir + * Direction towards which the action needs to be performed + */ + + public Action(Direction dir) { + if (dir != null) { + mDirection = dir; + } else { + mDirection = Direction.NONE; + } + mSuccess = true; + mDies = false; + } + + /** + * Constructs an action of an animal towards a specified direction, with a + * specified success, that does not die between two squares. + * + * @param dir + * Direction towards which the action needs to be performed + * @param successful + * Determines whether this action was successful + */ + + public Action(Direction dir, boolean successful) { + mDirection = dir; + mSuccess = successful; + mDies = false; + } + + /** + * Constructs an action of an animal towards a specified direction, with a + * specified success, and that also specifies if the animal dies between two + * squares. + * + * @param dir + * Direction towards which the action needs to be performed + * @param successful + * Determines whether this action was successful + * @param dies + * Determines whether the action will die between two squares + */ + + public Action(Direction dir, boolean successful, boolean dies) { + mDirection = dir; + mSuccess = successful; + mDies = dies; + } + + /** + * Retrieves the direction towards which the action shall move. + * + * @return Direction of the action + */ + + public Direction getDirection() { + return mDirection; + } + + /** + * Determines if the action was successful or not. + * + * @return true if the action was successful, false otherwise + */ + + public boolean isSuccessful() { + return mSuccess; + } + + /** + * Determines if the animal performing the action dies while moving from a + * square to another. + * + * @return true if the action dies between two squares, false + * otherwise + */ + + public boolean diesBetweenSquares() { + return mDies; + } +} diff --git a/src/ch/epfl/maze/util/Direction.java b/src/ch/epfl/maze/util/Direction.java new file mode 100644 index 0000000..a75ba7f --- /dev/null +++ b/src/ch/epfl/maze/util/Direction.java @@ -0,0 +1,235 @@ +package ch.epfl.maze.util; + +/** + * Directions that an animal can take to move. They represent the four cardinal + * points ({@code DOWN, UP, RIGHT, LEFT}) from the frame of reference of the + * labyrinth, plus a default one : {@code NONE}. + * + */ + +public enum Direction { + DOWN, UP, RIGHT, LEFT, NONE; + + /** + * Returns the integer value of the direction + * + * @return Integer value of the direction + */ + + public int intValue() { + switch (this) { + case DOWN: + return 0; + + case UP: + return 1; + + case RIGHT: + return 2; + + case LEFT: + return 3; + + case NONE: + default: + return 4; + } + } + + /** + * Converts the direction into an orthonormal vector, when possible. + * + * @return Orthonormal {@code Vector2D} that represents the direction. + */ + + public Vector2D toVector() { + switch (this) { + case DOWN: + return new Vector2D(0, 1); + + case UP: + return new Vector2D(0, -1); + + case RIGHT: + return new Vector2D(1, 0); + + case LEFT: + return new Vector2D(-1, 0); + + case NONE: + default: + return new Vector2D(0, 0); + } + } + + /** + * Reverses the direction. + * + * @return The opposite direction. + */ + + public Direction reverse() { + switch (this) { + case DOWN: + return UP; + + case UP: + return DOWN; + + case RIGHT: + return LEFT; + + case LEFT: + return RIGHT; + + case NONE: + default: + return NONE; + } + } + + /** + * Determines whether the argument is the opposite of another. + * + * @param d + * The direction to compare with + * @return true if the direction is the opposite the argument, + * false otherwise + */ + + public boolean isOpposite(Direction d) { + return this == d.reverse(); + } + + /** + * Converts the argument relative to the frame of reference given by the + * direction that calls the method. + * + * @param dir + * The direction to convert + * @return The direction converted to the frame of reference given by the + * direction called. + */ + + public Direction relativeDirection(Direction dir) { + switch (this) { + case DOWN: + return dir.reverse(); + + case UP: + return dir; + + case RIGHT: + return dir.rotateLeft(); + + case LEFT: + return dir.rotateRight(); + + case NONE: + default: + return NONE; + } + } + + /** + * Converts the argument back to the frame of reference of the labyrinth + * + * @param dir + * The direction to convert back + * @return The direction converted back to the frame of reference of the + * labyrinth + */ + + public Direction unRelativeDirection(Direction dir) { + switch (this) { + case DOWN: + return dir.reverse(); + + case UP: + return dir; + + case RIGHT: + return dir.rotateRight(); + + case LEFT: + return dir.rotateLeft(); + + case NONE: + default: + return NONE; + } + } + + /** + * Rotates the direction to the right. + * + * @return The rotated direction to the right + */ + + public Direction rotateRight() { + switch (this) { + case DOWN: + return LEFT; + + case UP: + return RIGHT; + + case RIGHT: + return DOWN; + + case LEFT: + return UP; + + case NONE: + default: + return NONE; + } + } + + /** + * Rotates the direction to the left. + * + * @return The rotated direction to the left + */ + + public Direction rotateLeft() { + switch (this) { + case DOWN: + return RIGHT; + + case UP: + return LEFT; + + case RIGHT: + return UP; + + case LEFT: + return DOWN; + + case NONE: + default: + return NONE; + } + } + + /** + * Applies the change of coordinates relative to the frame of reference + * of the direction that calls the method to all the directions in the + * argument. + * + * @param dir + * The array of directions to convert + * @return The directions converted to the frame of reference given by the + * direction which calls the method + */ + + public Direction[] relativeDirections(Direction[] dir) { + Direction[] relativeDirections = new Direction[dir.length]; + + for (int i = 0; i < dir.length; i++) { + relativeDirections[i] = this.relativeDirection(dir[i]); + } + + return relativeDirections; + } +} diff --git a/src/ch/epfl/maze/util/LabyrinthGenerator.java b/src/ch/epfl/maze/util/LabyrinthGenerator.java new file mode 100644 index 0000000..f0e5f1b --- /dev/null +++ b/src/ch/epfl/maze/util/LabyrinthGenerator.java @@ -0,0 +1,533 @@ +package ch.epfl.maze.util; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Scanner; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Generates a set of pre-computed labyrinth structures + * + */ + +public final class LabyrinthGenerator { + + /** + * Returns a precomputed labyrinth of small size. + * + * @return A small labyrinth + */ + + public static int[][] getSmall() { + int[][] labyrinth = { + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1 }, + { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 }, + { 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1 }, + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, + { 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1 }, + { 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1 }, + { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1 }, + { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 }, + { 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1 }, + { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 }, + { 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, + }; + + return labyrinth; + } + + /** + * Returns a precomputed labyrinth of medium size. + * + * @return A medium labyrinth + */ + + public static int[][] getMedium() { + int[][] labyrinth = { + { 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, + { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, + { 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, + { 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, + { 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1 }, + { 1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, 1, 0, 1, 0, 1, 0, 1 }, + { 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1 }, + { 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1 }, + { 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1 }, + { 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1 }, + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1 }, + { 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1 }, + { 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1 }, + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } + }; + + return labyrinth; + } + + // ============================================================== + + // ============================================================== + + /** + * Returns the labyrinth structure of the Pac-Man level. + * + * @return The Pac-Man level + */ + + public static int[][] getPacMan() { + int[][] labyrinth = { + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, + { 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 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 0, 0, 0, 0, 0, 0, 0, 1 }, + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } + }; + + return labyrinth; + } + + // ============================================================== + + /** + * Returns the labyrinth structure of one of the Ms. Pac-Man levels. + * + * @return One of the Ms. Pac-Man levels + */ + + public static int[][] getMsPacMan() { + int[][] labyrinth = { + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, + { 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1 }, + { 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1 }, + { 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1 }, + { 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1 }, + { 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1 }, + { 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0 }, + { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1 }, + { 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1 }, + { 1, 0, 0, 0, 0, 1, 0, 1, -1, -1, -1, 1, 0, 1, 0, 0, 0, 0, 1 }, + { 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1 }, + { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1 }, + { 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1 }, + { 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1 }, + { 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1 }, + { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1 }, + { 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1 }, + { 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1 }, + { 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1 }, + { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }, + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } + }; + + return labyrinth; + } + + /** + * Returns a hard-coded labyrinth which is multiply connected. + *
+ * If the Monkey algorithm is run on this labyrinth, it will never find the + * solution. + * + * @return A labyrinth multiply connected + */ + + public static int[][] getMultiplyConnected() { + int[][] labyrinth = { + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, }, + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, }, + { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, }, + { 1, 0, 0, 3, 1, 0, 1, 0, 0, 0, 1, }, + { 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, }, + { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, }, + { 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, }, + { 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, }, + { 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, }, + { 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, }, + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, } + }; + + return labyrinth; + } + + // ============================================================== + + /** + * Returns a hard-coded maze for debugging the Mouse. + * + * @return A maze for debugging the Mouse + */ + + public static int[][] getDebugMouse() { + int[][] labyrinth = { + { 1, 1, 1, 1, 1, 1, 1 }, + { 2, 0, 0, 0, 0, 0, 1 }, + { 1, 1, 1, 1, 1, 0, 1 }, + { 1, 3, 1, 1, 1, 0, 1 }, + { 1, 0, 1, 1, 1, 0, 1 }, + { 1, 0, 0, 0, 0, 0, 1 }, + { 1, 1, 1, 1, 1, 1, 1 } + }; + + return labyrinth; + } + + /** + * Returns a hard-coded maze for debugging the Hamster. + * + * @return A maze for debugging the Hamster + */ + + public static int[][] getDebugHamster() { + int[][] labyrinth = { + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, + { 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1 }, + { 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1 }, + { 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3 }, + { 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1 }, + { 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1 }, + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } + }; + + return labyrinth; + } + + /** + * Returns a hard-coded maze for debugging the Monkey. + * + * @return A maze for debugging the Monkey + */ + + public static int[][] getDebugMonkey() { + int[][] labyrinth = { + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, + { 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1 }, + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 }, + { 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1 }, + { 1, 1, 0, 1, 1, 1, 3, 1, 0, 1, 1 }, + { 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1 }, + { 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1 }, + { 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1 } + }; + + return labyrinth; + } + + /** + * Returns a hard-coded maze for debugging the Bear. + * + * @return A maze for debugging the Bear + */ + + public static int[][] getDebugBear1() { + int[][] labyrinth = { + { 1, 1, 1, 2, 1, 1, 1, }, + { 1, 0, 0, 0, 1, 0, 1, }, + { 1, 0, 0, 0, 0, 0, 1, }, + { 1, 0, 0, 0, 0, 0, 1, }, + { 1, 1, 1, 1, 0, 0, 1, }, + { 3, 0, 0, 0, 0, 0, 1, }, + { 1, 1, 1, 1, 1, 1, 1, } + }; + + return labyrinth; + } + + /** + * Returns a hard-coded maze for debugging the Bear. + * + * @return A maze for debugging the Bear + */ + + public static int[][] getDebugBear2() { + int[][] labyrinth = { + { 1, 2, 1, 1 }, + { 1, 0, 1, 1 }, + { 1, 0, 0, 3 }, + { 1, 0, 1, 1 }, + { 1, 0, 1, 1 }, + { 1, 1, 1, 1 } + }; + + return labyrinth; + } + + /** + * Returns a hard-coded maze for debugging the Panda. + * + * @return A maze for debugging the Panda + */ + + public static int[][] getDebugPanda1() { + int[][] labyrinth = { + { 1, 1, 1, 2, 1, 1, 1 }, + { 1, 1, 1, 0, 1, 1, 1 }, + { 1, 0, 0, 0, 0, 0, 1 }, + { 1, 0, 1, 1, 1, 0, 1 }, + { 1, 0, 0, 0, 0, 0, 1 }, + { 1, 1, 1, 1, 1, 1, 1 } + }; + + return labyrinth; + } + + /** + * Returns a hard-coded maze for debugging the Panda. + * + * @return A maze for debugging the Panda + */ + + public static int[][] getDebugPanda2() { + int[][] labyrinth = { + { 1, 1, 1, 1, 1, 1, 1, 1, 1 }, + { 1, 1, 1, 1, 0, 1, 1, 1, 1 }, + { 1, 1, 1, 1, 0, 1, 1, 1, 1 }, + { 1, 1, 1, 1, 0, 1, 1, 1, 1 }, + { 1, 0, 0, 0, 2, 0, 0, 0, 1 }, + { 1, 1, 1, 1, 0, 1, 1, 1, 1 }, + { 1, 1, 1, 1, 0, 1, 1, 1, 1 }, + { 1, 1, 1, 1, 0, 1, 1, 1, 1 }, + { 1, 1, 1, 1, 1, 1, 1, 1, 1 } + }; + + return labyrinth; + } + + // ============================================================== + + /** + * Returns a hard-coded maze that shows the efficiency of the Bear over + * the Monkey. + * + * @return A maze to run with a Bear and a Monkey + */ + + public static int[][] getBearVsMonkey() { + int[][] labyrinth = { + { 1, 1, 1, 3, 1, 1, 1 }, + { 1, 0, 0, 0, 0, 0, 1 }, + { 1, 0, 1, 1, 1, 0, 1 }, + { 1, 0, 0, 2, 0, 0, 1 }, + { 1, 1, 1, 1, 1, 1, 1 } + }; + + return labyrinth; + } + + /** + * Returns a hard-coded maze that shows the efficiency of the Panda over + * the Hamster. + * + * @return A maze to run with a Panda and a Hamster + */ + + public static int[][] getPandaVsHamster() { + int[][] labyrinth = { + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1 }, + { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 }, + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, + { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 }, + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, + { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 }, + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, + { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 }, + { 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } + }; + + return labyrinth; + } + + // ============================================================== + + /** + * Returns a hard-coded maze for debugging Blinky. + * + * @return A maze for debugging Blinky + */ + + public static int[][] getDebugBlinky() { + int[][] labyrinth = { + { 1, 1, 1, 1, 1, 1, 1, 1 }, + { 1, 0, 0, 0, 0, 0, 0, 1 }, + { 1, 0, 1, 0, 1, 1, 0, 1 }, + { 1, 0, 0, 0, 0, 0, 0, 1 }, + { 1, 0, 1, 0, 1, 1, 0, 1 }, + { 1, 0, 0, 0, 0, 0, 0, 1 }, + { 1, 1, 1, 1, 1, 1, 1, 1 } + }; + + return labyrinth; + } + + /** + * Returns a hard-coded maze for debugging Pinky. + * + * @return A maze for debugging Pinky + */ + + public static int[][] getDebugPinky() { + int[][] labyrinth = { + { 1, 1, 1, 1, 1, 1, 1, 1, 1 }, + { 1, 0, 0, 0, 0, 0, 0, 0, 1 }, + { 1, 0, 1, 0, 1, 1, 1, 0, 1 }, + { 1, 0, 0, 0, 0, 0, 0, 0, 1 }, + { 1, 1, 1, 1, 1, 1, 1, 1, 1 } + }; + + return labyrinth; + } + + /** + * Returns a hard-coded maze for debugging Inky. + * + * @return A maze for debugging Inky + */ + + public static int[][] getDebugInky() { + int[][] labyrinth = { + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, + { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 }, + { 1, 0, 0, 3, 0, 0, 0, 0, 0, 0, 1 }, + { 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1 }, + { 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1 }, + { 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1 }, + { 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1 }, + { 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1 }, + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } + }; + + return labyrinth; + } + + /** + * Returns a hard-coded maze for debugging Clyde. + * + * @return A maze for debugging Clyde + */ + + public static int[][] getDebugClyde() { + int[][] labyrinth = { + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, }, + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, }, + { 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, }, + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, }, + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, } + }; + + return labyrinth; + } + + // ============================================================== + + /** + * Reads and returns a labyrinth from specified file. + *
+ * The file must be present in the root folder of the project.
+ *
+ * @param filename
+ * The file location
+ * @return Labyrinth structure parsed from a file
+ */
+
+ public static int[][] readFromFile(String filename) {
+ File file = new File(filename);
+ int[][] labyrinth = null;
+ Scanner scanner = null;
+
+ try {
+ scanner = new Scanner(file);
+
+ // reads one line after the other
+ ArrayList
+ * mean(X) = total(X) / N
+ *
+ * @param results
+ * List of numbers
+ * @return The mean of the results
+ */
+
+ public static int mean(List
+ * var(X) = (X - mean(X)) / N
+ *
+ * @param results
+ * List of numbers
+ * @return The variance of the results
+ */
+
+ public static double var(List
+ * std(X) = sqrt(var(X))
+ *
+ * @param results
+ * List of numbers
+ * @return The variance of the results
+ */
+
+ public static double std(List