Implement Unmake storing and reading (untested)
This commit is contained in:
parent
c1934f6398
commit
3797e28c5b
51
Board.h
51
Board.h
|
|
@ -3,6 +3,13 @@
|
|||
|
||||
#include "Types.h"
|
||||
|
||||
struct Unmake {
|
||||
byte sq_from;
|
||||
byte sq_to;
|
||||
byte enpassant;
|
||||
};
|
||||
|
||||
|
||||
class Board {
|
||||
public:
|
||||
Board();
|
||||
|
|
@ -45,33 +52,49 @@ class Board {
|
|||
|
||||
const byte PTR_ENPASSANT = 0x18;
|
||||
|
||||
const byte UNMAKE_START = 0x1A;
|
||||
const byte PTR_UNMAKE_START = 0x1A;
|
||||
const byte PTR_UNMAKE_LAST = 0x7F;
|
||||
inline byte get_unmake() __attribute__((always_inline)) {
|
||||
return field[PTR_PTR_REVMOV];
|
||||
}
|
||||
byte next_unmake() {
|
||||
field[PTR_PTR_REVMOV]++;
|
||||
if(get_unmake() >= 0x80) {
|
||||
field[PTR_PTR_REVMOV] = UNMAKE_START;
|
||||
return UNMAKE_START;
|
||||
if(get_unmake() > PTR_UNMAKE_LAST) {
|
||||
field[PTR_PTR_REVMOV] = PTR_UNMAKE_START;
|
||||
return PTR_UNMAKE_START;
|
||||
}
|
||||
while(get_unmake() & 0x88) {
|
||||
field[PTR_PTR_REVMOV]++;
|
||||
if(!(get_unmake() & 0x8)) {
|
||||
field[PTR_PTR_REVMOV] += 0x8;
|
||||
}
|
||||
return get_unmake();
|
||||
}
|
||||
byte prev_unmake() {
|
||||
field[PTR_PTR_REVMOV]--;
|
||||
if(get_unmake() < UNMAKE_START) {
|
||||
field[PTR_PTR_REVMOV] = 0x7F;
|
||||
return 0x7F;
|
||||
if(get_unmake() < PTR_UNMAKE_START) {
|
||||
field[PTR_PTR_REVMOV] = PTR_UNMAKE_LAST;
|
||||
return PTR_UNMAKE_LAST;
|
||||
}
|
||||
while(get_unmake() & 0x88) {
|
||||
field[PTR_PTR_REVMOV]--;
|
||||
if(!(get_unmake() & 0x8)) {
|
||||
field[PTR_PTR_REVMOV] -= 0x8;
|
||||
}
|
||||
return get_unmake();
|
||||
}
|
||||
|
||||
void store_unmake(Unmake *u) {
|
||||
field[get_unmake()] = *(byte*)u;
|
||||
for(size_t i = 0; i < sizeof(u); i++) {
|
||||
field[next_unmake()] = *(byte*)(u+i);
|
||||
}
|
||||
}
|
||||
Unmake read_unmake() {
|
||||
Unmake u;
|
||||
byte* ptr = (byte*) &u;
|
||||
for(size_t i = sizeof(u) - 1; i >= 0; i++) {
|
||||
ptr[i] = field[prev_unmake()];
|
||||
}
|
||||
return u;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
|
@ -81,10 +104,4 @@ Board::Board() {
|
|||
}
|
||||
|
||||
|
||||
struct Unmake {
|
||||
byte sq_from;
|
||||
byte sq_to;
|
||||
byte enpassant;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue