static void movetonotation(struct pos pos,struct move m, char *str, int color) { /* make a notation out of a move */ /* m is the move, str the string, color the side to move */ int from, to; char c; /* WHITE 28 29 30 31 32 31 30 29 24 25 26 27 28 27 26 25 20 21 22 23 24 23 22 21 16 17 18 19 20 19 18 17 12 13 14 15 16 15 14 13 8 9 10 11 12 11 10 9 4 5 6 7 8 7 6 5 0 1 2 3 4 3 2 1 BLACK */ static int square[32]={4,3,2,1,8,7,6,5, 12,11,10,9,16,15,14,13, 20,19,18,17,24,23,22,21, 28,27,26,25,32,31,30,29}; /* maps bits to checkers notation */ if(color==BLACK) { if(m.wk|m.wm) c='x'; else c='-'; /* capture or normal ? */ from=(m.bm|m.bk)&(pos.bm|pos.bk); /* bit set on square from */ to= (m.bm|m.bk)&(~(pos.bm|pos.bk)); from=lastbit(from); to=lastbit(to); from=square[from]; to=square[to]; sprintf(str,"%2i%c%2i",from,c,to); } else { if(m.bk|m.bm) c='x'; else c='-'; /* capture or normal ? */ from=(m.wm|m.wk)&(pos.wm|pos.wk); /* bit set on square from */ to= (m.wm|m.wk)&(~(pos.wm|pos.wk)); from=lastbit(from); to=lastbit(to); from=square[from]; to=square[to]; sprintf(str,"%2i%c%2i",from,c,to); } return; }
TEST(LastBitTest, lastbit64) { // There are uint16_t, uint32_t and uint64_t overloads of lastbit. // Explicitly cast arg so we know which we are testing. EXPECT_EQ(0, lastbit(uint64_t(0))); EXPECT_EQ(0, lastbit(uint64_t(1))); EXPECT_EQ(1, lastbit(uint64_t(2))); EXPECT_EQ(0, lastbit(uint64_t(3))); EXPECT_EQ(2, lastbit(uint64_t(4))); EXPECT_EQ(0, lastbit(uint64_t(31))); EXPECT_EQ(5, lastbit(uint64_t(32))); EXPECT_EQ(2, lastbit(uint64_t(36))); for (int i = 1; i < 64; i++) { EXPECT_EQ(0, lastbit(uint64_t((UINT64_C(1) << i) - 1))); EXPECT_EQ(i, lastbit(uint64_t((UINT64_C(1) << i)))); EXPECT_EQ(0, lastbit(uint64_t((UINT64_C(1) << i) + 1))); if (i < 62) { EXPECT_EQ( i, lastbit(uint64_t((UINT64_C(1) << i) | (UINT64_C(1) << (i + 2))))); } } }