Skip to content

Commit

Permalink
squash this later
Browse files Browse the repository at this point in the history
  • Loading branch information
mbluemer committed Apr 18, 2017
1 parent 828fe60 commit 84d4d9e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 11 deletions.
3 changes: 3 additions & 0 deletions include/Move.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class Move
Move();
Move(int start);
void addMove(int move);
void removeLast();
bool isEmpty();
int length();
};

#endif
40 changes: 30 additions & 10 deletions src/BitBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,41 +44,61 @@ void BitBoard::addJumps(std::vector<Move> &moves)
}
}

std::vector<int> BitBoard::generateImmediateJumps(uint32_t piece)
void BitBoard::generateAllJumps(BitBoard board, Move move, uint32_t piece, std::vector<Move> &moves)
{
std::vector<int> moves;
if (move.isEmpty()) move.addMove(getIndex(piece)); // Add start position
std::vector<uint32_t> 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<uint32_t> BitBoard::generateImmediateJumps(uint32_t piece)
{
std::vector<uint32_t> 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;
Expand Down
13 changes: 13 additions & 0 deletions src/Move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
12 changes: 11 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#include <iostream>
#include <cstdint>
#include <vector>
#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<Move> moves = board.generateImmediateJumps(16384);
for (Move move : moves) {
for (int x : move.getMoves()) {
std::cout << x << std::endl;
}
}
return 0;
}

0 comments on commit 84d4d9e

Please sign in to comment.