Put unmake struct on a diet
This commit is contained in:
parent
6954cfcb0c
commit
e400106b55
22
Board.h
22
Board.h
|
|
@ -8,8 +8,7 @@
|
||||||
struct Unmove {
|
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(4enpassantinfo)(1color)(3piecetype)
|
||||||
byte enpassant; // store enpassant state
|
|
||||||
byte revmov; // 8bit integer
|
byte revmov; // 8bit integer
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -97,7 +96,7 @@ void Board::make(Move m) {
|
||||||
// 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];
|
||||||
u.captured = field[m.sq_to];
|
u.captured = field[m.sq_to] | (field[PTR_ENPASSANT] << 4);
|
||||||
u.sq_from = m.sq_from;
|
u.sq_from = m.sq_from;
|
||||||
u.sq_to = m.sq_to;
|
u.sq_to = m.sq_to;
|
||||||
|
|
||||||
|
|
@ -155,15 +154,14 @@ void Board::make(Move m) {
|
||||||
(m.sq_to & 0x7) == (field[PTR_ENPASSANT] & 0x7) &&
|
(m.sq_to & 0x7) == (field[PTR_ENPASSANT] & 0x7) &&
|
||||||
(m.sq_to & 0x70) == (0x50 - 0x30*black_moving())
|
(m.sq_to & 0x70) == (0x50 - 0x30*black_moving())
|
||||||
) {
|
) {
|
||||||
// we are also going to the correct square to do EP.
|
// all EP-conditions are met
|
||||||
// therefore, delete the EP-vurnerable pawn
|
// therefore, delete the EP-vurnerable pawn
|
||||||
byte ep_field = m.sq_to - 16 + 32*black_moving();
|
byte ep_field = m.sq_to - 16 + 32*black_moving();
|
||||||
field[ep_field] = P_EMPTY;
|
field[ep_field] = P_EMPTY;
|
||||||
|
// also put information that we did an EP-capture
|
||||||
|
u.sq_to |= 0x08;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the current enpassant situation
|
|
||||||
u.enpassant = field[PTR_ENPASSANT];
|
|
||||||
|
|
||||||
// handle enpassant setup (double pawn move)
|
// handle enpassant setup (double pawn move)
|
||||||
if(
|
if(
|
||||||
piece_type == W_PAWN &&
|
piece_type == W_PAWN &&
|
||||||
|
|
@ -199,6 +197,7 @@ void Board::make(Move m) {
|
||||||
|
|
||||||
void Board::unmake() {
|
void Board::unmake() {
|
||||||
Unmove u = read_unmove();
|
Unmove u = read_unmove();
|
||||||
|
field[PTR_REVMOV] = u.revmov;
|
||||||
|
|
||||||
byte sq_to = u.sq_to & 0x77;
|
byte sq_to = u.sq_to & 0x77;
|
||||||
byte prom_ep_capt = u.sq_to & 0x88;
|
byte prom_ep_capt = u.sq_to & 0x88;
|
||||||
|
|
@ -206,20 +205,23 @@ void Board::unmake() {
|
||||||
|
|
||||||
if(prom_ep_capt == 0) {
|
if(prom_ep_capt == 0) {
|
||||||
// regular move
|
// regular move
|
||||||
field[u.sq_from] = field[u.sq_to];
|
field[u.sq_from] = field[sq_to];
|
||||||
} else if (prom_ep_capt == 0x80) {
|
} 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 | (field[u.sq_to] & 0b1000);
|
field[u.sq_from] = W_PAWN | (field[u.sq_to] & 0b1000);
|
||||||
} else if (prom_ep_capt == 0x08) {
|
} else if (prom_ep_capt == 0x08) {
|
||||||
// we did an enpassant capture
|
// we did an enpassant capture
|
||||||
byte ep_sq = (sq_to & 0x07) | (u.sq_from & 0x70);
|
byte ep_sq = (u.sq_to & 0x07) | (u.sq_from & 0x70);
|
||||||
field[ep_sq] = W_PAWN | black_moving() << 3;
|
field[ep_sq] = W_PAWN | black_moving() << 3;
|
||||||
|
// also undo the regular move
|
||||||
|
field[u.sq_from] = field[sq_to];
|
||||||
}
|
}
|
||||||
|
|
||||||
field[u.sq_to] = u.captured & 0b1111;
|
field[sq_to] = u.captured & 0b1111;
|
||||||
|
|
||||||
field[PTR_SIDE_AND_CASTLERIGHT] ^= 0x01;
|
field[PTR_SIDE_AND_CASTLERIGHT] ^= 0x01;
|
||||||
|
field[PTR_ENPASSANT] = u.captured >> 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Board::next_unmove() {
|
void Board::next_unmove() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue