From 733fd2a75e8df3863afeb78a63efd2ff9dfca699 Mon Sep 17 00:00:00 2001 From: MathieuPietri Date: Wed, 16 Oct 2019 18:10:29 +0200 Subject: [PATCH] =?UTF-8?q?l=C3=A9g=C3=A8res=20modif?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commandSystem/BasicInstructionQueue.java | 16 ++++++++++++---- src/simulation/Elevator.java | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/commandSystem/BasicInstructionQueue.java b/src/commandSystem/BasicInstructionQueue.java index 5f1b4f6..234345e 100644 --- a/src/commandSystem/BasicInstructionQueue.java +++ b/src/commandSystem/BasicInstructionQueue.java @@ -39,8 +39,9 @@ public class BasicInstructionQueue implements InstructionQueue { * direction the call is directed to. */ case CALLFROMFLOOR: + if (currentFloor == event.getIncomingCallFloor()) + break; switch (event.getRequestedDirection()) { - /* * Adds the instruction to the upQueue then sorts it. */ @@ -89,7 +90,7 @@ public class BasicInstructionQueue implements InstructionQueue { emergencyState = false; break; /* - * Refreshes the local values of current floor and current direction with the + * Refreshes the local values of current floor and current rrentFloodirection with the * ones given by the event. These values will */ case REACHEDFLOORSIGNAL: @@ -112,7 +113,7 @@ public class BasicInstructionQueue implements InstructionQueue { public int getNextInstruction() { int nextFloor = -1; - //System.out.println("" + upQueue + downQueue); + System.out.println("we go " + currentDirection + " current floor: " + currentFloor + " queues: " + upQueue + downQueue); switch (currentDirection) { // get the first element of upQueue that is ABOVE the elevator's current floor @@ -127,6 +128,9 @@ public class BasicInstructionQueue implements InstructionQueue { if (nextFloor < 0 && downQueue.size() > 0) { nextFloor = downQueue.get(0); } + if (nextFloor < 0 && upQueue.size() > 0) { + nextFloor = upQueue.get(0); + } break; // get the first element of downQueue that is UNDER the elevator's current floor @@ -141,6 +145,9 @@ public class BasicInstructionQueue implements InstructionQueue { if (nextFloor < 0 && upQueue.size() > 0) { nextFloor = upQueue.get(0); } + if (nextFloor < 0 && downQueue.size() > 0) { + nextFloor = downQueue.get(0); + } break; default: break; @@ -173,7 +180,8 @@ public class BasicInstructionQueue implements InstructionQueue { private void removeInstruction(int floor) { switch (currentDirection) { - /* + /* current floor: 0 queues: [0, 1, 2, 3][4, 3, 2, 1] +Next instruction: 0 * Elevator is headed upwards. */ case UP: diff --git a/src/simulation/Elevator.java b/src/simulation/Elevator.java index 649bcfe..ca1893d 100644 --- a/src/simulation/Elevator.java +++ b/src/simulation/Elevator.java @@ -8,7 +8,7 @@ import commandSystem.ElevatorListener; public class Elevator { - static final int PRECISION = 10; + static final int PRECISION = 100; private double floorHeight; private double step; private double height;