summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ch/epfl/maze/physical/zoo/Monkey.java35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/ch/epfl/maze/physical/zoo/Monkey.java b/src/ch/epfl/maze/physical/zoo/Monkey.java
index f0f9b2e..8aea75d 100644
--- a/src/ch/epfl/maze/physical/zoo/Monkey.java
+++ b/src/ch/epfl/maze/physical/zoo/Monkey.java
@@ -4,12 +4,20 @@ import ch.epfl.maze.physical.Animal;
4import ch.epfl.maze.util.Direction; 4import ch.epfl.maze.util.Direction;
5import ch.epfl.maze.util.Vector2D; 5import ch.epfl.maze.util.Vector2D;
6 6
7import java.util.ArrayList;
8import java.util.Arrays;
9import java.util.List;
10
7/** 11/**
8 * Monkey A.I. that puts its hand on the left wall and follows it. 12 * Monkey A.I. that puts its hand on the left wall and follows it.
13 *
14 * @author Pacien TRAN-GIRARD
9 */ 15 */
10 16
11public class Monkey extends Animal { 17public class Monkey extends Animal {
12 18
19 private Direction currentDirection;
20
13 /** 21 /**
14 * Constructs a monkey with a starting position. 22 * Constructs a monkey with a starting position.
15 * 23 *
@@ -18,7 +26,25 @@ public class Monkey extends Animal {
18 26
19 public Monkey(Vector2D position) { 27 public Monkey(Vector2D position) {
20 super(position); 28 super(position);
21 // TODO 29 this.currentDirection = Direction.NONE;
30 }
31
32 /**
33 * Finds a currentDirection following the "left paw rule".
34 *
35 * @param choices An array of possible directions
36 * @return The currentDirection to take according to the "left paw rule"
37 */
38
39 private Direction followLeft(Direction[] choices) {
40 if (choices.length == 0) return Direction.NONE;
41 if (choices.length == 1) return choices[0];
42
43 List<Direction> choiceList = new ArrayList<>(Arrays.asList(choices));
44 Direction dir = this.currentDirection.rotateLeft();
45 while (!choiceList.contains(dir)) dir = dir.rotateRight();
46
47 return dir;
22 } 48 }
23 49
24 /** 50 /**
@@ -27,13 +53,12 @@ public class Monkey extends Animal {
27 53
28 @Override 54 @Override
29 public Direction move(Direction[] choices) { 55 public Direction move(Direction[] choices) {
30 // TODO 56 this.currentDirection = this.followLeft(choices);
31 return Direction.NONE; 57 return this.currentDirection;
32 } 58 }
33 59
34 @Override 60 @Override
35 public Animal copy() { 61 public Animal copy() {
36 // TODO 62 return new Monkey(this.getPosition());
37 return null;
38 } 63 }
39} 64}