Skip to content

Commit

Permalink
Working function to generate immediate jumps
Browse files Browse the repository at this point in the history
  • Loading branch information
mbluemer committed Apr 18, 2017
1 parent 69a5717 commit 7298345
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 7 deletions.
10 changes: 8 additions & 2 deletions include/BitBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,15 @@ class BitBoard
int h8() const;
int h9() const;
int h10() const;
int const getIndex(uint32_t piece);

void addBlackJumps(std::vector<Move> &moves);
std::vector<Move> generateImmediateJumps(uint32_t piece);
void addNewMove(uint32_t start, uint32_t end, std::vector<Move> &moves);

public:
BitBoard(uint32_t black, uint32_t white, uint32_t kings);


public:
std::string const player();
std::vector<Move> const actions();
BitBoard const result(Move move);
Expand Down
6 changes: 4 additions & 2 deletions include/Move.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define MOVE_H

#include <vector>
#include <cstdint>

class Move
{
Expand All @@ -10,8 +11,9 @@ class Move

public:

Move() : moves() {};
void printMessage();
Move();
Move(int start);
void addMove(int move);
};

#endif
84 changes: 83 additions & 1 deletion src/BitBoard.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#include <cstdint>
#include <limits.h>
#include <string>
#include <vector>
#include <cmath>
#include "Move.h"
#include "BitBoard.h"

/* Private Functions */


// These are basic 32 bit rotation functions
// Details here: http://stackoverflow.com/questions/776508/best-practices-for-circular-shift-rotate-operations-in-c
uint32_t const BitBoard::rotl32 (uint32_t n, unsigned int c) const
{
const unsigned int mask = (CHAR_BIT*sizeof(n)-1);
Expand All @@ -22,9 +26,87 @@ uint32_t const BitBoard::rotr32 (uint32_t n, unsigned int c) const
return (n>>c) | (n<<( (-c)&mask ));
}

// Given a piece represented by a binary value return it's index
int const BitBoard::getIndex(uint32_t piece)
{
return (int)std::log2(piece);
}

void BitBoard::addBlackJumps(std::vector<Move> &moves)
{
uint32_t notOcc = ~(m_whitePieces|m_blackPieces);
for (int i = 0; i < 32; ++i) {
// grab the specific piece
uint32_t piece = m_blackPieces & 1<<i;
if (piece) {
//
}
}
}

std::vector<Move> BitBoard::generateImmediateJumps(uint32_t piece)
{
std::vector<Move> 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)
addNewMove(piece, rotl32(piece, 14), moves);
temp = (rotl32(piece, 1) & upRight) & m_whitePieces;
if ((rotl32(temp, 1) & upRight) & notOcc)
addNewMove(piece, rotl32(piece, 2), moves);
if (isKing) {
temp = (rotr32(piece, 7) & downRight) & m_whitePieces;
if ((rotr32(temp, 7) & downRight) & notOcc)
addNewMove(piece, rotr32(piece, 14), moves);
temp = (rotr32(piece, 1) & downLeft) & m_whitePieces;
if ((rotr32(temp, 1) & downLeft) & notOcc)
addNewMove(piece, rotr32(piece, 2), moves);
}
} else {
temp = (rotr32(piece, 7) & downRight) & m_blackPieces;
if ((rotr32(temp, 7) & downRight) & notOcc)
addNewMove(piece, rotr32(piece, 14), moves);
temp = (rotr32(piece, 1) & downLeft) & m_blackPieces;
if ((rotr32(temp, 1) & downLeft) & notOcc)
addNewMove(piece, rotr32(piece, 2), moves);
if (isKing) {
temp = (rotl32(piece, 7) & upLeft) & m_blackPieces;
if ((rotl32(temp, 7) & upLeft) & notOcc)
addNewMove(piece, rotl32(piece, 14), moves);
temp = (rotl32(piece, 1) & upRight) & m_blackPieces;
if ((rotl32(temp, 1) & upRight) & notOcc)
addNewMove(piece, rotl32(piece, 2), moves);
}
}
return moves;
}

void BitBoard::addNewMove(uint32_t start, uint32_t end, std::vector<Move> &moves)
{
Move newMove(getIndex(start));
newMove.addMove(getIndex(end));
moves.push_back(newMove);
}

/* Public functions */

BitBoard::BitBoard(uint32_t black, uint32_t white, uint32_t kings) :
m_blackPieces(black), m_whitePieces(white), m_kings(kings)
{
m_isBlacksTurn = true;
}

std::string const BitBoard::player()
{
return m_isBlacksTurn ? "black" : "white";
}

std::vector<Move> const BitBoard::actions()
{
std::vector<Move> moves;

return moves;
}
12 changes: 10 additions & 2 deletions src/Move.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#include <iostream>
#include "Move.h"

void Move::printMessage()
Move::Move() : moves() {};

Move::Move(int start)
{
std::cout << "Here is an example message" << std::endl;
moves = {start};
}

void Move::addMove(int move)
{
moves.push_back(move);
}

0 comments on commit 7298345

Please sign in to comment.