-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBitBoard.h
87 lines (68 loc) · 2.75 KB
/
BitBoard.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright Chris Welty
// All Rights Reserved
// This file is distributed subject to GNU GPL version 2. See the files
// Copying.txt and GPL.txt for details.
// board header file
#pragma once
#ifndef _H_BitBoard // MSC sucks
#define _H_BitBoard
#include "BitBoardBlock.h"
class CMoves;
class CBitBoard {
public:
CBitBoardBlock empty, mover;
template<class Archive>
void serialize(Archive& archive, const unsigned int version)
{
archive & empty;
archive & mover;
}
// Set to starting position
void Initialize();
void Initialize(const char* boardText, bool fBlackMove=true);
void SetRow(const char* sRow, int row);
// flipping
void FlipHorizontal();
void FlipVertical();
void FlipDiagonal();
CBitBoard Symmetry(int sym) const;
CBitBoard MinimalReflection() const;
void InvertColors();
// impossible board
void Impossible();
// I/O
void Print(bool fBlackMove) const;// Print the board in human-readable format
void FPrint(FILE* fp, bool blackMove) const;// Print the board in human-readable format
bool Write(FILE* fp) const; // print in bitstream format
bool Read(FILE* fp); // read in bitstream format; return true if successful
char* GetSBoardNonnormalized(char sBoard[NN+1]) const; // turning it back into a string
char* GetSBoardNormalized(char sBoard[NN+1], bool fBlackMove) const; // turning it back into a string
// statistics
u4 Hash() const;
int NEmpty() const;
void NDiscs(bool fBlackMove, int& nBlack, int& nWhite, int& nEmpty) const;
int TerminalValue() const;
// moving
bool CalcMoves(CMoves& moves) const;
int CalcMobility(u4& nMovesPlayer, u4& nMovesOpponent) const;
#ifdef OLD
int CalcMobility(u4& nMovesPlayer, u4& nMovesOpponent, CMoves& moves) const;
#endif
bool operator==(const CBitBoard& b) const;
bool operator!=(const CBitBoard& b) const;
static void Test();
protected:
void FPrintHeader(FILE* fp) const;
};
bool operator<(const CBitBoard& a, const CBitBoard& b);
std::size_t hash_value(const CBitBoard& b);
inline void CBitBoard::Impossible() {
mover[0]=mover[1]=empty[0]=empty[1]=(u4)-1;
}
inline bool CBitBoard::operator==(const CBitBoard& b) const { return mover==b.mover && empty==b.empty;};
inline bool CBitBoard::operator!=(const CBitBoard& b) const { return mover!=b.mover || empty!=b.empty;};
inline void CBitBoard::FlipVertical() { empty.FlipVertical(); mover.FlipVertical();}
inline void CBitBoard::FlipHorizontal() { empty.FlipHorizontal(); mover.FlipHorizontal();}
inline void CBitBoard::FlipDiagonal() { empty.FlipDiagonal(); mover.FlipDiagonal();}
inline void CBitBoard::InvertColors() { mover^=~empty; }
#endif // defined _H_BitBoard