Skip to content

Commit

Permalink
derived constructors bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cnpapado committed Apr 6, 2020
1 parent e153b7a commit 54be162
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.out
.vscode/
21 changes: 10 additions & 11 deletions Bitboard.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "bitboard.hpp"


Bitboard::Bitboard(U64 dec){
Bitboard::Bitboard(U64 dec) {
bb = dec;
}

Expand All @@ -10,7 +10,7 @@ int Bitboard::BitScanForward() {
* returns the index of LSB between [0,63]
* adapted by CPW, original by @author Kim Walisch (2012)
*/
if (!bb) throw "empty bitboard";
if (!bb) throw empty_bitboard();
const int index64[64] = {
0, 47, 1, 56, 48, 27, 2, 60,
57, 49, 41, 37, 28, 16, 3, 61,
Expand All @@ -26,7 +26,7 @@ int Bitboard::BitScanForward() {
return index64[((bb ^ (bb-1)) * debruijn64) >> 58];
}

void Bitboard::printNumber() {
void Bitboard::printNumber() const{
std::cout << bb;
return;
}
Expand All @@ -43,25 +43,24 @@ std::ostream& operator<<(std::ostream &out, const Bitboard board){
return out;
}

bool Bitboard::empty() {
bool Bitboard::empty() const {
return bb == 0;
}

Bitboard Bitboard::getComplement() {
Bitboard Bitboard::getComplement() const {
return Bitboard(~bb);
}

void Bitboard::bitToggle(int index) {
bb ^= (1ULL << index);
return ;
}
std::list<int> Bitboard::extractIndexes() {
std::list<int> Bitboard::extractIndexes() const {
Bitboard temp = *this;
std::list<int> myList;
while (bb) {
myList.push_back(Bitboard::BitScanForward());
bb &= bb-1; //reset LSB
while (temp.bb) {
myList.push_back(temp.BitScanForward());
temp.bb &= temp.bb-1; //reset LSB
}
return myList;
}


10 changes: 7 additions & 3 deletions bitboard.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <iostream>
#include <list>
#include <string>
#include <exception>

typedef unsigned long long int U64;
#define C64(constantU64) constantU64##ULL
Expand All @@ -15,15 +16,17 @@ class Bitboard {
friend std::ostream& operator<<(std::ostream &out, Bitboard bit); //prints as chessboard
void printNumber() const; //prints number
bool empty() const;
int BitScanForward();
protected:
U64 bb; //bitboard 64bit
int BitScanForward();
static const U64 notAFile = 0xfefefefefefefefe;
static const U64 notHFile = 0x7f7f7f7f7f7f7f7f;
static const U64 notABFile = 0xFCFCFCFCFCFCFCFC;
static const U64 notGHFile = 0x3F3F3F3F3F3F3F3F;
static const U64 firstRank = (1ULL << 8)-1;
static const U64 secondRank = (1ULL << 16)-1;
static const U64 eighthRank = (1ULL << 63)-1;
class empty_bitboard : public std::exception {};
};

class BitboardPawns : public Bitboard { //protected or public ??
Expand Down Expand Up @@ -63,15 +66,16 @@ class BitboardRooks : public Bitboard {
Bitboard RookMoves(int index, Bitboard occupiedBitboard); //check if we include last blocker
protected:
enum rookDirection {north, south, west, east}; //??
U64 rookRays[4][64]; //rays[direction][index] - possible moves when chessboard is empty
static U64 rookRays[4][64]; //rays[direction][index] - possible moves when chessboard is empty
void initializeRookRays();
};

class BitboardBishops : public Bitboard {
public:
Bitboard BishopMoves(int index, Bitboard occupiedBitboard); //check if we include last blocker
protected:
enum bishopDirection {northWest, southWest, northEast, southEast}; //??
U64 bishopRays[4][64]; //rays[direction][index] - possible moves when chessboard is empty
static U64 bishopRays[4][64]; //rays[direction][index] - possible moves when chessboard is empty
};

class BitboardQueens : public BitboardRooks, public BitboardBishops {
Expand Down

0 comments on commit 54be162

Please sign in to comment.