Fix unmove storing

This commit is contained in:
Quinten Kock 2020-06-16 00:09:54 +02:00
parent 19a2e5e076
commit 7c05006d9d
1 changed files with 29 additions and 31 deletions

60
Board.h
View File

@ -42,7 +42,7 @@ class Board {
private:
static const byte PTR_SIDE_AND_CASTLERIGHT = 0x08; //byte (1=side, 2,4=white castle, 8,16=black)
static const byte PTR_PTR_UNMAKE = 0x09; //byte (points to index)
// CAN FILL 0x09
static const byte PTR_W_KING = 0x0A; // byte (points to index or maybe 64-arr index)
// const byte PTR_B_KING = 0x0B; (PTR_W_KING | COLOR or PTR_W_KING + COLOR)
static const byte PTR_ZOBRIST = 0x0C; // 4 bytes
@ -52,46 +52,44 @@ class Board {
static const byte PTR_ENPASSANT = 0x18;
static const byte PTR_REVMOV = 0x19;
// free space
static const byte PTR_UNMAKE_START = 0x28;
static const byte PTR_UNMAKE_LAST = 0x7F;
inline byte get_unmake() __attribute__((always_inline)) {
return field[PTR_PTR_UNMAKE];
static const byte PTR_UNMOVE_START = 0x28;
static const byte PTR_UNMOVE_LAST = 0x7E;
byte PTR_UNMOVE = PTR_UNMOVE_START;
void next_unmove() {
PTR_UNMOVE++;
if(PTR_UNMOVE > PTR_UNMOVE_LAST) {
panic(F("Unmove stack overflow"));
}
if(!(PTR_UNMOVE & 0x8)) {
PTR_UNMOVE += 0x8;
}
}
byte next_unmake() {
field[PTR_PTR_UNMAKE]++;
if(get_unmake() > PTR_UNMAKE_LAST) {
field[PTR_PTR_UNMAKE] = PTR_UNMAKE_START;
return PTR_UNMAKE_START;
void prev_unmove() {
PTR_UNMOVE--;
if(PTR_UNMOVE < PTR_UNMOVE_START) {
panic(F("Unmaking from empty stack"));
}
if(!(get_unmake() & 0x8)) {
field[PTR_PTR_UNMAKE] += 0x8;
if(!(PTR_UNMOVE & 0x8)) {
PTR_UNMOVE -= 0x8;
}
return get_unmake();
}
byte prev_unmake() {
field[PTR_PTR_UNMAKE]--;
if(get_unmake() < PTR_UNMAKE_START) {
field[PTR_PTR_UNMAKE] = PTR_UNMAKE_LAST;
return PTR_UNMAKE_LAST;
}
if(!(get_unmake() & 0x8)) {
field[PTR_PTR_UNMAKE] -= 0x8;
}
return get_unmake();
}
void store_unmake(Unmake *u) {
field[get_unmake()] = *(byte*)u;
void store_unmove(Unmove u) {
byte *ub = (byte*) &u;
for(size_t i = 0; i < sizeof(u); i++) {
field[next_unmake()] = *(byte*)(u+i);
next_unmove();
field[PTR_UNMOVE] = ub[i];
}
}
Unmake read_unmake() {
Unmake u;
Unmove read_unmove() {
Unmove u;
byte* ptr = (byte*) &u;
for(int i = sizeof(u) - 1; i >= 0; i++) {
ptr[i] = field[prev_unmake()];
for(int i = sizeof(u) - 1; i >= 0; i--) {
ptr[i] = field[PTR_UNMOVE];
prev_unmove();
}
return u;
}