From e19af9df0e2d46ba8801029e9ea2a7d80eded2ca Mon Sep 17 00:00:00 2001 From: rektdie Date: Fri, 18 Apr 2025 10:08:43 +0200 Subject: [PATCH] reworked viri move | bench 1422551 --- source/move.h | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/source/move.h b/source/move.h index d9ee537..a2b36d0 100644 --- a/source/move.h +++ b/source/move.h @@ -84,48 +84,42 @@ public: uint16_t viriMove = 0; int flags = GetFlags(); - // 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.) + const uint16_t TO_MASK = 0xFC0; + const uint16_t MOVE_TYPE_MASK = 0x3000; + const uint16_t PROMO_PIECE_MASK = 0xC000; - // Set 'from' and 'to' squares - viriMove |= (MoveFrom() & FROM_MASK); // Mask the 'from' square - viriMove |= (MoveTo() & TO_MASK) << 6; // Mask the 'to' square + viriMove |= MoveFrom(); + viriMove |= (MoveTo() << 6) & TO_MASK; - // Determine move type (bits 12-13) uint16_t moveType = 0; uint16_t promoPiece = 0; if (flags == kingCastle || flags == queenCastle) { - moveType = 1; // Castling + moveType = 2; } else if (flags == epCapture) { - moveType = 2; // En passant + moveType = 1; } else if (flags >= knightPromotion && flags <= queenPromoCapture) { - moveType = 3; // Promotion - // Set promo piece (bits 14-15) + moveType = 3; + if (flags == knightPromotion || flags == knightPromoCapture) { - promoPiece = 1; // Knight + promoPiece = 0; } else if (flags == bishopPromotion || flags == bishopPromoCapture) { - promoPiece = 2; // Bishop + promoPiece = 0; } else if (flags == rookPromotion || flags == rookPromoCapture) { - promoPiece = 3; // Rook + promoPiece = 0; } else if (flags == queenPromotion || flags == queenPromoCapture) { - promoPiece = 4; // Queen + promoPiece = 0; } } - // Apply move type (bits 12-13) using mask - viriMove |= (moveType & MOVE_TYPE_MASK); + viriMove |= (moveType << 12) & MOVE_TYPE_MASK; - // Apply promotion piece (bits 14-15) using mask - viriMove |= (promoPiece & PROMO_PIECE_MASK); + viriMove |= (promoPiece << 14) & PROMO_PIECE_MASK; return viriMove; }