-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.py
42 lines (30 loc) · 924 Bytes
/
action.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from collections import deque
from dataclasses import dataclass
from typing import Any, Deque
from utils import ActionType
@dataclass
class Action:
action_type: ActionType
argument: Any = None
class ActionQueue:
"""A queue of actions to be performed by the elevator"""
def __init__(self):
self.actions: Deque[Action] = deque()
def get(self):
try:
return self.actions.popleft()
except IndexError:
return Action(ActionType.RUN_CYCLE)
def add(self, action: Action):
self.actions.append(action)
def tick(self, count=1):
for _ in range(count):
self.actions.append(Action(ActionType.ADD_TICK))
def open_door(self):
self.tick(3)
def close_door(self):
self.tick(3)
def copy(self):
new_queue = ActionQueue()
new_queue.actions = self.actions.copy()
return new_queue