-int HL_findpath(int start, int end, int psize, int *path,
- double (*metric)(int,int)) {
- int neighbors[6];
- int count;
- int cur = 0;
- struct astar state;
- int neighbor;
-
- if (start == end) return 0;
- if (!metric) metric = default_metric;
-
- astar_init(&state);
- addopen(&state, start);
-
- while (1) {
- cur = lowrank(&state);
- if (cur == end) {
+int HL_findpath(struct HL_astar *s, int loops) {
+ int dir, y;
+ struct HL_astar_hex *node, *x, *yopen;
+ int tent_better;
+ double cost;
+
+ s->error = 0;
+
+ if (s->start == s->goal) return 0;
+
+ node = add_open(s, s->start);
+ node->g = 0.0;
+ node->h = s->heuristic(s->start, s->goal);
+ node->f = node->h;
+
+#ifdef DEBUG_ASTAR
+ fprintf(stderr, "A* findpath: ");
+ fprintf(stderr, "(%d,%d)", HL_cantor_x(s->start), HL_cantor_y(s->start));
+ fprintf(stderr, " -> ");
+ fprintf(stderr, "(%d,%d)", HL_cantor_x(s->goal), HL_cantor_y(s->goal));
+ fprintf(stderr, "\n");
+#endif
+
+ while (s->open) {
+
+#ifdef DEBUG_ASTAR
+ fprintf(stderr, "open list: ");
+ for(x = s->open; x; x = x->next) {
+ fprintf(stderr, "(%d,%d)", HL_cantor_x(x->hex), HL_cantor_y(x->hex));
+ }
+ fprintf(stderr, "\n");
+ fprintf(stderr, "closed list: ");
+ for(x = s->closed; x; x = x->next) {
+ fprintf(stderr, "(%d,%d)", HL_cantor_x(x->hex), HL_cantor_y(x->hex));
+ }
+ fprintf(stderr, "\n");
+#endif
+
+ x = lowrank(s);
+#ifdef DEBUG_ASTAR
+ fprintf(stderr, "checking lowest f hex = (%d,%d) f = %f, g = %f, h = %f\n",
+ HL_cantor_x(x->hex), HL_cantor_y(x->hex),
+ x->f, x->g, x->h
+ );
+#endif
+ if (x->hex == s->goal) {