From 0b1b1485581e7c4d7fbaa5414e9506e9c0c02463 Mon Sep 17 00:00:00 2001 From: mar77i Date: Tue, 20 Aug 2024 10:21:51 +0200 Subject: [PATCH] panel_prio lets callers go somewhere befeore next call_queue --- elevator.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/elevator.py b/elevator.py index e0c3d59..44435aa 100755 --- a/elevator.py +++ b/elevator.py @@ -154,6 +154,7 @@ class Door: elif self.state >= self.CLOSED: self.state = self.CLOSED self.direction = 0 + self.elevator.panel_prio = False return True def draw(self, surf): @@ -226,6 +227,14 @@ class Elevator: self.destination = None self.queued_dest = None self.call_queue = [] + self.panel_prio = False + + def pop_destination(self, destination): + if destination == self.queued_dest: + self.queued_dest = None + while destination in self.call_queue: + self.call_queue.remove(destination) + self.destination = destination def pick_destination(self): """ @@ -236,15 +245,11 @@ class Elevator: if not all(door.state == door.CLOSED for door in self.doors): return False if self.queued_dest is not None: - self.destination = self.queued_dest - while self.destination in self.call_queue: - self.call_queue.remove(self.destination) - self.queued_dest = None + self.pop_destination(self.queued_dest) return True - elif len(self.call_queue) > 0: - self.destination = self.call_queue.pop(0) - if self.destination == self.queued_dest: - self.destination = None + elif not self.panel_prio and len(self.call_queue) > 0: + self.pop_destination(self.call_queue.pop(0)) + self.panel_prio = True return True return False -- 2.47.0