My code:
board.hpp:
Code: Select all
/*
* board.hpp
* Magic Chess
*
* Created by Matthew Brades on 26/12/2011.
*
*/
#ifndef BOARD_H
#define BOARD_H
#include <stdint.h>
typedef struct move {
unsigned char From,
Dest,
Piece,
Colour,
CapturedPiece,
CapturedColour,
Flags;
} move;
typedef struct moves {
move Stack[100];
int Value[100];
int StackNumber;
} moves;
class board {
public:
board(uint64_t = 0xFF00ULL, uint64_t = 0x42ULL, uint64_t = 0x24ULL,
uint64_t = 0x81ULL, uint64_t = 0x8ULL, uint64_t = 0x10ULL,
uint64_t = 0xFF000000000000ULL, uint64_t = 0x4200000000000000ULL, uint64_t = 0x8100000000000000ULL,
uint64_t = 0x2400000000000000ULL, uint64_t = 0x800000000000000ULL, uint64_t = 0x1000000000000000ULL,
uint64_t = 0ULL, uint64_t = 0xFFFF00000000FFFFULL, uint64_t = 0xFFFFFFFF0000ULL,
uint64_t = 0xFFFF000000000000ULL, uint64_t = 0xFFFFULL, int = 0xFULL);
board(const board&);
void PrintBitboard(uint64_t);
bool MakeMove(move);
bool MakeCapture(move);
void UnmakeMove(move);
void UnmakeCapture(move);
private:
uint64_t Pieces[12],
Colours[2],
Enpassant,
Occupied,
Empty;
int CastlingRights,
SideToMove,
Halfmove,
Fullmove;
} board;
#endif
Code: Select all
/*
* board.cpp
* Magic Chess
*
* Created by Matthew Brades on 26/12/2011.
*
*/
#include "board.hpp"
#include <cstdio>
board::board(uint64_t whitePawns, uint64_t whiteKnights, uint64_t whiteBishops,
uint64_t whiteRooks, uint64_t whiteQueens, uint64_t whiteKing,
uint64_t blackPawns, uint64_t blackKnights, uint64_t blackBishops,
uint64_t blackRooks, uint64_t blackQueens, uint64_t blackKing,
uint64_t enpassant, uint64_t occupied, uint64_t empty,
uint64_t black, uint64_t white, int castlingRights)
{
Pieces[0] = whitePawns;
Pieces[1] = whiteKnights;
Pieces[2] = whiteBishops;
Pieces[3] = whiteRooks;
Pieces[4] = whiteQueens;
Pieces[5] = whiteKing;
Pieces[6] = blackPawns;
Pieces[7] = blackKnights;
Pieces[8] = blackBishops;
Pieces[9] = blackRooks;
Pieces[10] = blackQueens;
Pieces[11] = blackKing;
Enpassant = enpassant;
Occupied = occupied;
Empty = empty;
Colours[0] = white;
Colours[1] = black;
CastlingRights = castlingRights;
}
board::board(const board& Board)
{
for (int i = 0; i < 12 && (Pieces[i] = Board.Pieces[i]); i++)
;
Enpassant = Board.Enpassant;
Occupied = Board.Occupied;
Empty = Board.Empty;
for (int i = 0; i < 2 && (Colours[i] = Board.Colours[i]); i++)
;
CastlingRights = Board.CastlingRights;
}
void PrintBitboard(uint64_t b)
{
printf("%llu\n", b);
}
bool board::MakeMove(move m)
{
uint64_t a, b, c;
a = 1ULL << m.From;
b = 1ULL << m.Dest;
c = a ^ b;
Pieces[m.Piece] ^= c;
Colours[m.Colour] ^= c;
Occupied ^= c;
Empty ^= c;
return true;
}
bool board::MakeCapture(move m)
{
uint64_t a, b, c;
a = 1ULL << m.From;
b = 1ULL << m.Dest;
c = a ^ b;
Pieces[m.Piece] ^= c;
Colours[m.Colour] ^= c;
Pieces[m.CapturedPiece] ^= b;
Colours[m.CapturedColour] ^= b;
Occupied ^= a;
Empty ^= a;
return true;
}
void board::UnmakeMove(move m)
{
uint64_t a, b, c;
a = 1ULL << m.From;
b = 1ULL << m.Dest;
c = a ^ b;
Pieces[m.Piece] ^= c;
Colours[m.Colour] ^= c;
Occupied ^= c;
Empty ^= c;
}
void board::UnmakeCapture(move m)
{
uint64_t a, b, c;
a = 1ULL << m.From;
b = 1ULL << m.Dest;
c = a ^ b;
Pieces[m.Piece] ^= c;
Colours[m.Colour] ^= c;
Pieces[m.CapturedPiece] ^= b;
Colours[m.CapturedColour] ^= b;
Occupied ^= a;
Empty ^= a;
}
Code: Select all
/*
* main.cpp
* My Bitboard Project
*
* Created by Matthew Brades on 26/12/2011.
*
*/
#include "board.hpp"
int main()
{
board x; // expected ';' before 'x'
return 0;
}
When I try it with the class keyword in front of it, it gives me a linker failure (which is understandable)
What am I doing wrong?
Matthew:out