numBitmapEffect.h
Go to the documentation of this file.
#ifndef OSL_NUM_BITMAP_EFFECT_H
#define OSL_NUM_BITMAP_EFFECT_H
#include "osl/basic_type.h"
#include "osl/bits/ptypeTraits.h"
#include "osl/bits/pieceMask.h"
namespace osl
{
namespace effect
{
class NumBitmapEffect : public PieceMask
{
public:
NumBitmapEffect(){
resetAll();
}
template<Player P>
static NumBitmapEffect playerEffect(){
NumBitmapEffect ret;
if (P == BLACK) ret.flip(48);
else ret.flip(54);
return ret;
}
static NumBitmapEffect playerEffect(Player pl){
mask_t mask1=numToMask(54);
mask1-=numToMask(48);
mask1&=mask_t::makeDirect(pl);
mask1+=numToMask(48);
NumBitmapEffect ret;
ret.setMask(1,mask1);
assert((pl==BLACK && ret==playerEffect<BLACK>()) ||
(pl==WHITE && ret==playerEffect<WHITE>()));
return ret;
}
template<Player P>
static mask_t playerEffectMask(){
if (P == BLACK) {
mask_t mask1=numToMask(54);
mask1-=numToMask(48);
return mask1;
} else {
mask_t mask1=numToMask(60);
mask1-=numToMask(54);
return mask1;
}
}
static mask_t playerEffectMask(Player pl){
mask_t mask1=numToMask(60);
mask1-=numToMask(48);
mask1&=mask_t::makeDirect(pl);
// pl==BLACK -> mask1 = 0
// pl==WHITE -> mask1 = 0x0fff0000(32bit), 0x0fff000000000000(64bit)
mask_t mask2=numToMask(54);
mask2-=numToMask(48);
// mask2 = 0x3f0000(32bit), 0x3f000000000000(64bit)
mask1^=mask2;
// pl==BLACK -> mask1 = 0x3f0000(32bit), 0x3f000000000000(64bit)
// pl==WHITE -> mask2 = 0x0fc00000(32bit), 0x0fc0000000000000(64bit)
assert((pl==BLACK && mask1==playerEffectMask<BLACK>()) ||
(pl==WHITE && mask1==playerEffectMask<WHITE>()));
return mask1;
}
int countEffect(Player pl) const {
int shift=48+(6&pl);
mask_t mask=getMask(1);
mask>>=numToOffset(shift);
mask&=mask_t::makeDirect(0x3f);
return static_cast<int>(mask.value());
}
template<Player P>
static NumBitmapEffect makeEffect(int num){
NumBitmapEffect effect=playerEffect<P>();
effect.flip(num);
return effect;
}
enum Op{
Add,Sub,
};
template<Op OP>
NumBitmapEffect& opEqual(NumBitmapEffect const& rhs){
if (OP == Add)
*this+=rhs;
else
*this-=rhs;
return *this;
}
static const mask_t longEffectMask() {
#if OSL_WORDSIZE == 64
return mask_t::makeDirect(0xff0000000000uLL);
#elif OSL_WORDSIZE == 32
return mask_t::makeDirect(0xff00u);
#endif
}
#if OSL_WORDSIZE == 64
static const int longToNumOffset=-8;
#elif OSL_WORDSIZE == 32
static const int longToNumOffset=32-8;
#endif
static const mask_t makeLongMask(int num)
{
return mask_t::makeDirect(0x101) << PieceMask::numToOffset(num);
}
template<Player P>
static NumBitmapEffect makeLongEffect(int num){
assert(32<=num && num<=39);
NumBitmapEffect effect=NumBitmapEffect::playerEffect<P>();
effect.orMask(1,makeLongMask(num));
return effect;
}
static NumBitmapEffect makeLongEffect(Player pl,int num){
assert(32<=num && num<=39);
NumBitmapEffect effect=NumBitmapEffect::playerEffect(pl);
effect.orMask(1,makeLongMask(num));
return effect;
}
// utility methods
const mask_t selectLong() const
{
return (getMask(1) & longEffectMask());
}
bool hasLong() const
{
return selectLong().any();
}
template <Ptype PTYPE> const mask_t selectLong() const
{
return selectLong()
& mask_t::makeDirect(PtypeFuns<PTYPE>::indexMask << 8);
}
template <Ptype PTYPE> bool hasLong() const
{
return selectLong<PTYPE>().any();
}
template <Ptype PTYPE> bool hasAny() const
{
return (getMask(PtypeFuns<PTYPE>::indexNum)
& mask_t::makeDirect(PtypeFuns<PTYPE>::indexMask)).any();
}
};
} // namespace effect
} // namespace osl
#endif // _NUM_BITMAP_EFFECT_H
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
basic_type.h
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::flip
void flip(int num)
Definition pieceMask.h:51
osl::PieceMask::numToMask
static const mask_t numToMask(int num)
Definition pieceMask.h:25
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::resetAll
void resetAll()
Definition pieceMask64.h:24
osl::effect::NumBitmapEffect::hasAny
bool hasAny() const
Definition numBitmapEffect.h:155
osl::effect::NumBitmapEffect::countEffect
int countEffect(Player pl) const
Definition numBitmapEffect.h:81
osl::effect::NumBitmapEffect::playerEffect
static NumBitmapEffect playerEffect()
Definition numBitmapEffect.h:35
osl::effect::NumBitmapEffect::longEffectMask
static const mask_t longEffectMask()
Definition numBitmapEffect.h:107
osl::effect::NumBitmapEffect::Op
Op
Definition numBitmapEffect.h:95
osl::effect::NumBitmapEffect::Add
@ Add
Definition numBitmapEffect.h:96
osl::effect::NumBitmapEffect::Sub
@ Sub
Definition numBitmapEffect.h:96
osl::effect::NumBitmapEffect::selectLong
const mask_t selectLong() const
Definition numBitmapEffect.h:146
osl::effect::NumBitmapEffect::makeLongMask
static const mask_t makeLongMask(int num)
Definition numBitmapEffect.h:119
osl::effect::NumBitmapEffect::selectLong
const mask_t selectLong() const
Definition numBitmapEffect.h:138
osl::effect::NumBitmapEffect::makeEffect
static NumBitmapEffect makeEffect(int num)
Definition numBitmapEffect.h:90
osl::effect::NumBitmapEffect::playerEffectMask
static mask_t playerEffectMask()
Definition numBitmapEffect.h:53
osl::effect::NumBitmapEffect::playerEffect
static NumBitmapEffect playerEffect(Player pl)
Definition numBitmapEffect.h:41
osl::effect::NumBitmapEffect::hasLong
bool hasLong() const
Definition numBitmapEffect.h:151
osl::effect::NumBitmapEffect::NumBitmapEffect
NumBitmapEffect()
Definition numBitmapEffect.h:31
osl::effect::NumBitmapEffect::opEqual
NumBitmapEffect & opEqual(NumBitmapEffect const &rhs)
Definition numBitmapEffect.h:99
osl::effect::NumBitmapEffect::makeLongEffect
static NumBitmapEffect makeLongEffect(Player pl, int num)
Definition numBitmapEffect.h:130
osl::effect::NumBitmapEffect::playerEffectMask
static mask_t playerEffectMask(Player pl)
Definition numBitmapEffect.h:65
osl::effect::NumBitmapEffect::hasLong
bool hasLong() const
Definition numBitmapEffect.h:142
osl::effect::NumBitmapEffect::makeLongEffect
static NumBitmapEffect makeLongEffect(int num)
Definition numBitmapEffect.h:124
osl::misc::GeneralMask< mask_int_t >::makeDirect
static const GeneralMask makeDirect(mask_int_t value)
Definition mask.h:219
osl::misc::GeneralMask::any
bool any() const
Definition mask.h:298
osl::effect
Definition effectedNumTable.h:8
osl::misc::mask_t
GeneralMask< mask_int_t > mask_t
Definition mask.h:351
osl
Definition additionalEffect.h:6
osl::Player
Player
Definition basic_type.h:8
osl::WHITE
@ WHITE
Definition basic_type.h:10
osl::BLACK
@ BLACK
Definition basic_type.h:9
pieceMask.h
ptypeTraits.h
osl::PtypeFuns
Definition ptypeTraits.h:311
osl::PtypeFuns::indexMask
static const uint64_t indexMask
Definition ptypeTraits.h:318