Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def distance(x1, y1, x2, y2):
- return abs(x1 - x2) + abs(y1 - y2)
- def select_task(car, tasks):
- cx, cy = car.x, car.y
- time = car.time_free
- best_cost = 0
- best_i = -1
- for i, task in enumerate(tasks):
- dist = distance(cx, cy, task['x1'], task['y1'])
- arrival = time + d
- b = BONUS if arrival == taks['s'] else 0
- waiting = min(task['s'] - arrival, 0)
- cost = task['rew'] - dist + bonus - waiting
- if cost > best_cost:
- best_task = task
- best_cost = cost
- best_i = i
- best_dist = dist
- best_arrival_time = time + dist + waiting + task['rew']
- car.x, car.y = best_task['x2'], best_task['y2']
- car.time_free = best_arrival_time
- return best_id
Advertisement
Add Comment
Please, Sign In to add comment