diff --git a/include/Move.h b/include/Move.h index cb8ff26..fdbeb22 100644 --- a/include/Move.h +++ b/include/Move.h @@ -14,6 +14,9 @@ class Move Move(); Move(int start); void addMove(int move); + void removeLast(); + bool isEmpty(); + int length(); }; #endif diff --git a/src/BitBoard.cpp b/src/BitBoard.cpp index 6d283f4..7aee00a 100644 --- a/src/BitBoard.cpp +++ b/src/BitBoard.cpp @@ -44,41 +44,61 @@ void BitBoard::addJumps(std::vector &moves) } } -std::vector BitBoard::generateImmediateJumps(uint32_t piece) +void BitBoard::generateAllJumps(BitBoard board, Move move, uint32_t piece, std::vector &moves) { - std::vector moves; + if (move.isEmpty()) move.addMove(getIndex(piece)); // Add start position + std::vector immediateJumps = generateImmediateJumps(piece); + if (immediateJumps.size() == 0) { + if (move.length > 1) moves.push_back(move); // If no more jumps add move to list of moves + } else { + for (uint32_t x : immediateJumps) { + move.add(getIndex(x)); + generateAllJumps(boardMove(board, piece, x), move, x, moves); + move.removeLast(); + } + } +} + +BitBoard BitBoard::boardMove(BitBoard &board, uint32_t piece, uint32_t moveTo) +{ + +} + +std::vector BitBoard::generateImmediateJumps(uint32_t piece) +{ + std::vector moves; uint32_t notOcc = ~(m_whitePieces|m_blackPieces); uint32_t temp; bool isKing = piece & m_kings; if (m_isBlacksTurn) { temp = (rotl32(piece, 7) & upLeft) & m_whitePieces; if ((rotl32(temp, 7) & upLeft) & notOcc) - moves.push_back(getIndex(rotl32(temp, 7))); + moves.push_back(rotl32(temp, 7)); temp = (rotl32(piece, 1) & upRight) & m_whitePieces; if ((rotl32(temp, 1) & upRight) & notOcc) - moves.push_back(getIndex(rotl32(temp, 1))); + moves.push_back(rotl32(temp, 1)); if (isKing) { temp = (rotr32(piece, 7) & downRight) & m_whitePieces; if ((rotr32(temp, 7) & downRight) & notOcc) - moves.push_back(getIndex(rotr32(temp, 7))); + moves.push_back(rotr32(temp, 7)); temp = (rotr32(piece, 1) & downLeft) & m_whitePieces; if ((rotr32(temp, 1) & downLeft) & notOcc) - moves.push_back(getIndex(rotr32(temp, 1))); + moves.push_back(rotr32(temp, 1)); } } else { temp = (rotr32(piece, 7) & downRight) & m_blackPieces; if ((rotr32(temp, 7) & downRight) & notOcc) - moves.push_back(getIndex(rotr32(temp, 7))); + moves.push_back(rotr32(temp, 7)); temp = (rotr32(piece, 1) & downLeft) & m_blackPieces; if ((rotr32(temp, 1) & downLeft) & notOcc) - moves.push_back(getIndex(rotr32(temp, 1))); + moves.push_back(rotr32(temp, 1)); if (isKing) { temp = (rotl32(piece, 7) & upLeft) & m_blackPieces; if ((rotl32(temp, 7) & upLeft) & notOcc) - moves.push_back(getIndex(rotl32(temp, 7))); + moves.push_back(rotl32(temp, 7)); temp = (rotl32(piece, 1) & upRight) & m_blackPieces; if ((rotl32(temp, 1) & upRight) & notOcc) - moves.push_back(getIndex(rotl32(temp, 1))); + moves.push_back(rotl32(temp, 1)); } } return moves; diff --git a/src/Move.cpp b/src/Move.cpp index cd24105..488e0cc 100644 --- a/src/Move.cpp +++ b/src/Move.cpp @@ -13,3 +13,16 @@ void Move::addMove(int move) moves.push_back(move); } +void Move::removeLast() +{ + moves.pop_back(); +} + +bool Move::isEmpty() +{ + return moves.isEmpty(); +} + int Move::length() +{ + return moves.size(); +} diff --git a/src/main.cpp b/src/main.cpp index 2a87151..feead06 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,16 @@ #include +#include +#include +#include "BitBoard.h" +#include "Move.h" int main(int argc, const char * argv[]) { - std::cout << "Hello world!" << std::endl; + BitBoard board(16384, 2097280, 16384); + std::vector moves = board.generateImmediateJumps(16384); + for (Move move : moves) { + for (int x : move.getMoves()) { + std::cout << x << std::endl; + } + } return 0; }