-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMove.cpp
More file actions
62 lines (51 loc) · 1.89 KB
/
Copy pathMove.cpp
File metadata and controls
62 lines (51 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "Move.h"
// Create a move by packing all components into a 32-bit integer
// Uses bit shifting to efficiently store all move information
Move createMove(int from, int to, int piece, int captured, int promoted, int flags) {
return (from & FROM_MASK) // Bits 0-5: from square
| ((to & TO_MASK) << 6) // Bits 6-11: to square
| ((piece & PIECE_MASK) << 12) // Bits 12-15: moving piece
| ((captured & CAPTURED_MASK) << 16) // Bits 16-19: captured piece
| ((promoted & PROMOTED_MASK) << 20) // Bits 20-23: promotion piece
| ((flags & FLAGS_MASK) << 24); // Bits 24-31: move flags
}
// Extract the source square from a move (0-63)
int getFrom(Move move) {
return move & FROM_MASK;
}
// Extract the destination square from a move (0-63)
int getTo(Move move) {
return (move >> 6) & TO_MASK;
}
// Extract the moving piece type from a move
int getPiece(Move move) {
return (move >> 12) & PIECE_MASK;
}
// Extract the captured piece type from a move (0 if no capture)
int getCaptured(Move move) {
return (move >> 16) & CAPTURED_MASK;
}
// Extract the promotion piece type from a move (0 if no promotion)
int getPromoted(Move move) {
return (move >> 20) & PROMOTED_MASK;
}
// Extract the move flags from a move
int getFlags(Move move) {
return (move >> 24) & FLAGS_MASK;
}
// Add a move to the move list by creating and storing the packed move
void MoveList::addMove(int from, int to, int piece, int captured, int promoted, int flags) {
moves.push_back(createMove(from, to, piece, captured, promoted, flags));
}
// Clear all moves from the list
void MoveList::clear() {
moves.clear();
}
// Get the number of moves in the list
size_t MoveList::size() const {
return moves.size();
}
// Access a move by index
Move MoveList::operator[](size_t index) const {
return moves[index];
}