now generating basic king moves + fixed UB with move objects

This commit is contained in:
rektdie committed 2024-04-05 21:27:15 +02:00
1 parent b388adf692
commit 3fe2b9c20c
3 files changed
+39 -12

No files matched your search

+3 -1
View File
@@ -243,7 +243,9 @@ void Board::ResetMoves() {
void Board::ListMoves() {
int count = 1;
for (Move move : moveList) {
std::cout << count << ". ";
move.PrintMove();
count++;
}
}
+9 -8
View File
@@ -3,7 +3,6 @@
constexpr short moveFromMask = 0x3F;
constexpr short moveToMask = 0xFC0;
constexpr short moveFlagsMask = 0xF000;
enum MOVE_FLAGS {
quiet, doublePawnPush,
@@ -22,15 +21,17 @@ constexpr std::array<const char*, 14> moveTypes {
};
struct Move {
public:
private:
uint16_t m_move;
Move(){}
public:
Move() {
m_move = 0;
}
Move(int from, int to, int flags) {
m_move |= from;
m_move |= to << 6;
m_move |= flags << 12;
m_move = from;
m_move |= to << 6;
m_move |= flags << 12;
}
int MoveFrom() {
@@ -42,7 +43,7 @@ public:
}
int GetFlags() {
return (m_move & moveFlagsMask) >> 12;
return m_move >> 12;
}
void PrintMove() {
+27 -3
View File
@@ -290,7 +290,28 @@ static void GenQueenMoves(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) {
@@ -308,11 +329,14 @@ void GenAttackMaps(Board &board) {
} else if (type == King) {
board.attackMaps[color][type] |= kingAttacks[square].GetBoard();
} 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) {
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) {
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);
}