X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=t%2Fastar.c;h=5a447da42155a252c2cb8f61584571860f3766a5;hb=HEAD;hp=bab342d0301826f4d1ee5a2bacb79ddce60b68a6;hpb=67fdcec57ab31e7a972ed624ab5f6df866313206;p=hexagon diff --git a/t/astar.c b/t/astar.c index bab342d..5a447da 100644 --- a/t/astar.c +++ b/t/astar.c @@ -1,16 +1,17 @@ #include -#include "hexmap.h" +#include "hexagon.h" -#include "tap.h" +#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_init(p); +// HL_astar_clear(p); p->start = from; p->goal = to; @@ -19,15 +20,32 @@ void pcheck(struct HL_astar *p, int x1, int y1, int x2, int y2, int expect) { ok(p->error == 0, "found path from (%02d, %02d) to (%02d, %02d) with no error", x1, y1, x2, y2); ok(dist == expect, - "found path from (%02d, %02d) to (%02d, %02d) path length = %d (expect %d)\n", + "found path from (%02d, %02d) to (%02d, %02d) path length = %d (expect %d)", x1, y1, x2, y2, dist, expect); } +/* make hex 55 missing */ +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) { struct HL_astar *p; - int length; - plan_tests(15); + plan(16); p = HL_astar_init(0); ok(p != NULL, "allocated astar struct"); @@ -35,19 +53,22 @@ int main(void) { ok(p->open == NULL, "initial open list empty"); ok(p->closed == NULL, "initial closed list empty"); - p->start = HL_cantor_xy(1, 1); - p->goal = HL_cantor_xy(1, 2); - - length = HL_findpath(p, 0); - ok(p->error == 0, "path finding returns no error"); - pcheck(p, 1,1, 1,3, 2); + HL_astar_init(p); pcheck(p, 1,1, 2,1, 1); + HL_astar_init(p); pcheck(p, 1,1, 2,2, 2); + HL_astar_init(p); pcheck(p, 1,1, 3,1, 2); + HL_astar_init(p); pcheck(p, 1,1, 4,7, 8); + //HL_astar_clear(p); + HL_astar_init(p); + p->neighbor = neighbor55; + pcheck(p,5,4,5,6,3); + HL_astar_free(p); - return exit_status(); + return 0; }