He found another way to write your do-while loop, and he thought that your clever SQUARE64/SQUARE120 macros are correct but a bit too clever to understand immediately, so he wrote some very simple macros instead. I hope he did not make any errors ...
Code: Select all
#include <assert.h>
enum { QUIT = 0, THINK, GETCMD };
#define s32 int
#define u64 unsigned long long
#define CLEVER_SQUARE64(x) (((((x) / 10) - 2) << 3) + ((x) - ((x) / 10 * 10) - 1))
#define CLEVER_SQUARE120(x) (((((x) >> 3) + 2) * 10) + (((x) & 7) + 1))
#define FILE64(s64) ((s64) & 7)
#define RANK64(s64) ((s64) >> 3)
#define FILE120(s120) (((s120) - 21) % 10)
#define RANK120(s120) (((s120) - 21) / 10)
#define SQUARE64_FR(f,r) (((r) << 3) + (f))
#define SQUARE120_FR(f,r) ((10 * (r)) + (f) + 21)
#define SQUARE64(s120) SQUARE64_FR(FILE120(s120), RANK120(s120))
#define SQUARE120(s64) SQUARE120_FR(FILE64(s64), RANK64(s64))
#define BIT64(x) ((u64) 1 << (x))
void validateMacros()
{
#ifndef NDEBUG
s32 r, f;
for (r = 0; r < 8; r++) {
for (f = 0; f < 8; f++) {
s32 s64 = SQUARE64_FR(f, r);
s32 s120 = SQUARE120_FR(f, r);
assert(s64 >= 0);
assert(s64 < 64);
assert(s120 >= 21);
assert(s120 < 99);
assert(FILE64(s64) == f);
assert(RANK64(s64) == r);
assert(FILE120(s120) == f);
assert(RANK120(s120) == r);
assert(SQUARE64(s120) == s64);
assert(SQUARE120(s64) == s120);
assert(SQUARE64(s120) == CLEVER_SQUARE64(s120));
assert(SQUARE120(s64) == CLEVER_SQUARE120(s64));
}
}
#endif
}
void Think(void);
void Initialize(void);
void GetCmd(void);
u64 dirKn[64];
u64 dirKi[64];
u64 dir7p[64];
u64 dir9p[64];
u64 dir7m[64];
u64 dir9m[64];
u64 dir1p[64];
u64 dir8p[64];
u64 dir1m[64];
u64 dir8m[64];
u64 *const dirPtr[8] = { dir7p, dir9p, dir7m, dir9m, dir1p, dir8p, dir1m, dir8m };
s32 mode = GETCMD;
void Think() {
}
void GetCmd() {
mode = QUIT;
}
void Initialize() {
validateMacros();
s32 const dir[8] = { 9, 11, -9, -11, 1, 10, -1, -10 };
s32 const din[8] = { 8, 12, 19, 21, -8, -12, -19, -21 };
s32 const isOffBoard[120] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1
};
s32 fs64;
for (fs64 = 63; fs64 >= 0; fs64--) {
s32 fs120 = SQUARE120(fs64);
s32 i;
dirKn[fs64] = 0;
dirKi[fs64] = 0;
for (i = 7; i >= 0; i--) {
s32 ts120 = fs120 + din[i];
if (!isOffBoard[ts120]) {
dirKn[fs64] |= BIT64(SQUARE64(ts120));
}
dirPtr[i][fs64] = 0;
ts120 = fs120 + dir[i];
if (!isOffBoard[ts120]) {
dirKi[fs64] |= BIT64(SQUARE64(ts120));
do {
dirPtr[i][fs64] |= BIT64(SQUARE64(ts120));
ts120 += dir[i];
} while (!isOffBoard[ts120]);
}
}
}
}
s32 main()
{
Initialize();
while (mode) {
if (mode == THINK) Think();
GetCmd();
}
return 0;
}