87 lines
2.7 KiB
Python
87 lines
2.7 KiB
Python
import copy
|
|
from src.obj.Object import Object
|
|
|
|
|
|
class Waiter(Object):
|
|
def __init__(self, position, orientation, square_size, screen_size, basket=[], memory=[], battery=300):
|
|
super().__init__("waiter", position, orientation, square_size, screen_size)
|
|
self.battery = battery
|
|
self.basket_size = 4
|
|
self.memory_size = 4
|
|
self.basket = basket
|
|
self.memory = memory
|
|
self.prev_position = copy.deepcopy(self.position)
|
|
self.prev_orientation = copy.copy(self.orientation)
|
|
|
|
def changeState(self, state):
|
|
self.position = copy.deepcopy(state.position)
|
|
self.orientation = copy.copy(state.orientation)
|
|
self.basket = copy.copy(state.basket)
|
|
self.battery -= state.cost
|
|
return state
|
|
|
|
def dish_in_basket(self, table) -> bool:
|
|
return table in self.basket
|
|
|
|
def basket_is_full(self) -> bool:
|
|
return self.basket_size == 0
|
|
|
|
def basket_is_empty(self) -> bool:
|
|
return self.basket_size == 4
|
|
|
|
def combine_orders(self, current_time):
|
|
while not self.basket_is_full() and not self.memory_is_empty():
|
|
dish = self.memory.pop()
|
|
dish.set_done(current_time)
|
|
self.basket.append(dish)
|
|
self.basket_size -= 1
|
|
self.memory_size += 1
|
|
|
|
def deliver_dish(self, table, current_time):
|
|
if table in self.basket:
|
|
table.reset(current_time)
|
|
self.basket.remove(table)
|
|
self.basket_size += 1
|
|
|
|
def order_in_memory(self, table) -> bool:
|
|
return table in self.memory
|
|
|
|
def memory_is_empty(self) -> bool:
|
|
return not self.memory
|
|
|
|
def memory_is_full(self) -> bool:
|
|
return self.memory_size == 0
|
|
|
|
def collect_order(self, table, current_time):
|
|
if self.memory_is_full():
|
|
return
|
|
if table.agent_role == "order":
|
|
table.set_wait(current_time)
|
|
self.memory.append(table)
|
|
self.memory_size -= 1
|
|
|
|
def battery_status(self) -> int:
|
|
return 1 if self.battery >= 100 else 0
|
|
|
|
def recharge(self):
|
|
self.battery = 300
|
|
|
|
def left(self):
|
|
self.orientation = (self.orientation + 1) % 4
|
|
|
|
def right(self):
|
|
self.orientation = (self.orientation - 1) % 4
|
|
|
|
def front(self):
|
|
if self.orientation % 2: # x (1 or 3)
|
|
self.position[0] += self.orientation - 2 # x (-1 or +1)
|
|
else: # y (0 or 2)
|
|
self.position[1] += self.orientation - 1 # y (-1 or +1)
|
|
|
|
def chechNeighbor(self, n, r=1):
|
|
|
|
cond_x = abs(self.position[0] - n.position[0]) <= r
|
|
cond_y = abs(self.position[1] - n.position[1]) <= r
|
|
|
|
return cond_x and cond_y
|