From a995784aac58dcf375e8a19eb6565529e3f55e21 Mon Sep 17 00:00:00 2001 From: Quinten Kock Date: Tue, 16 Jun 2020 03:57:40 +0200 Subject: [PATCH] Hopefully add castling --- Board.h | 51 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/Board.h b/Board.h index 05edf33..c266440 100644 --- a/Board.h +++ b/Board.h @@ -93,16 +93,59 @@ void Board::print() { void Board::make(Move m) { // fill unmove struct with basic data Unmove u; + u.revmov = field[PTR_REVMOV]; u.captured = field[m.sq_to]; u.sq_from = m.sq_from; u.sq_to = m.sq_to; - // TODO handle castling - // TODO handle castling rights + byte piece_type = field[m.sq_from] & 0x8; + + if(u.captured || piece_type == W_PAWN) { + field[PTR_REVMOV]++; + } else { + field[PTR_REVMOV] = 0; + } + + // Calculate the move 'amount' (unique signature for dx,dy) + 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: test enpassant code + // TODO do any castling testing + // Handle castling + if((m.sq_from & 0b111) == W_KING && sq_diff_abs == 2) { + // We are castling! After all, a king cannot move + // more than one position except when castling. + // Since we don't care about legality; just do it + byte castle_source = 0x70*black_moving(); + if(sq_diff == 2) { + castle_source += 0x7; + } + byte castle_target = m.sq_from + (sq_diff/2); + field[castle_target] = field[castle_source]; + field[castle_source] = P_EMPTY; + } + + // Handle castling rights + // We are doing the simple way: + // unset it any time a move is made from the original position. + if(m.sq_from == 0x00) + field[PTR_SIDE_AND_CASTLERIGHT] &= ~0b00010; + if(m.sq_from == 0x07) + field[PTR_SIDE_AND_CASTLERIGHT] &= ~0b00100; + if(m.sq_from == 0x04) + field[PTR_SIDE_AND_CASTLERIGHT] &= ~0b00110; + if(m.sq_from == 0x70) + field[PTR_SIDE_AND_CASTLERIGHT] &= ~0b01000; + if(m.sq_from == 0x77) + field[PTR_SIDE_AND_CASTLERIGHT] &= ~0b10000; + if(m.sq_from == 0x74) + field[PTR_SIDE_AND_CASTLERIGHT] &= ~0b11000; + + + // TODO: test enpassant code more than basics // handle enpassant capture if(field[PTR_ENPASSANT] && (field[m.sq_from] & 0b111) == W_PAWN) { @@ -124,8 +167,6 @@ void Board::make(Move m) { u.enpassant = field[PTR_ENPASSANT]; // handle enpassant setup (double pawn move) - // Calculate the move 'amount' - int sq_diff = (int)m.sq_from - (int)m.sq_to; if( (field[m.sq_from] & 0b111) == W_PAWN && (sq_diff == 32 || sq_diff == -32)