Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <assert.h>
- #include "fruit_bot.h"
- int nearest_electricity(struct bot *b);
- int main(int argc, char *argv[]) {
- struct bot *me = fruit_bot_input(stdin);
- int distance = nearest_electricity(me);
- printf("Distance to nearest available electricity is %d\n", distance);
- return 0;
- }
- // return distance to nearest electricity
- // if nearest electricity is west return negative int
- // if nearest electricity is current location return 0
- int nearest_electricity(struct bot *b) {
- struct location *curr = b->location;
- struct bot *curr1 = b;
- struct location *head = b->location;
- int return_value = 0;
- int shell = 0;
- while (strcmp(curr->fruit, "Electricity") != 0) {
- if(strcmp(curr->fruit, "Electricity") == 0){
- if(curr->quantity > 0 && curr1->battery_level < curr1->battery_capacity) {
- int battery_amount = curr1->battery_capacity - curr1->battery_level;
- return_value = 0;
- }
- } else {
- curr = curr->east;
- return_value++;
- }
- }
- if (curr1->maximum_move < return_value) {
- return_value = curr1->maximum_move*(-1) / 10;
- }
- return return_value;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement