Skip to content

Commit

Permalink
fix for not moving after a kinging
Browse files Browse the repository at this point in the history
  • Loading branch information
mbluemer committed Apr 29, 2017
1 parent a2e6ef6 commit 5b2b0ed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion include/BitBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class BitBoard
uint32_t m_kings = 0;

bool m_isBlacksTurn = true;
bool m_wasKinged = false;

public:
/* Static bit masks */
Expand Down Expand Up @@ -75,13 +76,14 @@ class BitBoard

public:
BitBoard();
BitBoard(uint32_t black, uint32_t white, uint32_t kings, bool isBlacksTurn);
BitBoard(uint32_t black, uint32_t white, uint32_t kings, bool isBlacksTurn, bool wasKinged);
BitBoard(const BitBoard &board);

uint32_t getBlackPieces() { return m_blackPieces; };
uint32_t getWhitePieces() { return m_whitePieces; };
uint32_t getKings () { return m_kings; };
bool getIsBlacksTurn() { return m_isBlacksTurn; };
bool getWasKinged() { return m_wasKinged; }

std::string player() const;
vmup actions() const;
Expand Down
11 changes: 7 additions & 4 deletions src/BitBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void BitBoard::generateAllJumps(BitBoard board, mup &move, uint32_t piece, vmup
if (move->isEmpty()) move->addMove(getIndex(piece)); // Add start position
std::vector<uint32_t> immediateJumps = generateImmediateJumps(board, piece);

if (immediateJumps.size() == 0) {
if (immediateJumps.size() == 0 || board.getWasKinged()) {
if (move->length() > 1) {
mup newMove(new Move(*move));
moves.push_back(std::move(newMove)); // If no more jumps add move to list of moves
Expand All @@ -115,6 +115,7 @@ BitBoard BitBoard::boardMove(BitBoard &board, uint32_t piece, uint32_t moveTo) c
uint32_t white = board.m_whitePieces;
uint32_t black = board.m_blackPieces;
uint32_t kings = board.m_kings;
bool wasKinged = false;

// First figure out if a piece has been take
int pieceLoc = getIndex(piece);
Expand All @@ -127,15 +128,17 @@ BitBoard BitBoard::boardMove(BitBoard &board, uint32_t piece, uint32_t moveTo) c
if (diff == 2 || diff == 14) white &= ~(1<<avg);
black = (black | moveTo) & ~piece;
kings |= (black & blackKingSpots);
wasKinged = moveTo & blackKingSpots;
} else {
if (diff == 2 || diff == 14) black &= ~(1<<avg);
white = (white | moveTo) & ~piece;
kings |= (white & whiteKingSpots);
wasKinged = moveTo & whiteKingSpots;
}

if (piece & kings) kings = moveTo | (kings & ~piece);

return BitBoard(black, white, kings, board.m_isBlacksTurn);
return BitBoard(black, white, kings, board.m_isBlacksTurn, wasKinged);
}

std::vector<uint32_t> BitBoard::generateImmediateJumps(BitBoard &board, uint32_t piece) const
Expand Down Expand Up @@ -200,8 +203,8 @@ std::string BitBoard::pieceToString(int piece) const

BitBoard::BitBoard() {};

BitBoard::BitBoard(uint32_t black, uint32_t white, uint32_t kings, bool isBlacksTurn) :
m_blackPieces(black), m_whitePieces(white), m_kings(kings), m_isBlacksTurn(isBlacksTurn) {}
BitBoard::BitBoard(uint32_t black, uint32_t white, uint32_t kings, bool isBlacksTurn, bool wasKinged) :
m_blackPieces(black), m_whitePieces(white), m_kings(kings), m_isBlacksTurn(isBlacksTurn), m_wasKinged(wasKinged) {}

BitBoard::BitBoard(const BitBoard &board)
{
Expand Down

0 comments on commit 5b2b0ed

Please sign in to comment.