implement more Board functions outside Class definition

This commit is contained in:
Quinten Kock 2020-06-16 00:15:32 +02:00
parent 9adccec70a
commit 3e2fca227b
1 changed files with 39 additions and 34 deletions

73
Board.h
View File

@ -54,41 +54,11 @@ class Board {
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;
}
}
void prev_unmove() {
PTR_UNMOVE--;
if(PTR_UNMOVE < PTR_UNMOVE_START) {
panic(F("Unmaking from empty stack"));
}
if(!(PTR_UNMOVE & 0x8)) {
PTR_UNMOVE -= 0x8;
}
}
void next_unmove();
void prev_unmove();
void store_unmove(Unmove u) {
byte *ub = (byte*) &u;
for(size_t i = 0; i < sizeof(u); i++) {
next_unmove();
field[PTR_UNMOVE] = ub[i];
}
}
Unmove read_unmove() {
Unmove u;
byte* ptr = (byte*) &u;
for(int i = sizeof(u) - 1; i >= 0; i--) {
ptr[i] = field[PTR_UNMOVE];
prev_unmove();
}
return u;
}
void store_unmove(Unmove u);
Unmove read_unmove();
};
@ -114,4 +84,39 @@ void Board::make(Move m) {
Serial.println(u2.sq_to, HEX);
}
void Board::next_unmove() {
PTR_UNMOVE++;
if(PTR_UNMOVE > PTR_UNMOVE_LAST) {
panic(F("Unmove stack overflow"));
}
if(!(PTR_UNMOVE & 0x8)) {
PTR_UNMOVE += 0x8;
}
}
void Board::prev_unmove() {
PTR_UNMOVE--;
if(PTR_UNMOVE < PTR_UNMOVE_START) {
panic(F("Unmaking from empty stack"));
}
if(!(PTR_UNMOVE & 0x8)) {
PTR_UNMOVE -= 0x8;
}
}
void Board::store_unmove(Unmove u) {
byte *ub = (byte*) &u;
for(size_t i = 0; i < sizeof(u); i++) {
next_unmove();
field[PTR_UNMOVE] = ub[i];
}
}
Unmove Board::read_unmove() {
Unmove u;
byte* ptr = (byte*) &u;
for(int i = sizeof(u) - 1; i >= 0; i--) {
ptr[i] = field[PTR_UNMOVE];
prev_unmove();
}
return u;
}
#endif