From bc477506342411e9156b3230d847cb92bcb8e5f9 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Tue, 24 Nov 2015 11:11:17 +0100 Subject: Reformat code --- src/ch/epfl/maze/physical/Animal.java | 7 +------ src/ch/epfl/maze/physical/GhostPredator.java | 4 ++-- src/ch/epfl/maze/physical/Maze.java | 6 +----- src/ch/epfl/maze/physical/World.java | 16 +--------------- src/ch/epfl/maze/physical/pacman/Pinky.java | 3 +-- src/ch/epfl/maze/physical/zoo/Hamster.java | 5 +---- src/ch/epfl/maze/physical/zoo/Monkey.java | 5 +---- src/ch/epfl/maze/physical/zoo/Panda.java | 2 +- src/ch/epfl/maze/physical/zoo/SpaceInvader.java | 4 +--- 9 files changed, 10 insertions(+), 42 deletions(-) (limited to 'src/ch/epfl/maze/physical') diff --git a/src/ch/epfl/maze/physical/Animal.java b/src/ch/epfl/maze/physical/Animal.java index 9123d82..0079d11 100644 --- a/src/ch/epfl/maze/physical/Animal.java +++ b/src/ch/epfl/maze/physical/Animal.java @@ -9,7 +9,6 @@ import ch.epfl.maze.util.Vector2D; * * @author Pacien TRAN-GIRARD */ - abstract public class Animal { private Vector2D position; @@ -19,7 +18,6 @@ abstract public class Animal { * * @param position Position of the animal in the labyrinth */ - public Animal(Vector2D position) { this.position = position; } @@ -33,7 +31,6 @@ abstract public class Animal { * World.getChoices(Vector2D)}) * @return The next direction of the animal, chosen in {@code choices} */ - abstract public Direction move(Direction[] choices); /** @@ -44,7 +41,6 @@ abstract public class Animal { * * @param dir Direction that the animal has taken */ - public final void update(Direction dir) { this.position = this.position.addDirectionTo(dir); } @@ -57,7 +53,6 @@ abstract public class Animal { * * @param position */ - public final void setPosition(Vector2D position) { this.position = position; } @@ -67,10 +62,10 @@ abstract public class Animal { * * @return Current position of animal. */ - public final Vector2D getPosition() { return this.position; } abstract public Animal copy(); + } diff --git a/src/ch/epfl/maze/physical/GhostPredator.java b/src/ch/epfl/maze/physical/GhostPredator.java index 8188c00..5408bf6 100644 --- a/src/ch/epfl/maze/physical/GhostPredator.java +++ b/src/ch/epfl/maze/physical/GhostPredator.java @@ -122,7 +122,7 @@ abstract public class GhostPredator extends Predator { /** * Calculates the Euclidean distance from the adjacent position at the given Direction to the target position. * - * @param dir The adjacent Direction + * @param dir The adjacent Direction * @param targetPosition The targeted position * @return The Euclidean distance between the two positions */ @@ -138,7 +138,7 @@ abstract public class GhostPredator extends Predator { * Selects the best Direction in the given choices by minimizing the Euclidean distance to the targeted position. * * @param targetPosition The targeted position - * @param choices An array of Direction choices + * @param choices An array of Direction choices * @return An array of optimal Direction choices */ private Direction[] selectBestPaths(Vector2D targetPosition, Direction[] choices) { diff --git a/src/ch/epfl/maze/physical/Maze.java b/src/ch/epfl/maze/physical/Maze.java index bff8791..51b9811 100644 --- a/src/ch/epfl/maze/physical/Maze.java +++ b/src/ch/epfl/maze/physical/Maze.java @@ -10,7 +10,6 @@ import java.util.List; * * @author Pacien TRAN-GIRARD */ - public final class Maze extends World { private final List animals; @@ -21,7 +20,6 @@ public final class Maze extends World { * * @param labyrinth Structure of the labyrinth, an NxM array of tiles */ - public Maze(int[][] labyrinth) { super(labyrinth); @@ -46,7 +44,6 @@ public final class Maze extends World { * @return true if the animal belongs to the world, false * otherwise. */ - public boolean hasAnimal(Animal a) { return this.animals.contains(a); } @@ -56,7 +53,6 @@ public final class Maze extends World { * * @param a The animal to add */ - public void addAnimal(Animal a) { a.setPosition(this.getStart()); this.animals.add(a); @@ -67,7 +63,6 @@ public final class Maze extends World { * * @param a The animal to remove */ - public void removeAnimal(Animal a) { boolean contained = this.animals.remove(a); if (contained) this.animalHistory.add(a); @@ -80,4 +75,5 @@ public final class Maze extends World { this.animalHistory.forEach(a -> this.addAnimal(a.copy())); this.animalHistory.clear(); } + } diff --git a/src/ch/epfl/maze/physical/World.java b/src/ch/epfl/maze/physical/World.java index f13b2b1..9afbd5e 100644 --- a/src/ch/epfl/maze/physical/World.java +++ b/src/ch/epfl/maze/physical/World.java @@ -12,7 +12,6 @@ import java.util.List; * * @author Pacien TRAN-GIRARD */ - public abstract class World { /* tiles constants */ @@ -25,7 +24,6 @@ public abstract class World { /** * Structure of the labyrinth, an NxM array of tiles */ - private final int[][] labyrinth; private final Vector2D start; @@ -36,7 +34,6 @@ public abstract class World { * * @param labyrinth Structure of the labyrinth, an NxM array of tiles */ - public World(int[][] labyrinth) { this.labyrinth = labyrinth; @@ -50,7 +47,6 @@ public abstract class World { * @param tileType Type of the tile * @return A Vector2D of the first occurrence of the given tile type */ - private Vector2D findFirstTileOfType(int tileType) { for (int x = 0; x < this.getWidth(); ++x) for (int y = 0; y < this.getHeight(); ++y) @@ -65,13 +61,11 @@ public abstract class World { * * @return true if no more moves can be made, false otherwise */ - abstract public boolean isSolved(); /** * Resets the world as when it was instantiated. */ - abstract public void reset(); /** @@ -79,7 +73,6 @@ public abstract class World { * * @return A list of all animals in the world */ - abstract public List getAnimals(); /** @@ -90,7 +83,6 @@ public abstract class World { * @return The tile number at position (x, y), or the NOTHING tile if x or y is * incorrect. */ - public final int getTile(int x, int y) { if (x < 0 || x >= this.getWidth()) return World.NOTHING; if (y < 0 || y >= this.getHeight()) return World.NOTHING; @@ -104,7 +96,6 @@ public abstract class World { * @param y Vertical coordinate * @return true if an animal can walk on tile, false otherwise */ - public final boolean isFree(int x, int y) { int tile = this.getTile(x, y); return !(tile == World.WALL || tile == World.NOTHING); @@ -116,7 +107,6 @@ public abstract class World { * @param position The position vector * @return true if an animal can walk on tile, false otherwise */ - public final boolean isFree(Vector2D position) { return this.isFree(position.getX(), position.getY()); } @@ -129,7 +119,6 @@ public abstract class World { * @param position A position in the maze * @return An array of all available choices at a position */ - public final Direction[] getChoices(Vector2D position) { List choices = new ArrayList<>(); for (Direction dir : Direction.POSSIBLE_DIRECTIONS) @@ -144,7 +133,6 @@ public abstract class World { * * @return The horizontal length of the labyrinth */ - public final int getWidth() { return this.labyrinth[0].length; } @@ -154,7 +142,6 @@ public abstract class World { * * @return The vertical length of the labyrinth */ - public final int getHeight() { return this.labyrinth.length; } @@ -165,7 +152,6 @@ public abstract class World { * * @return Start position of the labyrinth, null if none. */ - public final Vector2D getStart() { return this.start; } @@ -175,8 +161,8 @@ public abstract class World { * * @return Exit position of the labyrinth, null if none. */ - public final Vector2D getExit() { return this.exit; } + } diff --git a/src/ch/epfl/maze/physical/pacman/Pinky.java b/src/ch/epfl/maze/physical/pacman/Pinky.java index ebabc15..9c3d2c8 100644 --- a/src/ch/epfl/maze/physical/pacman/Pinky.java +++ b/src/ch/epfl/maze/physical/pacman/Pinky.java @@ -6,8 +6,6 @@ import ch.epfl.maze.physical.GhostPredator; import ch.epfl.maze.util.Direction; import ch.epfl.maze.util.Vector2D; -import java.util.Vector; - /** * Pink ghost from the Pac-Man game, targets 4 squares in front of its target. * @@ -16,6 +14,7 @@ import java.util.Vector; public class Pinky extends GhostPredator { private static final int TARGET_OFFSET = 4; + /** * Constructs a Pinky with a starting position. * diff --git a/src/ch/epfl/maze/physical/zoo/Hamster.java b/src/ch/epfl/maze/physical/zoo/Hamster.java index 3c903f5..7fa0b0d 100644 --- a/src/ch/epfl/maze/physical/zoo/Hamster.java +++ b/src/ch/epfl/maze/physical/zoo/Hamster.java @@ -16,7 +16,6 @@ import java.util.stream.Collectors; * * @author Pacien TRAN-GIRARD */ - public class Hamster extends ProbabilisticAnimal { private final List deadPaths; @@ -26,7 +25,6 @@ public class Hamster extends ProbabilisticAnimal { * * @param position Starting position of the hamster in the labyrinth */ - public Hamster(Vector2D position) { super(position); this.deadPaths = new ArrayList<>(); @@ -38,7 +36,6 @@ public class Hamster extends ProbabilisticAnimal { * @param choices An array of choices * @return An array of smart choices */ - private Direction[] excludeDeadPaths(Direction[] choices) { return (new ArrayList<>(Arrays.asList(choices))) .stream() @@ -51,7 +48,6 @@ public class Hamster extends ProbabilisticAnimal { * Moves without retracing directly its steps and by avoiding the dead-ends * it learns during its journey. */ - @Override public Direction move(Direction[] choices) { Direction[] smartChoices = this.excludeDeadPaths(choices); @@ -63,4 +59,5 @@ public class Hamster extends ProbabilisticAnimal { public Animal copy() { return new Hamster(this.getPosition()); } + } diff --git a/src/ch/epfl/maze/physical/zoo/Monkey.java b/src/ch/epfl/maze/physical/zoo/Monkey.java index 7bcf090..196b028 100644 --- a/src/ch/epfl/maze/physical/zoo/Monkey.java +++ b/src/ch/epfl/maze/physical/zoo/Monkey.java @@ -13,7 +13,6 @@ import java.util.List; * * @author Pacien TRAN-GIRARD */ - public class Monkey extends Animal { private Direction currentDirection; @@ -23,7 +22,6 @@ public class Monkey extends Animal { * * @param position Starting position of the monkey in the labyrinth */ - public Monkey(Vector2D position) { super(position); this.currentDirection = Direction.NONE; @@ -35,7 +33,6 @@ public class Monkey extends Animal { * @param choices An array of possible directions * @return The currentDirection to take according to the "left paw rule" */ - private Direction followLeft(Direction[] choices) { List choiceList = new ArrayList<>(Arrays.asList(choices)); Direction dir = this.currentDirection.rotateLeft(); @@ -60,7 +57,6 @@ public class Monkey extends Animal { /** * Moves according to the relative left wall that the monkey has to follow. */ - @Override public Direction move(Direction[] choices) { this.currentDirection = this.findDirection(choices); @@ -71,4 +67,5 @@ public class Monkey extends Animal { public Animal copy() { return new Monkey(this.getPosition()); } + } diff --git a/src/ch/epfl/maze/physical/zoo/Panda.java b/src/ch/epfl/maze/physical/zoo/Panda.java index dc1198e..aa35efe 100644 --- a/src/ch/epfl/maze/physical/zoo/Panda.java +++ b/src/ch/epfl/maze/physical/zoo/Panda.java @@ -104,7 +104,7 @@ public class Panda extends ProbabilisticAnimal { * avoiding intersections over-marking. * * @param choices An array of possible Directions - * @param choice The selected Direction + * @param choice The selected Direction * @return T(the current position should be marked) */ private boolean shouldMarkCurrentPosition(Direction[] choices, Direction choice) { diff --git a/src/ch/epfl/maze/physical/zoo/SpaceInvader.java b/src/ch/epfl/maze/physical/zoo/SpaceInvader.java index f5963b1..d03d280 100644 --- a/src/ch/epfl/maze/physical/zoo/SpaceInvader.java +++ b/src/ch/epfl/maze/physical/zoo/SpaceInvader.java @@ -18,7 +18,6 @@ import ch.epfl.maze.util.Vector2D; * * @see ch.epfl.maze.tests.Competition Competition */ - public class SpaceInvader extends Animal { /** @@ -26,7 +25,6 @@ public class SpaceInvader extends Animal { * * @param position Starting position of the mouse in the labyrinth */ - public SpaceInvader(Vector2D position) { super(position); // TODO (bonus) @@ -35,7 +33,6 @@ public class SpaceInvader extends Animal { /** * Moves according to (... please complete with as many details as you can). */ - @Override public Direction move(Direction[] choices) { // TODO (bonus) @@ -47,4 +44,5 @@ public class SpaceInvader extends Animal { // TODO (bonus) return null; } + } -- cgit v1.2.3