Emania

Untitled

Mar 1st, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1.  
  2.  
  3. def distance(x1, y1, x2, y2):
  4. return abs(x1 - x2) + abs(y1 - y2)
  5.  
  6. def select_task(car, tasks):
  7. cx, cy = car.x, car.y
  8. time = car.time_free
  9.  
  10. best_cost = 0
  11. best_i = -1
  12. for i, task in enumerate(tasks):
  13. dist = distance(cx, cy, task['x1'], task['y1'])
  14. arrival = time + d
  15. b = BONUS if arrival == taks['s'] else 0
  16. waiting = min(task['s'] - arrival, 0)
  17. cost = task['rew'] - dist + bonus - waiting
  18. if cost > best_cost:
  19. best_task = task
  20. best_cost = cost
  21. best_i = i
  22. best_dist = dist
  23. best_arrival_time = time + dist + waiting + task['rew']
  24. car.x, car.y = best_task['x2'], best_task['y2']
  25. car.time_free = best_arrival_time
  26. return best_id
Advertisement
Add Comment
Please, Sign In to add comment