pieceMask.h
Go to the documentation of this file.
#ifndef _PIECE_MASK_H
#define _PIECE_MASK_H
#include "osl/config.h"
#include "osl/bits/ptypeTraits.h"
static_assert(OSL_WORDSIZE == 64, "word size");
#include "osl/bits/pieceMask64.h"
#include <iosfwd>
namespace osl
{
typedef PieceMask64 PieceMaskBase;
class PieceMask : public PieceMaskBase
{
public:
PieceMask() {}
PieceMask(const PieceMaskBase& base) : PieceMaskBase(base) {}
static const mask_t numToMask(int num) {
return mask_t::makeDirect(1) << PieceMask::numToOffset(num);
}
void setMask(int index,mask_t val) {
mutableMask(index)=val;
}
private:
mask_t& mutableMaskNum(int num) {
return mutableMask(numToIndex(num));
}
const mask_t getMaskNum(int num) const {
return getMask(numToIndex(num));
}
public:
void xorMask(int index,mask_t val) {
mutableMask(index)^=val;
}
void orMask(int index,mask_t val) {
mutableMask(index)|=val;
}
bool test(int num) const {
return (getMaskNum(num)&numToMask(num)).any();
}
void set(int num) {
mutableMaskNum(num)|=numToMask(num);
}
void flip(int num) {
mutableMaskNum(num)^=numToMask(num);
}
void reset(int num) {
mutableMaskNum(num)&= ~numToMask(num);
}
bool any() const { return ! none(); }
const mask_t getMask(int num) const { return PieceMaskBase::getMask(num); }
template <Ptype PTYPE>
const mask_t getMask() const { return getMask(PtypeFuns<PTYPE>::indexNum); }
template <Ptype PTYPE>
const mask_t selectBit() const
{
mask_t mask = getMask<PTYPE>();
mask &= mask_t::makeDirect(PtypeFuns<PtypeFuns<PTYPE>::basicType>::indexMask);
return mask;
}
template <Ptype PTYPE>
void clearBit()
{
mask_t& mask = mutableMask(PtypeFuns<PTYPE>::indexNum);
mask &= ~mask_t::makeDirect(PtypeFuns<PtypeFuns<PTYPE>::basicType>::indexMask);
}
template <Ptype PTYPE>
void setBit()
{
mask_t& mask = mutableMask(PtypeFuns<PTYPE>::indexNum);
mask |= mask_t::makeDirect(PtypeFuns<PtypeFuns<PTYPE>::basicType>::indexMask);
}
};
inline const PieceMask operator&(const PieceMask &m1, const PieceMask &m2) {
return PieceMask64(m1.getMask(0)&m2.getMask(0));
}
inline const PieceMask operator|(const PieceMask &m1, const PieceMask &m2) {
return PieceMask64(m1.getMask(0)|m2.getMask(0));
}
inline const PieceMask operator~(const PieceMask &m1) {
return PieceMask64(~m1.getMask(0));
}
inline bool operator==(const PieceMask &m1, const PieceMask &m2){
return m1.getMask(0)==m2.getMask(0) && m1.getMask(1)==m2.getMask(1);
}
inline bool operator!=(const PieceMask &m1, const PieceMask &m2)
{
return ! (m1 == m2);
}
std::ostream& operator<<(std::ostream& os,PieceMask const& pieceMask);
} // namespace osl
#endif /* _PIECE_MASK_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::PieceMask
駒番号のビットセット.
Definition pieceMask.h:21
osl::PieceMask::getMask
const mask_t getMask() const
unpromote(PTYPE) の駒のbit を*含む*mask_tを取り出す
Definition pieceMask.h:62
osl::PieceMask::setMask
void setMask(int index, mask_t val)
Definition pieceMask.h:28
osl::PieceMask::PieceMask
PieceMask()
Definition pieceMask.h:23
osl::PieceMask::getMask
const mask_t getMask(int num) const
Definition pieceMask.h:59
osl::PieceMask::set
void set(int num)
Definition pieceMask.h:48
osl::PieceMask::clearBit
void clearBit()
unpromote(PTYPE) の駒のbit を消す
Definition pieceMask.h:74
osl::PieceMask::getMaskNum
const mask_t getMaskNum(int num) const
Definition pieceMask.h:35
osl::PieceMask::test
bool test(int num) const
Definition pieceMask.h:45
osl::PieceMask::orMask
void orMask(int index, mask_t val)
Definition pieceMask.h:42
osl::PieceMask::xorMask
void xorMask(int index, mask_t val)
Definition pieceMask.h:39
osl::PieceMask::flip
void flip(int num)
Definition pieceMask.h:51
osl::PieceMask::setBit
void setBit()
unpromote(PTYPE) の駒のbit を立てる
Definition pieceMask.h:81
osl::PieceMask::mutableMaskNum
mask_t & mutableMaskNum(int num)
Definition pieceMask.h:32
osl::PieceMask::any
bool any() const
Definition pieceMask.h:57
osl::PieceMask::numToMask
static const mask_t numToMask(int num)
Definition pieceMask.h:25
osl::PieceMask::selectBit
const mask_t selectBit() const
unpromote(PTYPE) の駒のbit だけ取り出す
Definition pieceMask.h:66
osl::PieceMask::PieceMask
PieceMask(const PieceMaskBase &base)
Definition pieceMask.h:24
osl::PieceMask::reset
void reset(int num)
Definition pieceMask.h:54
osl::container::PieceMask64
Definition pieceMask64.h:12
osl::container::PieceMask64::none
bool none() const
Definition pieceMask64.h:57
osl::container::PieceMask64::numToIndex
static int numToIndex(int)
Definition pieceMask64.h:16
osl::container::PieceMask64::mask
Mask64 mask
Definition pieceMask64.h:14
osl::container::PieceMask64::numToOffset
static int numToOffset(int num)
Definition pieceMask64.h:17
osl::container::PieceMask64::mutableMask
misc::Mask64 & mutableMask(int)
Definition pieceMask64.h:21
osl::container::PieceMask64::getMask
const misc::Mask64 & getMask(int) const
Definition pieceMask64.h:23
osl::misc::GeneralMask< mask_int_t >::makeDirect
static const GeneralMask makeDirect(mask_int_t value)
Definition mask.h:219
config.h
OSL_WORDSIZE
#define OSL_WORDSIZE
Definition config.h:6
osl::misc::mask_t
GeneralMask< mask_int_t > mask_t
Definition mask.h:351
osl
Definition additionalEffect.h:6
osl::operator&
const PieceMask operator&(const PieceMask &m1, const PieceMask &m2)
Definition pieceMask.h:88
osl::operator~
const PieceMask operator~(const PieceMask &m1)
Definition pieceMask.h:94
osl::operator!=
bool operator!=(Offset l, Offset r)
Definition basic_type.h:516
osl::operator|
const PieceMask operator|(const PieceMask &m1, const PieceMask &m2)
Definition pieceMask.h:91
osl::PieceMaskBase
PieceMask64 PieceMaskBase
Definition pieceMask.h:12
osl::operator<<
std::ostream & operator<<(std::ostream &os, Player player)
Definition basic_type.cc:14
osl::operator==
bool operator==(Square l, Square r)
Definition basic_type.h:758
pieceMask64.h
ptypeTraits.h
osl::PtypeFuns
Definition ptypeTraits.h:311
osl::PtypeFuns::basicType
static const Ptype basicType
Definition ptypeTraits.h:320