now generating basic king moves + fixed UB with move objects
This commit is contained in:
1 parent
b388adf692
commit
3fe2b9c20c
3 files changed
+37
-10
No files matched your search
+3
-1
@@ -243,7 +243,9 @@ void Board::ResetMoves() {
|
|||||||
void Board::ListMoves() {
|
void Board::ListMoves() {
|
||||||
int count = 1;
|
int count = 1;
|
||||||
for (Move move : moveList) {
|
for (Move move : moveList) {
|
||||||
|
std::cout << count << ". ";
|
||||||
|
move.PrintMove();
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-6
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
constexpr short moveFromMask = 0x3F;
|
constexpr short moveFromMask = 0x3F;
|
||||||
constexpr short moveToMask = 0xFC0;
|
constexpr short moveToMask = 0xFC0;
|
||||||
constexpr short moveFlagsMask = 0xF000;
|
|
||||||
|
|
||||||
enum MOVE_FLAGS {
|
enum MOVE_FLAGS {
|
||||||
quiet, doublePawnPush,
|
quiet, doublePawnPush,
|
||||||
@@ -22,13 +21,15 @@ constexpr std::array<const char*, 14> moveTypes {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Move {
|
struct Move {
|
||||||
public:
|
private:
|
||||||
uint16_t m_move;
|
uint16_t m_move;
|
||||||
|
public:
|
||||||
Move(){}
|
Move() {
|
||||||
|
m_move = 0;
|
||||||
|
}
|
||||||
|
|
||||||
Move(int from, int to, int flags) {
|
Move(int from, int to, int flags) {
|
||||||
m_move |= from;
|
m_move = from;
|
||||||
m_move |= to << 6;
|
m_move |= to << 6;
|
||||||
m_move |= flags << 12;
|
m_move |= flags << 12;
|
||||||
}
|
}
|
||||||
@@ -42,7 +43,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int GetFlags() {
|
int GetFlags() {
|
||||||
return (m_move & moveFlagsMask) >> 12;
|
return m_move >> 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintMove() {
|
void PrintMove() {
|
||||||
|
|||||||
+27
-3
@@ -290,7 +290,28 @@ static void GenQueenMoves(Board &board, bool color) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void GenKingMoves(Board &board, bool color) {
|
static void GenKingMoves(Board &board, bool color) {
|
||||||
|
int kingSquare = (board.colors[color] & board.pieces[King]).getLS1BIndex();
|
||||||
|
|
||||||
|
Bitboard moves = (kingAttacks[kingSquare] & ~board.GetAttackMaps(!color)) & ~board.colors[color];
|
||||||
|
Bitboard captures = moves & board.colors[!color];
|
||||||
|
moves &= ~board.colors[!color];
|
||||||
|
|
||||||
|
while (moves.GetBoard()) {
|
||||||
|
int square = moves.getLS1BIndex();
|
||||||
|
|
||||||
|
board.AddMove(Move(kingSquare, square, quiet));
|
||||||
|
|
||||||
|
moves.PopBit(square);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (captures.GetBoard()) {
|
||||||
|
int square = captures.getLS1BIndex();
|
||||||
|
|
||||||
|
Move move(kingSquare, square, capture);
|
||||||
|
board.AddMove(move);
|
||||||
|
|
||||||
|
captures.PopBit(square);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenAttackMaps(Board &board) {
|
void GenAttackMaps(Board &board) {
|
||||||
@@ -308,11 +329,14 @@ void GenAttackMaps(Board &board) {
|
|||||||
} else if (type == King) {
|
} else if (type == King) {
|
||||||
board.attackMaps[color][type] |= kingAttacks[square].GetBoard();
|
board.attackMaps[color][type] |= kingAttacks[square].GetBoard();
|
||||||
} else if (type == Rook) {
|
} else if (type == Rook) {
|
||||||
board.attackMaps[color][type] |= getRookAttack(square, board.occupied.GetBoard()).GetBoard();
|
board.attackMaps[color][type] |= getRookAttack(square, (board.occupied
|
||||||
|
& ~(board.colors[!color] & board.pieces[King])).GetBoard()).GetBoard();
|
||||||
} else if (type == Bishop) {
|
} else if (type == Bishop) {
|
||||||
board.attackMaps[color][type] |= getBishopAttack(square, board.occupied.GetBoard()).GetBoard();
|
board.attackMaps[color][type] |= getBishopAttack(square, (board.occupied
|
||||||
|
& ~(board.colors[!color] & board.pieces[King])).GetBoard()).GetBoard();
|
||||||
} else if (type == Queen) {
|
} else if (type == Queen) {
|
||||||
board.attackMaps[color][type] |= getQueenAttack(square, board.occupied.GetBoard()).GetBoard();
|
board.attackMaps[color][type] |= getQueenAttack(square, (board.occupied
|
||||||
|
& ~(board.colors[!color] & board.pieces[King])).GetBoard()).GetBoard();
|
||||||
}
|
}
|
||||||
pieces.PopBit(square);
|
pieces.PopBit(square);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user