Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

works, continue moving astar to loc struct

  • Loading branch information...
commit b7ad7d15eed9a1124763d6472fde594688de77ef 1 parent 0a3c792
@datachomper authored
Showing with 14 additions and 12 deletions.
  1. +9 −8 c/MyBot.c
  2. +4 −3 c/api.c
  3. +1 −1  c/api.h
View
17 c/MyBot.c
@@ -86,14 +86,15 @@ void do_turn(struct Game *game)
}
}
if (closest != NULL) {
- struct square *s;
- fprintf(stderr, "assign a(%d,%d) to f(%d,%d)\n",
- a->loc.x, a->loc.y,
- closest->loc.x, closest->loc.y);
- s = astar(game->watermap, &a->loc, &closest->loc);
- order_loc(&a->loc, &s->loc);
- list_move(&a->node, &game->freefood);
- list_move(&closest->node, &game->freeants);
+ struct loc next;
+ if (!astar(game->watermap, &a->loc, &closest->loc, &next)) {
+ fprintf(stderr, "move a(%d,%d) to f(%d,%d)\n",
+ a->loc.x, a->loc.y,
+ next.x, next.y);
+ order_loc(&a->loc, &next);
+ list_move(&a->node, &game->freefood);
+ list_move(&closest->node, &game->freeants);
+ }
}
}
}
View
7 c/api.c
@@ -104,7 +104,7 @@ struct square * get_best_f(struct list_head *openlist)
return lowest;
}
-struct square * astar(int *map, struct loc *a, struct loc *b)
+int astar(int *map, struct loc *a, struct loc *b, struct loc *next)
{
struct square *s, *n;
struct square *start, *target;
@@ -133,7 +133,8 @@ struct square * astar(int *map, struct loc *a, struct loc *b)
do {
s = s->parent;
} while (s->parent->parent != NULL);
- return s;
+ memcpy(next, &s->loc, sizeof(*next));
+ return 0;
}
s->list = CLOSED;
list_del_init(&s->astar);
@@ -158,7 +159,7 @@ struct square * astar(int *map, struct loc *a, struct loc *b)
}
}
printf("oops, open list is empty!\n");
- return NULL;
+ return -1;
}
int neighbor(int row, int col, enum DIRECTION dir)
View
2  c/api.h
@@ -78,4 +78,4 @@ int neighbor(int row, int col, enum DIRECTION dir);
void order(int row, int col, enum DIRECTION dir);
int time_remaining(struct Game *game);
char min(char a, char b);
-struct square * astar(int *map, struct loc *a, struct loc *b);
+int astar(int *map, struct loc *a, struct loc *b, struct loc *next);
Please sign in to comment.
Something went wrong with that request. Please try again.