Start working on unmake

This commit is contained in:
Quinten Kock 2020-06-17 23:19:35 +02:00
parent cc20fa0ce5
commit 6d774260a3
1 changed files with 20 additions and 11 deletions

31
Board.h
View File

@ -9,8 +9,8 @@ struct Unmove {
byte sq_from; // 0b(1unused)(3rank)(1unused)(3file) byte sq_from; // 0b(1unused)(3rank)(1unused)(3file)
byte sq_to; // 0b(1promoted?)(3rank)(1unused)(3file) byte sq_to; // 0b(1promoted?)(3rank)(1unused)(3file)
byte captured; // 0b(4unused)(1color)(3piecetype) byte captured; // 0b(4unused)(1color)(3piecetype)
byte enpassant; byte enpassant; // store enpassant state
byte revmov; byte revmov; // 8bit integer
}; };
class Board { class Board {
@ -91,6 +91,9 @@ void Board::print() {
} }
void Board::make(Move m) { void Board::make(Move m) {
// TODO handle revmov clock
// TODO zobrist?
// fill unmove struct with basic data // fill unmove struct with basic data
Unmove u; Unmove u;
u.revmov = field[PTR_REVMOV]; u.revmov = field[PTR_REVMOV];
@ -110,10 +113,8 @@ void Board::make(Move m) {
int sq_diff = (int)m.sq_from - (int)m.sq_to; int sq_diff = (int)m.sq_from - (int)m.sq_to;
int sq_diff_abs = abs(sq_diff); int sq_diff_abs = abs(sq_diff);
// TODO handle revmov clock
// TODO zobrist
// TODO do any castling testing // TODO test the csatling code
// Handle castling // Handle castling
if(piece_type == W_KING && sq_diff_abs == 2) { if(piece_type == W_KING && sq_diff_abs == 2) {
// We are castling! After all, a king cannot move // We are castling! After all, a king cannot move
@ -185,7 +186,7 @@ void Board::make(Move m) {
// not promoting; so keep the same piece type // not promoting; so keep the same piece type
new_val = field[m.sq_from]; new_val = field[m.sq_from];
} }
// copy (and possibly promote) our piece. // copy or promote our piece.
field[m.sq_to] = new_val; field[m.sq_to] = new_val;
// then delete the original copy. // then delete the original copy.
field[m.sq_from] = P_EMPTY; field[m.sq_from] = P_EMPTY;
@ -197,20 +198,28 @@ void Board::make(Move m) {
} }
void Board::unmake() { void Board::unmake() {
field[PTR_SIDE_AND_CASTLERIGHT] ^= 0x01;
Unmove u = read_unmove(); Unmove u = read_unmove();
if((u.sq_to & 0x80) == 0) {
byte sq_to = u.sq_to & 0x77;
byte prom_ep_capt = u.sq_to & 0x88;
if(prom_ep_capt == 0) {
// regular move // regular move
field[u.sq_from] = field[u.sq_to]; field[u.sq_from] = field[u.sq_to];
} else { } else if (prom_ep_capt == 0x80) {
// piece was promoted // piece was promoted
// so the source is a pawn // so the source is a pawn
field[u.sq_from] = W_PAWN | black_moving() << 3; field[u.sq_from] = W_PAWN | (field[u.sq_to] & 0b1000);
} else if (prom_ep_capt == 0x08) {
// we did an enpassant capture
byte ep_sq = (sq_to & 0x07) | (u.sq_from & 0x70);
field[ep_sq] = W_PAWN | black_moving() << 3;
} }
field[u.sq_to] = u.captured & 0b1111; field[u.sq_to] = u.captured & 0b1111;
field[PTR_SIDE_AND_CASTLERIGHT] ^= 0x01;
} }
void Board::next_unmove() { void Board::next_unmove() {