diff --git a/Board.h b/Board.h index 71a5804..b6041b0 100644 --- a/Board.h +++ b/Board.h @@ -9,8 +9,8 @@ struct Unmove { byte sq_from; // 0b(1unused)(3rank)(1unused)(3file) byte sq_to; // 0b(1promoted?)(3rank)(1unused)(3file) byte captured; // 0b(4unused)(1color)(3piecetype) - byte enpassant; - byte revmov; + byte enpassant; // store enpassant state + byte revmov; // 8bit integer }; class Board { @@ -91,6 +91,9 @@ void Board::print() { } void Board::make(Move m) { + // TODO handle revmov clock + // TODO zobrist? + // fill unmove struct with basic data Unmove u; 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_abs = abs(sq_diff); - // TODO handle revmov clock - // TODO zobrist - // TODO do any castling testing + // TODO test the csatling code // Handle castling if(piece_type == W_KING && sq_diff_abs == 2) { // 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 new_val = field[m.sq_from]; } - // copy (and possibly promote) our piece. + // copy or promote our piece. field[m.sq_to] = new_val; // then delete the original copy. field[m.sq_from] = P_EMPTY; @@ -197,20 +198,28 @@ void Board::make(Move m) { } void Board::unmake() { - field[PTR_SIDE_AND_CASTLERIGHT] ^= 0x01; - 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 field[u.sq_from] = field[u.sq_to]; - } else { + } else if (prom_ep_capt == 0x80) { // piece was promoted // 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[PTR_SIDE_AND_CASTLERIGHT] ^= 0x01; } void Board::next_unmove() {