]> pd.if.org Git - hexagon/blob - t/astarlg.c
7d2ef6bc196d6f56b31b9a7d0a7d4be37a098d8c
[hexagon] / t / astarlg.c
1 #include <stdio.h>
2
3 #include "hexagon.h"
4
5 #include "tap.h"
6
7 void pcheck(struct HL_astar *p, int x1, int y1, int x2, int y2, int expect) {
8         int from, to, dist;
9
10         from = HL_cantor_xy(x1,y1);
11         to = HL_cantor_xy(x2,y2);
12
13         HL_astar_clear(p);
14
15         p->start = from;
16         p->goal = to;
17
18         dist = HL_findpath(p,0);
19         ok(p->error == 0, "found path from (%02d, %02d) to (%02d, %02d) with no error",
20                 x1, y1, x2, y2);
21         ok(dist == expect,
22                         "found path from (%02d, %02d) to (%02d, %02d) path length = %d (expect %d)",
23                 x1, y1, x2, y2, dist, expect);
24 }
25
26 /* make hex 55 missing */
27 int neighbor55(int hex, int dir) {
28         int neighbor;
29
30         do {
31                 neighbor = HL_adjacent_hex(hex, dir++);
32         } while (neighbor == HL_cantor_xy(5,5));
33
34         return neighbor;
35 }
36
37 int main(void) {
38         struct HL_astar *p;
39 #if 0
40         int length;
41 #endif
42
43         plan_tests(2);
44
45         p = HL_astar_init(0);
46
47         pcheck(p, 1,1, 10000,10000, 14999);
48
49         HL_astar_free(p);
50
51         return exit_status();
52 }