Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <assert.h>
  4.  
  5. #include "fruit_bot.h"
  6.  
  7. int nearest_electricity(struct bot *b);
  8.  
  9. int main(int argc, char *argv[]) {
  10. struct bot *me = fruit_bot_input(stdin);
  11.  
  12. int distance = nearest_electricity(me);
  13. printf("Distance to nearest available electricity is %d\n", distance);
  14.  
  15. return 0;
  16. }
  17.  
  18.  
  19. // return distance to nearest electricity
  20. // if nearest electricity is west return negative int
  21. // if nearest electricity is current location return 0
  22.  
  23. int nearest_electricity(struct bot *b) {
  24. struct location *curr = b->location;
  25. struct bot *curr1 = b;
  26. struct location *head = b->location;
  27. int return_value = 0;
  28. int shell = 0;
  29. while (strcmp(curr->fruit, "Electricity") != 0) {
  30. if(strcmp(curr->fruit, "Electricity") == 0){
  31. if(curr->quantity > 0 && curr1->battery_level < curr1->battery_capacity) {
  32. int battery_amount = curr1->battery_capacity - curr1->battery_level;
  33. return_value = 0;
  34. }
  35. } else {
  36. curr = curr->east;
  37. return_value++;
  38. }
  39. }
  40.  
  41. if (curr1->maximum_move < return_value) {
  42. return_value = curr1->maximum_move*(-1) / 10;
  43. }
  44.  
  45. return return_value;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement