ID3 #3
@ -43,8 +43,6 @@ class GarbageTruck:
|
||||
self.rect.y -= FIELDWIDTH
|
||||
|
||||
def next_destination(self):
|
||||
if self.fuel <= 0 or not self.request_list:
|
||||
return self.dump_x, self.dump_y
|
||||
|
||||
for i in range(len(self.request_list)):
|
||||
request = self.request_list[i]
|
||||
@ -54,12 +52,12 @@ class GarbageTruck:
|
||||
continue
|
||||
|
||||
#nie straczy paliwa na dojechanie i powrót na wysypisko
|
||||
if heuristicfn(request.x_pos, request.y_pos, self.dump_x, self.dump_y) / 50 * 200 > self.fuel:
|
||||
if heuristicfn(request.x_pos, request.y_pos, self.dump_x, self.dump_y) // 50 * 200 > self.fuel:
|
||||
continue
|
||||
|
||||
|
||||
|
||||
distance = heuristicfn(self.rect.x, self.rect.y, request.x_pos, request.y_pos) / 50
|
||||
distance = heuristicfn(self.rect.x, self.rect.y, request.x_pos, request.y_pos) // 50
|
||||
|
||||
r = [
|
||||
self.fuel,
|
||||
@ -82,7 +80,7 @@ class GarbageTruck:
|
||||
|
||||
def collect(self):
|
||||
if self.rect.x == self.dump_x and self.rect.y == self.dump_y:
|
||||
self.fuel = MAX_WEIGHT
|
||||
self.fuel = MAX_FUEL
|
||||
self.free_space = MAX_SPACE
|
||||
self.weight_capacity = MAX_WEIGHT
|
||||
print(f'agent at ({self.rect.x}, {self.rect.y}); fuel: {self.fuel}; free space: {self.free_space}; weight capacity: {self.weight_capacity}')
|
||||
|
3
main.py
3
main.py
@ -49,7 +49,7 @@ def main():
|
||||
if x == agent.rect.x and y == agent.rect.y:
|
||||
print('out of jobs')
|
||||
break
|
||||
steps = astar(State(None, None, agent.rect.x, agent.rect.y, agent.orientation, priority_array[0][0], heuristicfn(agent.rect.x, agent.rect.y, x, y)), x, y, priority_array)
|
||||
steps = astar(State(None, None, agent.rect.x, agent.rect.y, agent.orientation, priority_array[agent.rect.x//50][agent.rect.y//50], heuristicfn(agent.rect.x, agent.rect.y, x, y)), x, y, priority_array)
|
||||
for interm in steps:
|
||||
if interm.action == 'LEFT':
|
||||
agent.turn_left()
|
||||
@ -68,6 +68,7 @@ def main():
|
||||
time.sleep(0.3)
|
||||
agent.collect()
|
||||
fields[agent.rect.x//50][agent.rect.y//50] = GRASS
|
||||
priority_array[agent.rect.x//50][agent.rect.y//50] = 1
|
||||
time.sleep(0.5)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user