Hopefully add castling
This commit is contained in:
parent
e4c7dcc7e2
commit
a995784aac
51
Board.h
51
Board.h
|
|
@ -93,16 +93,59 @@ void Board::print() {
|
||||||
void Board::make(Move m) {
|
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.captured = field[m.sq_to];
|
u.captured = field[m.sq_to];
|
||||||
u.sq_from = m.sq_from;
|
u.sq_from = m.sq_from;
|
||||||
u.sq_to = m.sq_to;
|
u.sq_to = m.sq_to;
|
||||||
|
|
||||||
// TODO handle castling
|
byte piece_type = field[m.sq_from] & 0x8;
|
||||||
// TODO handle castling rights
|
|
||||||
|
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 handle revmov clock
|
||||||
// TODO zobrist
|
// 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
|
// handle enpassant capture
|
||||||
if(field[PTR_ENPASSANT] && (field[m.sq_from] & 0b111) == W_PAWN) {
|
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];
|
u.enpassant = field[PTR_ENPASSANT];
|
||||||
|
|
||||||
// handle enpassant setup (double pawn move)
|
// handle enpassant setup (double pawn move)
|
||||||
// Calculate the move 'amount'
|
|
||||||
int sq_diff = (int)m.sq_from - (int)m.sq_to;
|
|
||||||
if(
|
if(
|
||||||
(field[m.sq_from] & 0b111) == W_PAWN &&
|
(field[m.sq_from] & 0b111) == W_PAWN &&
|
||||||
(sq_diff == 32 || sq_diff == -32)
|
(sq_diff == 32 || sq_diff == -32)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue