-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitmanip.cpp
More file actions
70 lines (58 loc) · 1.7 KB
/
Copy pathbitmanip.cpp
File metadata and controls
70 lines (58 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "bitmanip.h"
uint32_t transformBits(uint32_t bit, bool left, bool down) {
uint32_t transableBits = bit & ~(RIGHT_EDGE>>(left*7)) & ~(FIRST_ROW<<(down*28));
return ((transableBits & EVEN_ROWS)
<< (4*(down))//modify vertical direction of jump (down the board)
>> (4 + left)//evaluate horizontal direction of jump (up the board)
<< (4*(down)))//finish vertical correction (to not overflow)
+ ((transableBits & ODD_ROWS)
<< (4*(down))
>> (3 + left)
<< (4*(down)));
}
uint32_t Square::getBit() {
return bit;
}
int Square::getRow() {
return
(((bit&ROW_1) > 0) * 0)
+ (((bit&ROW_2) > 0) * 1)
+ (((bit&ROW_3) > 0) * 2)
+ (((bit&ROW_4) > 0) * 3)
+ (((bit&ROW_5) > 0) * 4)
+ (((bit&ROW_6) > 0) * 5)
+ (((bit&ROW_7) > 0) * 6)
+ (((bit&ROW_8) > 0) * 7);
}
int Square::getCol() {
return
(((bit&COL_1) > 0) * 0)
+ (((bit&COL_2) > 0) * 1)
+ (((bit&COL_3) > 0) * 2)
+ (((bit&COL_4) > 0) * 3)
+ (((bit&COL_5) > 0) * 4)
+ (((bit&COL_6) > 0) * 5)
+ (((bit&COL_7) > 0) * 6)
+ (((bit&COL_8) > 0) * 7);
}
Square Square::fromStr(std::string str) {
return fromCoords('8' - str.data()[1], (str.data()[0] - 'a')/2);
}
Square Square::fromBit(uint32_t board) {
Square square;
square.bit = board;
return square;
}
Square Square::fromCoords(int row, int col) {
Square square;
square.bit = (1<<(row*4 + col));
return square;
}
Square Square::transform(bool left, bool down) {
return Square::fromBit(
transformBits(
bit,
left,
down
));
}