From 9bec90d20c20b01e94a8b5d8364bbe60f9687f05 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Tue, 24 Nov 2015 17:57:23 +0100 Subject: Refactor Bear A.I. --- .../physical/stragegies/picker/CyclePicker.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/ch/epfl/maze/physical/stragegies') diff --git a/src/ch/epfl/maze/physical/stragegies/picker/CyclePicker.java b/src/ch/epfl/maze/physical/stragegies/picker/CyclePicker.java index e1a969f..efa3794 100644 --- a/src/ch/epfl/maze/physical/stragegies/picker/CyclePicker.java +++ b/src/ch/epfl/maze/physical/stragegies/picker/CyclePicker.java @@ -38,4 +38,25 @@ public interface CyclePicker extends BlindPicker { return dir; } + /** + * Counts the number of rotations to rotates to the given Direction + * + * @param direction The Direction + * @return The number of rotations + */ + default int countRotations(Direction direction) { + if (direction == Direction.NONE) return 0; + if (this.getStartingDirection() == Direction.NONE) return 0; + if (this.getRotationDirection() == Direction.NONE) return 0; + + Direction dir = this.getStartingDirection(); + int counter = 0; + while (dir != direction) { + dir = dir.unRelativeDirection(this.getRotationDirection()); + counter += 1; + } + + return counter; + } + } -- cgit v1.2.3