]> pd.if.org Git - hexagon/blobdiff - t/astar.c
rework library to use structs
[hexagon] / t / astar.c
index 729a7a864f8863391d453f8736a76f8bdd3ae482..5a447da42155a252c2cb8f61584571860f3766a5 100644 (file)
--- a/t/astar.c
+++ b/t/astar.c
@@ -5,10 +5,11 @@
 #include "ctap.h"
 
 void pcheck(struct HL_astar *p, int x1, int y1, int x2, int y2, int expect) {
-       int from, to, dist;
+       struct HL_hex from, to;
+       int dist;
 
-       from = HL_cantor_xy(x1,y1);
-       to = HL_cantor_xy(x2,y2);
+       from = HL_hex_xy(x1,y1);
+       to = HL_hex_xy(x2,y2);
 
 //     HL_astar_clear(p);
 
@@ -24,14 +25,21 @@ void pcheck(struct HL_astar *p, int x1, int y1, int x2, int y2, int expect) {
 }
 
 /* make hex 55 missing */
-int neighbor55(int hex, int dir) {
-       int neighbor;
-
-       do {
-               neighbor = HL_adjacent_hex(hex, dir++);
-       } while (neighbor == HL_cantor_xy(5,5));
-
-       return neighbor;
+int neighbor55(struct HL_hex hex, int dir, struct HL_hex *n) {
+       int valid;
+       struct HL_hex nh;
+
+       valid = HL_adjhexp(hex, dir, &nh);
+       if (valid && nh.x == 5 && nh.y == 5) {
+               valid = 0;
+       }
+               if (valid && n) {
+               *n = nh;
+       }
+       
+       return valid;
+
+       return 1;
 }
 
 int main(void) {