From 10627af7a85b50bce965245a472d9b69e928d0ba Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 21 Nov 2015 22:53:24 +0100 Subject: Generalize turn back avoidance to all ProbabilisticAnimals --- src/ch/epfl/maze/physical/zoo/Mouse.java | 39 +------------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) (limited to 'src/ch/epfl/maze/physical/zoo') diff --git a/src/ch/epfl/maze/physical/zoo/Mouse.java b/src/ch/epfl/maze/physical/zoo/Mouse.java index b5483c1..08d7f3d 100644 --- a/src/ch/epfl/maze/physical/zoo/Mouse.java +++ b/src/ch/epfl/maze/physical/zoo/Mouse.java @@ -2,64 +2,27 @@ package ch.epfl.maze.physical.zoo; import ch.epfl.maze.physical.Animal; import ch.epfl.maze.physical.ProbabilisticAnimal; -import ch.epfl.maze.util.Direction; import ch.epfl.maze.util.Vector2D; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.stream.Collectors; - /** * Mouse A.I. that remembers only the previous choice it has made. * * @author Pacien TRAN-GIRARD */ - public class Mouse extends ProbabilisticAnimal { - private Direction previousChoice; - /** * Constructs a mouse with a starting position. * * @param position Starting position of the mouse in the labyrinth */ - public Mouse(Vector2D position) { super(position); - this.previousChoice = Direction.NONE; - } - - /** - * Excludes the origin direction for choices. - * - * @param choices An array of choices - * @return An array of smart choices - */ - - private Direction[] excludeOrigin(Direction[] choices) { - return (new ArrayList<>(Arrays.asList(choices))) - .stream() - .filter(dir -> !dir.isOpposite(this.previousChoice)) - .collect(Collectors.toList()) - .toArray(new Direction[0]); - } - - /** - * Moves according to an improved version of a random walk : the - * mouse does not directly retrace its steps. - */ - - @Override - public Direction move(Direction[] choices) { - Direction[] smartChoices = choices.length > 1 ? this.excludeOrigin(choices) : choices; - Direction dir = super.move(smartChoices); - this.previousChoice = dir; - return dir; } @Override public Animal copy() { return new Mouse(this.getPosition()); } + } -- cgit v1.2.3