fixed viri move format
This commit is contained in:
1 parent
5ad924f3c6
commit
34f5bbdd43
1 file changed
+23
-15
+23
-15
@@ -79,15 +79,21 @@ public:
|
||||
uint16_t ConvertToViriMoveFormat() {
|
||||
uint16_t viriMove = 0;
|
||||
int flags = GetFlags();
|
||||
|
||||
// Set from and to squares (6 bits each)
|
||||
viriMove |= MoveFrom();
|
||||
viriMove |= MoveTo() << 6;
|
||||
|
||||
|
||||
// Define masks for different parts of the move
|
||||
const uint16_t FROM_MASK = 0x3F; // 6 bits for the 'from' square (0-63)
|
||||
const uint16_t TO_MASK = 0x3F; // 6 bits for the 'to' square (0-63)
|
||||
const uint16_t MOVE_TYPE_MASK = 0x3 << 12; // 2 bits for the move type (castling, en passant, promotion, etc.)
|
||||
const uint16_t PROMO_PIECE_MASK = 0x3 << 14; // 2 bits for the promotion piece (knight, bishop, etc.)
|
||||
|
||||
// Set 'from' and 'to' squares
|
||||
viriMove |= (MoveFrom() & FROM_MASK); // Mask the 'from' square
|
||||
viriMove |= (MoveTo() & TO_MASK) << 6; // Mask the 'to' square
|
||||
|
||||
// Determine move type (bits 12-13)
|
||||
uint16_t moveType = 0;
|
||||
uint16_t promoPiece = 0;
|
||||
|
||||
|
||||
if (flags == kingCastle || flags == queenCastle) {
|
||||
moveType = 1; // Castling
|
||||
}
|
||||
@@ -98,23 +104,25 @@ public:
|
||||
moveType = 3; // Promotion
|
||||
// Set promo piece (bits 14-15)
|
||||
if (flags == knightPromotion || flags == knightPromoCapture) {
|
||||
promoPiece = 0; // Knight
|
||||
promoPiece = 1; // Knight
|
||||
}
|
||||
else if (flags == bishopPromotion || flags == bishopPromoCapture) {
|
||||
promoPiece = 1; // Bishop
|
||||
promoPiece = 2; // Bishop
|
||||
}
|
||||
else if (flags == rookPromotion || flags == rookPromoCapture) {
|
||||
promoPiece = 2; // Rook
|
||||
promoPiece = 3; // Rook
|
||||
}
|
||||
else if (flags == queenPromotion || flags == queenPromoCapture) {
|
||||
promoPiece = 3; // Queen
|
||||
promoPiece = 4; // Queen
|
||||
}
|
||||
}
|
||||
// else moveType remains 0 (normal move)
|
||||
|
||||
viriMove |= moveType << 12;
|
||||
viriMove |= promoPiece << 14;
|
||||
|
||||
|
||||
// Apply move type (bits 12-13) using mask
|
||||
viriMove |= (moveType & MOVE_TYPE_MASK);
|
||||
|
||||
// Apply promotion piece (bits 14-15) using mask
|
||||
viriMove |= (promoPiece & PROMO_PIECE_MASK);
|
||||
|
||||
return viriMove;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user