#include "ctap.h"
int icmp(const void *ap, const void *bp) {
- int a;
- int b;
+ struct HL_hex const *a;
+ struct HL_hex const *b;
- a = *((int *)(ap));
- b = *((int *)(bp));
+ a = ap;
+ b = bp;
- return a-b;
+ if (a->x < b->x) return -1;
+ if (a->x > b->x) return 1;
+ if (a->y < b->y) return -1;
+ if (a->y > b->y) return 1;
+
+ return 0;
}
-void sort(int *r, int ct) {
+void sort(struct HL_hex *r, int ct) {
qsort(r, ct, sizeof *r, icmp);
}
int main(void) {
- int start;
+ struct HL_hex start;
int i, count;
- int range[32];
- int testrange[32];
+ struct HL_hex range[32];
+ struct HL_hex testrange[32];
plan(7+4);
/* printf("range = 1 from 3,3\n"); */
- start = HL_cantor_xy(3,3);
+ start = HL_hex_xy(3,3);
count = HL_hexes_at_range(start, 1, range, 0);
ok(count == 6, "6 hexes at range 1");
count = HL_hexes_at_range(start, 1, range, count);
sort(range, 6);
- testrange[0] = HL_cantor_xy(3,2);
- testrange[1] = HL_cantor_xy(3,4);
- testrange[2] = HL_cantor_xy(4,3);
- testrange[3] = HL_cantor_xy(4,2);
- testrange[4] = HL_cantor_xy(2,3);
- testrange[5] = HL_cantor_xy(2,2);
+ testrange[0] = HL_hex_xy(3,2);
+ testrange[1] = HL_hex_xy(3,4);
+ testrange[2] = HL_hex_xy(4,3);
+ testrange[3] = HL_hex_xy(4,2);
+ testrange[4] = HL_hex_xy(2,3);
+ testrange[5] = HL_hex_xy(2,2);
sort(testrange, 6);
for (i = 0; i < count; i++) {
- ok(range[i] == testrange[i], "3, 3 range 1 hex %d", testrange[i]);
+ ok(HL_hex_eq(&range[i], &testrange[i]), "3, 3 range 1 hex %d", testrange[i]);
}
- start = HL_cantor_xy(0,3);
+ start = HL_hex_xy(0,3);
count = HL_hexes_at_range(start, 1, range, 0);
ok(count == 6, "6 hexes at range1 from 0,3");
- start = HL_cantor_xy(-1,5);
+ start = HL_hex_xy(-1,5);
count = HL_hexes_at_range(start, 1, range, 0);
ok(count == 6, "6 hexes at range1 from -1,5");
- start = HL_cantor_xy(-2,3);
+ start = HL_hex_xy(-2,3);
count = HL_hexes_at_range(start, 1, range, 0);
ok(count == 6, "6 hexes at range1 from -2,3");
- start = HL_cantor_xy(3,3);
+ start = HL_hex_xy(3,3);
count = HL_hexes_at_range(start, 2, range, 0);
ok(count == 12, "6 hexes at range1 from 3,3");