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