Skip to content

Commit

Permalink
Move generation complete
Browse files Browse the repository at this point in the history
  • Loading branch information
mbluemer committed Apr 18, 2017
1 parent 6c1c966 commit 72a0ec8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/BitBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ class BitBoard
int const getIndex(uint32_t piece);

void addJumps(std::vector<Move> &moves);
void addNormalMoves(std::vector<Move> &moves);
void generateAllJumps(BitBoard board, Move move, uint32_t piece, std::vector<Move> &moves);
BitBoard boardMove(BitBoard &board, uint32_t piece, uint32_t moveTo);
std::vector<uint32_t> generateImmediateJumps(uint32_t piece);
void addNewMove(uint32_t start, uint32_t end, std::vector<Move> &moves);

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

std::string const player();
Expand Down
38 changes: 38 additions & 0 deletions src/BitBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string>
#include <vector>
#include <cmath>
#include <iostream>
#include "Move.h"
#include "BitBoard.h"

Expand Down Expand Up @@ -44,6 +45,38 @@ void BitBoard::addJumps(std::vector<Move> &moves)
}
}

void BitBoard::addNormalMoves(std::vector<Move> &moves) {
uint32_t notOcc = ~(m_whitePieces|m_blackPieces);
for (int i = 0; i < 32; ++i) {
uint32_t piece;
if (m_isBlacksTurn) {
piece = m_blackPieces & 1<<i;
if (rotl32(piece, 7) & notOcc & upLeft)
addNewMove(piece, rotl32(piece, 7), moves);
if (rotl32(piece, 1) & notOcc & upRight)
addNewMove(piece, rotl32(piece, 1), moves);
if (piece & m_kings) {
if (rotr32(piece, 7) & notOcc & downRight)
addNewMove(piece, rotr32(piece, 7), moves);
if (rotr32(piece, 1) & notOcc & downLeft)
addNewMove(piece, rotr32(piece, 1), moves);
}
} else {
piece = m_whitePieces & 1<<i;
if (rotr32(piece, 7) & notOcc & downRight)
addNewMove(piece, rotr32(piece, 7), moves);
if (rotr32(piece, 1) & notOcc & downLeft)
addNewMove(piece, rotr32(piece, 1), moves);
if (piece & m_kings) {
if (rotl32(piece, 7) & notOcc & upLeft)
addNewMove(piece, rotl32(piece, 7), moves);
if (rotl32(piece, 1) & notOcc & upRight)
addNewMove(piece, rotl32(piece, 1), moves);
}
}
}
}

void BitBoard::generateAllJumps(BitBoard board, Move move, uint32_t piece, std::vector<Move> &moves)
{
if (move.isEmpty()) move.addMove(getIndex(piece)); // Add start position
Expand Down Expand Up @@ -131,6 +164,8 @@ void BitBoard::addNewMove(uint32_t start, uint32_t end, std::vector<Move> &moves

/* Public functions */

BitBoard::BitBoard() {};

BitBoard::BitBoard(uint32_t black, uint32_t white, uint32_t kings) :
m_blackPieces(black), m_whitePieces(white), m_kings(kings)
{
Expand All @@ -146,6 +181,9 @@ std::vector<Move> const BitBoard::actions()
{
std::vector<Move> moves;
addJumps(moves);
if (moves.empty()) {
addNormalMoves(moves);
}

return moves;
}

0 comments on commit 72a0ec8

Please sign in to comment.