boardMask.h
Go to the documentation of this file.
/* boardMask.h
*/
#ifndef OSL_BOARDMASK_H
#define OSL_BOARDMASK_H
#include "osl/basic_type.h"
#include "osl/bits/directionTraits.h"
#include "osl/bits/mask.h"
#include "osl/container.h"
#include <iosfwd>
namespace osl
{
namespace container
{
class BoardMask;
bool operator==(const BoardMask&, const BoardMask&);
std::ostream& operator<<(std::ostream&, const BoardMask&);
class BoardMask
{
CArray<unsigned long long,3> contents;
public:
BoardMask() { invalidate(); }
BoardMask(const BoardMask& src) {
contents[0] = src.contents[0];
contents[1] = src.contents[1];
}
BoardMask& operator=(const BoardMask& src) {
if (this != &src) {
contents[0] = src.contents[0];
contents[1] = src.contents[1];
}
return *this;
}
void clear() { contents[0]=contents[1]=0; }
void invalidate() { contents[0] = static_cast<uint64_t>(-1); }
bool isInvalid() const { return contents[0] == static_cast<uint64_t>(-1); }
void set(unsigned int i) {
int j=(i>>6);
contents[j]|=(1ull<<(i&63));
}
void set(Square pos) {
set(index(pos));
}
void reset(unsigned int i) {
int j=(i>>6);
contents[j] &= ~(1ull<<(i&63));
}
void reset(Square pos) { reset(index(pos)); }
bool test(unsigned int i) const {
int j=(i>>6);
return (contents[j]&(1ull<<(i&63)))!=0;
}
bool test(Square pos) const { return test(index(pos)); }
bool anyInRange(const BoardMask& mask) const
{
return (contents[0] & mask.contents[0])
|| (contents[1] & mask.contents[1]);
}
BoardMask& operator|=(const BoardMask& mask)
{
contents[0] |= mask.contents[0];
contents[1] |= mask.contents[1];
return *this;
}
bool any() const
{
assert(! isInvalid());
return contents[0] || contents[1];
}
Square takeOneBit()
{
assert(! isInvalid() && any());
if (contents[0])
return toSquare(BitOp::takeOneBit(contents[0]));
return toSquare(BitOp::takeOneBit(contents[1])+64);
}
static int index(int x,int y){ return x*12+y+1; }
static int index(Square pos) {
int v=pos.index();
return v-((v>>2)&0x3c);
}
template<Direction Dir,Player P>
static int getIndexOffset() {
int blackDx=DirectionTraitsGen<Dir>::blackDx;
int blackDy=DirectionTraitsGen<Dir>::blackDy;
int val=blackDx*12+blackDy;
if(P==BLACK) return val;
else return -val;
}
static Square toSquare(int n) { return Square::makeDirect(n+(((n*21)>>8)<<2)); }
friend bool operator==(const BoardMask&, const BoardMask&);
};
inline const BoardMask operator|(const BoardMask& l, const BoardMask& r)
{
BoardMask result = l;
result |= r;
return result;
}
inline bool operator==(const BoardMask& l, const BoardMask& r)
{
return l.contents[0] == r.contents[0]
&& l.contents[1] == r.contents[1];
}
class BoardMaskTable5x5
{
CArray<BoardMask, Square::SIZE> data;
public:
BoardMaskTable5x5();
const BoardMask& mask(Square p) const { return data[p.index()]; }
};
extern const BoardMaskTable5x5 Board_Mask_Table5x5;
class BoardMaskTable3x3
{
CArray<BoardMask, Square::SIZE> data;
public:
BoardMaskTable3x3();
const BoardMask& mask(Square p) const { return data[p.index()]; }
};
extern const BoardMaskTable3x3 Board_Mask_Table3x3;
class BoardMaskTable5x3Center
{
CArray<BoardMask, Square::SIZE> data;
public:
BoardMaskTable5x3Center();
const BoardMask& mask(Square p) const { return data[p.index()]; }
};
extern const BoardMaskTable5x3Center Board_Mask_Table5x3_Center;
} // namespace container
using container::BoardMask;
using container::Board_Mask_Table5x5;
using container::Board_Mask_Table5x3_Center;
using container::Board_Mask_Table3x3;
} // namespace osl
#endif /* OSL_BOARDMASK_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
basic_type.h
osl::BoardMask::BoardMask
BoardMask()
Definition boardMask.h:25
osl::CArray
Definition container.h:20
osl::Square
Definition basic_type.h:532
osl::Square::index
unsigned int index() const
Definition basic_type.h:572
osl::Square::makeDirect
static const Square makeDirect(int value)
Definition basic_type.h:538
osl::container::BoardMaskTable3x3::mask
const BoardMask & mask(Square p) const
p中心の3x3 の範囲のbitを立てたもの, centeringなし
Definition boardMask.h:123
osl::container::BoardMaskTable3x3::BoardMaskTable3x3
BoardMaskTable3x3()
Definition boardMask.cc:43
osl::container::BoardMaskTable3x3::data
CArray< BoardMask, Square::SIZE > data
Definition boardMask.h:119
osl::container::BoardMaskTable5x3Center::mask
const BoardMask & mask(Square p) const
p中心の5x3 の範囲のbitを立てたもの, centering
Definition boardMask.h:133
osl::container::BoardMaskTable5x3Center::data
CArray< BoardMask, Square::SIZE > data
Definition boardMask.h:129
osl::container::BoardMaskTable5x3Center::BoardMaskTable5x3Center
BoardMaskTable5x3Center()
Definition boardMask.cc:64
osl::container::BoardMaskTable5x5::mask
const BoardMask & mask(Square p) const
p中心の5x5 の範囲のbitを立てたもの, centeringなし
Definition boardMask.h:113
osl::container::BoardMaskTable5x5::data
CArray< BoardMask, Square::SIZE > data
Definition boardMask.h:109
osl::container::BoardMaskTable5x5::BoardMaskTable5x5
BoardMaskTable5x5()
Definition boardMask.cc:22
osl::container::BoardMask
11 x 12
Definition boardMask.h:21
osl::container::BoardMask::test
bool test(Square pos) const
Definition boardMask.h:56
osl::container::BoardMask::takeOneBit
Square takeOneBit()
Definition boardMask.h:73
osl::container::BoardMask::reset
void reset(unsigned int i)
Definition boardMask.h:47
osl::container::BoardMask::set
void set(Square pos)
Definition boardMask.h:44
osl::container::BoardMask::set
void set(unsigned int i)
Definition boardMask.h:40
osl::container::BoardMask::contents
CArray< unsigned long long, 3 > contents
the third one is only for edge
Definition boardMask.h:23
osl::container::BoardMask::any
bool any() const
Definition boardMask.h:68
osl::container::BoardMask::operator=
BoardMask & operator=(const BoardMask &src)
Definition boardMask.h:30
osl::container::BoardMask::operator|=
BoardMask & operator|=(const BoardMask &mask)
Definition boardMask.h:62
osl::container::BoardMask::index
static int index(int x, int y)
Definition boardMask.h:80
osl::container::BoardMask::operator==
friend bool operator==(const BoardMask &, const BoardMask &)
Definition boardMask.h:102
osl::container::BoardMask::clear
void clear()
Definition boardMask.h:37
osl::container::BoardMask::test
bool test(unsigned int i) const
Definition boardMask.h:52
osl::container::BoardMask::anyInRange
bool anyInRange(const BoardMask &mask) const
Definition boardMask.h:57
osl::container::BoardMask::index
static int index(Square pos)
Definition boardMask.h:81
osl::container::BoardMask::invalidate
void invalidate()
Definition boardMask.h:38
osl::container::BoardMask::getIndexOffset
static int getIndexOffset()
Definition boardMask.h:86
osl::container::BoardMask::BoardMask
BoardMask()
Definition boardMask.h:25
osl::container::BoardMask::toSquare
static Square toSquare(int n)
Definition boardMask.h:93
osl::container::BoardMask::reset
void reset(Square pos)
Definition boardMask.h:51
osl::container::BoardMask::isInvalid
bool isInvalid() const
Definition boardMask.h:39
osl::container::BoardMask::BoardMask
BoardMask(const BoardMask &src)
Definition boardMask.h:26
container.h
directionTraits.h
mask.h
osl::container
Definition bitXmask.h:12
osl::container::operator|
const BoardMask operator|(const BoardMask &l, const BoardMask &r)
Definition boardMask.h:96
osl::container::Board_Mask_Table5x5
const BoardMaskTable5x5 Board_Mask_Table5x5
Definition tables.cc:119
osl::container::operator==
bool operator==(BitXmask l, BitXmask r)
Definition bitXmask.h:33
osl::container::Board_Mask_Table3x3
const BoardMaskTable3x3 Board_Mask_Table3x3
Definition tables.cc:120
osl::container::Board_Mask_Table5x3_Center
const BoardMaskTable5x3Center Board_Mask_Table5x3_Center
Definition tables.cc:121
osl::container::operator<<
std::ostream & operator<<(std::ostream &, const BitXmask)
Definition bitXmask.cc:6
osl
Definition additionalEffect.h:6
osl::Board_Mask_Table5x5
const BoardMaskTable5x5 Board_Mask_Table5x5
Definition tables.cc:119
osl::Board_Mask_Table3x3
const BoardMaskTable3x3 Board_Mask_Table3x3
Definition tables.cc:120
osl::BLACK
@ BLACK
Definition basic_type.h:9
osl::Board_Mask_Table5x3_Center
const BoardMaskTable5x3Center Board_Mask_Table5x3_Center
Definition tables.cc:121
osl::BitOp::takeOneBit
static int takeOneBit(Integer &mask)
Definition mask.h:148
osl::DirectionTraitsGen
Definition directionTraits.h:11