2023-05-26 19:08:22 +02:00
|
|
|
from heuristicfn import heuristicfn
|
2023-04-21 14:31:17 +02:00
|
|
|
|
2023-06-01 23:44:09 +02:00
|
|
|
|
2023-05-26 19:08:22 +02:00
|
|
|
FIELDWIDTH = 50
|
|
|
|
TURN_FUEL_COST = 10
|
|
|
|
MOVE_FUEL_COST = 200
|
|
|
|
MAX_FUEL = 20000
|
|
|
|
MAX_SPACE = 5
|
2023-06-01 23:44:09 +02:00
|
|
|
MAX_WEIGHT = 400
|
|
|
|
MAX_WEIGHT_GLASS = 100
|
|
|
|
MAX_WEIGHT_MIXED = 100
|
|
|
|
MAX_WEIGHT_PAPER = 100
|
|
|
|
MAX_WEIGHT_PLASTIC = 100
|
2023-03-28 18:00:13 +02:00
|
|
|
|
|
|
|
|
2023-03-31 13:49:27 +02:00
|
|
|
class GarbageTruck:
|
2023-05-26 19:08:22 +02:00
|
|
|
|
|
|
|
garbage_types = {'bio': 0, 'electronics': 1, 'mixed': 2, 'recyclable': 3}
|
|
|
|
|
|
|
|
def __init__(self, dump_x, dump_y, rect, orientation, request_list: list, clf):
|
|
|
|
self.dump_x = dump_x
|
|
|
|
self.dump_y = dump_y
|
|
|
|
self.fuel = MAX_FUEL
|
|
|
|
self.free_space = MAX_SPACE
|
|
|
|
self.weight_capacity = MAX_WEIGHT
|
2023-06-01 23:44:09 +02:00
|
|
|
self.weight_capacity_glass = MAX_WEIGHT_GLASS
|
|
|
|
self.weight_capacity_mixed = MAX_WEIGHT_MIXED
|
|
|
|
self.weight_capacity_paper = MAX_WEIGHT_PAPER
|
|
|
|
self.weight_capacity_plastic = MAX_WEIGHT_PLASTIC
|
2023-04-21 14:31:17 +02:00
|
|
|
self.rect = rect
|
2023-04-19 21:16:40 +02:00
|
|
|
self.orientation = orientation
|
2023-05-26 19:08:22 +02:00
|
|
|
self.request_list = request_list #lista domów do odwiedzenia
|
|
|
|
self.clf = clf
|
2023-04-21 14:31:17 +02:00
|
|
|
|
|
|
|
def turn_left(self):
|
|
|
|
self.orientation = (self.orientation - 1) % 4
|
2023-05-26 19:08:22 +02:00
|
|
|
self.fuel -= TURN_FUEL_COST
|
2023-04-21 14:31:17 +02:00
|
|
|
|
|
|
|
def turn_right(self):
|
|
|
|
self.orientation = (self.orientation + 1) % 4
|
2023-05-26 19:08:22 +02:00
|
|
|
self.fuel -= TURN_FUEL_COST
|
2023-04-21 14:31:17 +02:00
|
|
|
|
|
|
|
def forward(self):
|
2023-05-26 19:08:22 +02:00
|
|
|
self.fuel -= MOVE_FUEL_COST
|
2023-04-21 14:31:17 +02:00
|
|
|
if self.orientation == 0:
|
|
|
|
self.rect.x += FIELDWIDTH
|
|
|
|
elif self.orientation == 1:
|
|
|
|
self.rect.y += FIELDWIDTH
|
|
|
|
elif self.orientation == 2:
|
|
|
|
self.rect.x -= FIELDWIDTH
|
|
|
|
else:
|
2023-05-26 19:08:22 +02:00
|
|
|
self.rect.y -= FIELDWIDTH
|
|
|
|
|
|
|
|
def next_destination(self):
|
|
|
|
|
|
|
|
for i in range(len(self.request_list)):
|
2023-06-16 12:20:46 +02:00
|
|
|
if(self.request_list==[]):
|
|
|
|
break
|
2023-05-26 19:08:22 +02:00
|
|
|
request = self.request_list[i]
|
|
|
|
|
|
|
|
#nie ma miejsca w zbiorniku lub za ciężkie śmieci
|
|
|
|
if request.volume > self.free_space or request.weight > self.weight_capacity:
|
|
|
|
continue
|
|
|
|
|
|
|
|
#nie straczy paliwa na dojechanie i powrót na wysypisko
|
2023-05-26 20:14:13 +02:00
|
|
|
if heuristicfn(request.x_pos, request.y_pos, self.dump_x, self.dump_y) // 50 * 200 > self.fuel:
|
2023-05-26 19:08:22 +02:00
|
|
|
continue
|
|
|
|
|
2023-06-16 12:20:46 +02:00
|
|
|
self.request_list.pop(i)
|
|
|
|
self.free_space -= request.volume
|
|
|
|
self.weight_capacity -= request.weight
|
|
|
|
return request.x_pos, request.y_pos
|
2023-05-26 19:08:22 +02:00
|
|
|
return self.dump_x, self.dump_y
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-06-01 23:44:09 +02:00
|
|
|
def collect(self, garbage_type):
|
2023-05-26 19:08:22 +02:00
|
|
|
if self.rect.x == self.dump_x and self.rect.y == self.dump_y:
|
2023-05-26 20:14:13 +02:00
|
|
|
self.fuel = MAX_FUEL
|
2023-05-26 19:08:22 +02:00
|
|
|
self.free_space = MAX_SPACE
|
|
|
|
self.weight_capacity = MAX_WEIGHT
|
2023-06-01 23:44:09 +02:00
|
|
|
self.weight_capacity_plastic = MAX_WEIGHT_PLASTIC
|
|
|
|
self.weight_capacity_mixed = MAX_WEIGHT_MIXED
|
|
|
|
self.weight_capacity_glass = MAX_WEIGHT_GLASS
|
|
|
|
self.weight_capacity_paper = MAX_WEIGHT_PAPER
|
2023-06-16 12:20:46 +02:00
|
|
|
if self.request_list==[]:
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
request = self.request_list[0]
|
2023-06-01 23:44:09 +02:00
|
|
|
if garbage_type == "glass":
|
|
|
|
if request.weight > self.weight_capacity_glass:
|
|
|
|
return 1
|
|
|
|
self.weight_capacity_glass -= request.weight
|
|
|
|
elif garbage_type == "mixed":
|
|
|
|
if request.weight > self.weight_capacity_mixed:
|
|
|
|
return 1
|
|
|
|
self.weight_capacity_mixed -= request.weight
|
|
|
|
elif garbage_type == "paper":
|
|
|
|
if request.weight > self.weight_capacity_paper:
|
|
|
|
return 1
|
|
|
|
self.weight_capacity_paper -= request.weight
|
|
|
|
elif garbage_type == "plastic":
|
|
|
|
if request.weight > self.weight_capacity_plastic:
|
|
|
|
return 1
|
|
|
|
self.weight_capacity_plastic -= request.weight
|
|
|
|
|
|
|
|
print(f'agent at ({self.rect.x}, {self.rect.y}); fuel: {self.fuel}; free space: {self.free_space}; weight capacity: {self.weight_capacity}, glass_capacity: {self.weight_capacity_glass}, mixed_capacity: {self.weight_capacity_mixed}, paper_capacity: {self.weight_capacity_paper}, plastic_capacity: {self.weight_capacity_plastic}')
|
|
|
|
return 0
|
2023-05-26 19:08:22 +02:00
|
|
|
pass
|