- addclosed(&state, cur);
- count = HL_hexes_at_range(cur->hex, 1, neighbors, 6);
- for (i=0;i<count;i++) {
- neighbor = neighbors[i];
- cost = g(&state, current) + metric(current, neighbor);
- if (inopen(&state, neighbor) && cost < g(&state, neighbor)) {
- removeopen(&state, neighbor);
- } else
- if (inclosed(&state, neighbor) && cost < g(&state, neighbor)) {
- /* should never happen with
- * admissible heuristic
- */
- removeclosed(&state, neighbor);
- } else
- if (!inopen(&state, neighbor) && !inclosed(&state, neighbor)) {
- addopen(&state, neighbor);
- setg(&state, neighbor, cost);
- setrank(&state, neighbor, cost + h(neighbor,end));
- setparent(&state, neighbor, current);
+ closehex(s, x);
+
+ int n;
+ for (dir = 0; n = s->neighbor(x->hex, dir, &y),dir<6; dir++) {
+ if (n == 0) continue; /* no hex in that direction */
+ if (in_closed(s, y)) {
+ continue;
+ }
+#ifdef DEBUG_ASTAR
+ fprintf(stderr, "checking dir %d, hex (%d, %d)\n", dir,
+ y.x, y.y);
+#endif
+
+ cost = x->g + s->metric(x->hex, y);
+
+ yopen = in_open(s, y);
+#ifdef DEBUG_ASTAR
+ fprintf(stderr, "checking inopen = %p\n", yopen);
+#endif
+ if (!yopen) {
+ yopen = add_open(s, y);
+ tent_better = 1;
+ } else if (cost < yopen->g) {
+ tent_better = 1;