/usr/include/osl/effect/boardBitMask.h is in libosl-dev 0.6.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | /* boardBitMask.h
*/
#ifndef _BOARD_BIT_MASK_H
#define _BOARD_BIT_MASK_H
#include "osl/square.h"
#include "osl/misc/carray.h"
#include "osl/misc/carray2d.h"
#include <iosfwd>
namespace osl
{
namespace effect
{
/**
* SSE2も可なのだが,あまり良い方法が見つからない
*/
#ifdef USE_XMM
typedef int v4sf __attribute__ ((mode(V4SF))); // works
#endif
struct BoardBitMask{
#ifdef USE_XMM
union {
v4sf xmm;
CArray<unsigned long long,2> mask;
CArray<unsigned char,16> bMask;
};
#else
union {
CArray<unsigned long long,2> mask;
CArray<unsigned char,16> bMask;
};
#endif
friend BoardBitMask& operator&=(BoardBitMask& lhs,BoardBitMask const& rhs);
friend BoardBitMask& operator^=(BoardBitMask& lhs,BoardBitMask const& rhs);
friend BoardBitMask operator^(BoardBitMask& src1,BoardBitMask const& src2);
public:
BoardBitMask(){}
template<class State>
explicit BoardBitMask(State const& st){
clearAll();
for(int y=1;y<=9;y++){
for(int x=1;x<=9;x++){
Square position(x,y);
if (st.pieceAt(position).isEmpty())
setBit(positionToOffset(position));
}
}
}
/**
* すべてのビットが0のものを作る
*/
void clearAll(){mask[0]=mask[1]=0ull;}
void setAll(){mask[0]=mask[1]=static_cast<unsigned long long>(-1ll);}
/**
* 0-8 11-19 22-30
* 33-41 44-52 55-63
* 66-74 77-85 88-96
* でやってみる
* 香車と角の利きをなんとかするアイデアもあったのだが
*/
static int positionToOffset(Square pos){
assert(pos.isOnBoard());
const int x=pos.x();
const int y=pos.y();
return (x-1)*11+(y-1);
}
/**
* @param offset(0-96) - bitをセットする
*/
void setBit(int offset){
assert(0<=offset && offset<=96);
int index=offset>>6;
unsigned long long tmpMask=1ull<<(offset&63);
assert((index == 0) || (index == 1));
mask[index]|= tmpMask;
}
void setBit(Square pos){
setBit(positionToOffset(pos));
}
/**
* @param offset(0-96) - bitをクリアする
*/
void clearBit(int offset){
assert(0<=offset && offset<=96);
int index=offset>>6;
unsigned long long tmpMask=1ull<<(offset&63);
assert((index == 0) || (index == 1));
mask[index]&= ~tmpMask;
}
void clearBit(Square pos){
clearBit(positionToOffset(pos));
}
bool isZero() const{
return (mask[0]|mask[1])==0ull;
}
BoardBitMask& operator=(BoardBitMask const& rhs){
if (this == &rhs)
return *this;
#ifdef USE_XMM
xmm=rhs.xmm;
#else
mask[0]=rhs.mask[0];
mask[1]=rhs.mask[1];
#endif
return *this;
}
};
inline BoardBitMask& operator^=(BoardBitMask& lhs,BoardBitMask const& rhs){
#ifdef USE_XMM
lhs.xmm=__builtin_ia32_xorps(lhs.xmm,rhs.xmm);
#else
lhs.mask[0]^=rhs.mask[0];
lhs.mask[1]^=rhs.mask[1];
#endif
return lhs;
}
inline BoardBitMask operator^(BoardBitMask const& lhs,BoardBitMask const& rhs){
#ifdef USE_XMM
BoardBitMask ret=lhs;
ret.xmm=__builtin_ia32_xorps(lhs.xmm,rhs.xmm);
return ret;
#else
BoardBitMask ret=lhs;
ret.mask[0]^=rhs.mask[0];
ret.mask[1]^=rhs.mask[1];
return ret;
#endif
}
std::ostream& operator<<(std::ostream& os,BoardBitMask const& boardBitMask);
class BoardBitMaskTable{
CArray<BoardBitMask, Square::SIZE> maskOfSquare;
/**
* lanceに関しては作らなくても良いかも
* lanceBetweenMask[from][to] が non all 0 なら黒からの利きがある
*/
CArray2d<BoardBitMask,Square::SIZE,Square::SIZE> rookBetweenMask;
/**
*
*/
CArray2d<BoardBitMask, Square::SIZE,Square::SIZE> lanceBetweenMask;
CArray2d<BoardBitMask, Square::SIZE,Square::SIZE> bishopBetweenMask;
private:
void initMaskOfSquare();
void initBetweenMask();
public:
BoardBitMaskTable();
const BoardBitMask& getMask(Square pos) const{
assert(pos.isOnBoard());
return maskOfSquare[pos.index()];
}
const BoardBitMask& getRookMask(Square from,Square to) const{
assert(from.isOnBoard() && to.isOnBoard());
return rookBetweenMask[from.index()][to.index()];
}
const BoardBitMask& getBishopMask(Square from,Square to) const{
assert(from.isOnBoard() && to.isOnBoard());
return bishopBetweenMask[from.index()][to.index()];
}
const BoardBitMask& getLanceMask(Square from,Square to) const{
assert(from.isOnBoard() && to.isOnBoard());
return lanceBetweenMask[from.index()][to.index()];
}
};
#if 0
// テーブル削除予定
extern const BoardBitMaskTable Board_Bit_Mask_Table;
#endif
} // namespace effect
} // namespace osl
#endif // _BOARD_BIT_MASK_H
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
|