numSimpleEffect.h
Go to the documentation of this file.
#ifndef OSL_NUM_SIMPLE_EFFECT_H
#define OSL_NUM_SIMPLE_EFFECT_H
#include "osl/simpleState.h"
#include "osl/bits/numBitmapEffect.h"
#include "osl/bits/boardMask.h"
#include "osl/bits/bitXmask.h"
#include "osl/bits/effectedNumTable.h"
#include "osl/mobility/mobilityTable.h"
namespace osl
{
namespace checkmate
{
class King8Info;
}
namespace effect
{
class NumSimpleEffectTable;
bool operator==(const NumSimpleEffectTable&,const NumSimpleEffectTable&);
std::ostream& operator<<(std::ostream&, const NumSimpleEffectTable&);
class NumSimpleEffectTable
{
protected:
CArray<NumBitmapEffect, Square::SIZE> effects
#ifdef __GNUC__
__attribute__((aligned(16)))
#endif
;
CArray<BoardMask,2> changed_effects; // each player
NumBitmapEffect changed_effect_pieces;
public:
CArray<PieceMask,2> effected_mask;
CArray<PieceMask,2> effected_changed_mask;
mobility::MobilityTable mobilityTable;
EffectedNumTable effectedNumTable;
template<Player P,Ptype T,Direction Dir,NumBitmapEffect::Op OP,bool UC>
void doEffectShort(const SimpleState& state,Square pos,int num)
{
if ((PtypeTraits<T>::moveMask & DirectionTraits<Dir>::mask)!=0)
{
const Square target = pos+DirectionPlayerTraits<Dir,P>::offset();
effects[target.index()].template opEqual<OP>(NumBitmapEffect::makeEffect<P>(num));
if(UC){
int posIndex=BoardMask::index(pos);
changed_effects[P].set(posIndex+BoardMask::getIndexOffset<Dir,P>());
int num1;
if(Piece::isPieceNum(num1=state.pieceAt(target).number())){
if(OP==NumBitmapEffect::Add){
effected_mask[P].set(num1);
}
else{ // OP==Sub
if((effects[target.index()].getMask(1)&NumBitmapEffect::playerEffectMask(P)).none()){
effected_mask[P].reset(num1);
}
}
effected_changed_mask[P].set(num1);
}
}
}
}
template<Player P,Ptype T,Direction Dir,NumBitmapEffect::Op OP,bool UC>
void doEffectLong(const SimpleState& state,Square pos,int num)
{
if ((PtypeTraits<T>::moveMask & DirectionTraits<DirectionPlayerTraits<Dir,P>::directionByBlack>::mask)!=0)
{
int posIndex;
if(UC){
posIndex=BoardMask::index(pos);
}
const Offset offset=DirectionPlayerTraits<Dir,BLACK>::offset();
assert(!offset.zero());
NumBitmapEffect effect=NumBitmapEffect::makeLongEffect<P>(num);
const Direction SD=longToShort(Dir);
if(OP==NumBitmapEffect::Sub){
Square ePos=mobilityTable.get(longToShort(Dir),num);
int count=((SD==D || SD==DL || SD==DR) ? ePos.y()-pos.y() :
( (SD==U || SD==UL || SD==UR) ? pos.y()-ePos.y() :
( SD==L ? ePos.x()-pos.x() : pos.x()-ePos.x())));
assert(0<=count && count<=9);
if(UC){
for(int i=1;i<count;i++){
pos+=offset;
posIndex+=BoardMask::getIndexOffset<Dir,BLACK>();
effects[pos.index()].template opEqual<OP>(effect);
changed_effects[P].set(posIndex);
}
Piece p;
mobilityTable.set(longToShort(Dir),num,Square::STAND());
int num1=state.pieceAt(ePos).number();
if (!Piece::isEdgeNum(num1)){
effectedNumTable[num1][SD]=EMPTY_NUM;
effects[ePos.index()].template opEqual<OP>(effect);
effected_changed_mask[P].set(num1);
posIndex+=BoardMask::getIndexOffset<Dir,BLACK>();
changed_effects[P].set(posIndex);
if((effects[ePos.index()].getMask(1)&NumBitmapEffect::playerEffectMask(P)).none()){
effected_mask[P].reset(num1);
}
}
}
else{
for(int i=0;i<count;i++){
pos+=offset;
effects[pos.index()].template opEqual<OP>(effect);
}
int num1=state.pieceAt(ePos).number();
if (!Piece::isEdgeNum(num1))
effectedNumTable[num1][SD]=EMPTY_NUM;
}
}
else{ // OP==Add
for (;;)
{
pos=pos+offset;
if(UC){
posIndex+=BoardMask::getIndexOffset<Dir,BLACK>();
changed_effects[P].set(posIndex);
}
effects[pos.index()].template opEqual<OP>(effect);
// effect内にemptyを含むようにしたら短くなる
int num1=state.pieceAt(pos).number();
if (!Piece::isEmptyNum(num1)){
if(UC){
mobilityTable.set(longToShort(Dir),num,pos);
if(!Piece::isEdgeNum(num1)){
effectedNumTable[num1][SD]=num;
changed_effects[P].set(posIndex);
effected_mask[P].set(num1);
effected_changed_mask[P].set(num1);
}
}
else if(!Piece::isEdgeNum(num1)){
effectedNumTable[num1][SD]=num;
}
break;
}
}
}
}
}
template<Player P,Ptype T,NumBitmapEffect::Op OP,bool UC>
void doEffectBy(const SimpleState& state,Square pos,int num);
template<NumBitmapEffect::Op OP,bool UC>
void doEffect(const SimpleState& state,PtypeO ptypeo,Square pos,int num);
template<NumBitmapEffect::Op OP,bool UC>
void doEffect(const SimpleState& state,Piece p)
{
doEffect<OP,UC>(state,p.ptypeO(),p.square(),p.number());
}
void init(const SimpleState& state);
NumSimpleEffectTable(const SimpleState& state)
{
assert(reinterpret_cast<size_t>(this) % 16 == 0);
init(state);
}
const NumBitmapEffect effectSetAt(Square pos) const
{
return effects[pos.index()];
}
template<NumBitmapEffect::Op OP,bool UC>
void doBlockAt(const SimpleState& state,Square pos,int piece_num);
friend bool operator==(const NumSimpleEffectTable& et1,const NumSimpleEffectTable& et2);
/*
*
*/
const BoardMask changedEffects(Player pl) const{
return changed_effects[pl];
}
const NumBitmapEffect changedPieces() const {
return changed_effect_pieces;
}
const PieceMask effectedMask(Player pl) const {
return effected_mask[playerToIndex(pl)];
}
const PieceMask effectedChanged(Player pl) const {
return effected_changed_mask[playerToIndex(pl)];
}
void setChangedPieces(NumBitmapEffect const& effect) {
changed_effect_pieces |= effect;
}
void clearChangedEffects(){
changed_effects[0].clear();
changed_effects[1].clear();
changed_effect_pieces.resetAll();
}
void invalidateChangedEffects(){
changed_effects[0].invalidate();
changed_effects[1].invalidate();
changed_effect_pieces.setAll();
}
void clearEffectedChanged(){
effected_changed_mask[0].resetAll();
effected_changed_mask[1].resetAll();
}
void copyFrom(const NumSimpleEffectTable& src);
};
inline bool operator!=(const NumSimpleEffectTable& et1,const NumSimpleEffectTable& et2)
{
return !(et1==et2);
}
} // namespace effect
using effect::NumBitmapEffect;
} // namespace osl
template<osl::effect::NumBitmapEffect::Op OP,bool UC>
void osl::effect::
NumSimpleEffectTable::doBlockAt(const SimpleState& state,Square pos,int piece_num)
{
if(UC){
setChangedPieces(effects[pos.index()]);
}
mask_t mask1 =((effects[pos.index()].getMask(1))
& NumBitmapEffect::longEffectMask());
while (mask1.any()){
int num=mask1.takeOneBit()+NumBitmapEffect::longToNumOffset;
assert(32<=num && num<=39);
Piece p1=state.pieceOf(num);
Player pl1=p1.owner();
assert(p1.ptype()!=PPAWN);
Square pos1=p1.square();
Offset offset0;
Direction d=Board_Table.getShort8<BLACK>(pos1,pos,offset0);
if(OP==NumBitmapEffect::Sub){
Square endSquare=mobilityTable.get(d,num);
NumBitmapEffect effect=NumBitmapEffect::makeLongEffect(pl1,num);
Piece p;
Square pos2=pos+offset0;
int pos2Index, offset81;
if(UC){
int posIndex=BoardMask::index(pos);
pos2Index=BoardMask::index(pos2);
offset81=pos2Index-posIndex;
}
for(;pos2!=endSquare;pos2+=offset0){
if(UC){
changed_effects[pl1].set(pos2Index);
pos2Index+=offset81;
}
effects[pos2.index()].template opEqual<OP>(effect);
}
effects[pos2.index()].template opEqual<OP>(effect);
int num1=state.pieceAt(endSquare).number();
if (!Piece::isEdgeNum(num1)){
effectedNumTable[num1][d]=EMPTY_NUM;
if(UC){
changed_effects[pl1].set(pos2Index);
if((effects[endSquare.index()].getMask(1)&NumBitmapEffect::playerEffectMask(pl1)).none()){
effected_mask[pl1].reset(num1);
}
effected_changed_mask[pl1].set(num1);
mobilityTable.set(d,num,pos);
}
}
else
mobilityTable.set(d,num,pos);
effectedNumTable[piece_num][d]=num;
}
else{
NumBitmapEffect effect=NumBitmapEffect::makeLongEffect(pl1,num);
Square pos2=pos+offset0;
int pos2Index, offset81;
if(UC){
int posIndex=BoardMask::index(pos);
pos2Index=BoardMask::index(pos2);
offset81=pos2Index-posIndex;
}
for(;;){
int num1=state.pieceAt(pos2).number();
if(!Piece::isEmptyNum(num1)){
if(UC){
mobilityTable.set(d,num,pos2);
if(!Piece::isEdgeNum(num1)){
effectedNumTable[num1][d]=num;
effects[pos2.index()].template opEqual<OP>(effect);
changed_effects[pl1].set(pos2Index);
effected_mask[pl1].set(num1);
effected_changed_mask[pl1].set(num1);
}
}
else if(!Piece::isEdgeNum(num1)){
effectedNumTable[num1][d]=num;
effects[pos2.index()].template opEqual<OP>(effect);
}
break;
}
if(UC){
changed_effects[pl1].set(pos2Index);
pos2Index+=offset81;
}
effects[pos2.index()].template opEqual<OP>(effect);
pos2+=offset0;
}
}
}
}
#endif // OSL_NUM_SIMPLE_EFFECT_H
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
bitXmask.h
boardMask.h
osl::BoardMask::index
static int index(int x, int y)
Definition boardMask.h:80
osl::BoardMask::getIndexOffset
static int getIndexOffset()
Definition boardMask.h:86
osl::CArray
Definition container.h:20
osl::NumBitmapEffect::longEffectMask
static const mask_t longEffectMask()
Definition numBitmapEffect.h:107
osl::NumBitmapEffect::Add
@ Add
Definition numBitmapEffect.h:96
osl::NumBitmapEffect::Sub
@ Sub
Definition numBitmapEffect.h:96
osl::NumBitmapEffect::makeEffect
static NumBitmapEffect makeEffect(int num)
Definition numBitmapEffect.h:90
osl::NumBitmapEffect::playerEffectMask
static mask_t playerEffectMask()
Definition numBitmapEffect.h:53
osl::NumBitmapEffect::makeLongEffect
static NumBitmapEffect makeLongEffect(int num)
Definition numBitmapEffect.h:124
osl::Offset
座標の差分
Definition basic_type.h:430
osl::Offset::zero
bool zero() const
Definition basic_type.h:502
osl::PieceMask
駒番号のビットセット.
Definition pieceMask.h:21
osl::Piece
駒.
Definition basic_type.h:788
osl::Piece::ptypeO
PtypeO ptypeO() const
Definition basic_type.h:824
osl::Piece::ptype
Ptype ptype() const
Definition basic_type.h:821
osl::Piece::square
const Square square() const
Definition basic_type.h:832
osl::Piece::owner
Player owner() const
Definition basic_type.h:963
osl::Piece::isPieceNum
static bool isPieceNum(int num)
Definition basic_type.h:926
osl::Piece::isEmptyNum
static bool isEmptyNum(int num)
Definition basic_type.h:916
osl::Piece::number
int number() const
Definition basic_type.h:828
osl::Piece::isEdgeNum
static bool isEdgeNum(int num)
Definition basic_type.h:922
osl::SimpleState
Definition simpleState.h:35
osl::SimpleState::pieceOf
const Piece pieceOf(int num) const
Definition simpleState.h:76
osl::SimpleState::pieceAt
const Piece pieceAt(Square sq) const
Definition simpleState.h:167
osl::Square
Definition basic_type.h:532
osl::Square::index
unsigned int index() const
Definition basic_type.h:572
osl::Square::y
int y() const
将棋としてのY座標を返す.
Definition basic_type.h:567
osl::Square::STAND
static const Square STAND()
Definition basic_type.h:548
osl::Square::x
int x() const
将棋としてのX座標を返す.
Definition basic_type.h:563
osl::checkmate::King8Info
敵玉の8近傍の状態を表す.
Definition king8Info.h:29
osl::container::BoardMask
11 x 12
Definition boardMask.h:21
osl::effect::EffectedNumTable
Definition effectedNumTable.h:44
osl::effect::NumBitmapEffect
現在の定義 (2005/3/4以降)
Definition numBitmapEffect.h:29
osl::effect::NumSimpleEffectTable
局面全体の利きデータ.
Definition numSimpleEffect.h:27
osl::effect::NumSimpleEffectTable::clearEffectedChanged
void clearEffectedChanged()
Definition numSimpleEffect.h:260
osl::effect::NumSimpleEffectTable::copyFrom
void copyFrom(const NumSimpleEffectTable &src)
主要部分を高速にコピーする.
Definition numSimpleEffect.cc:23
osl::effect::NumSimpleEffectTable::doEffect
void doEffect(const SimpleState &state, PtypeO ptypeo, Square pos, int num)
ある種類の駒が持つ利きを更新する.
osl::effect::NumSimpleEffectTable::effectedNumTable
EffectedNumTable effectedNumTable
effected num
Definition numSimpleEffect.h:43
osl::effect::NumSimpleEffectTable::changedEffects
const BoardMask changedEffects(Player pl) const
Definition numSimpleEffect.h:235
osl::effect::NumSimpleEffectTable::doEffectLong
void doEffectLong(const SimpleState &state, Square pos, int num)
ある位置からある方向に長い利きがある時に，その方向の利きを更新する.
Definition numSimpleEffect.h:89
osl::effect::NumSimpleEffectTable::doEffectShort
void doEffectShort(const SimpleState &state, Square pos, int num)
ある位置からある方向に短い利きがある時に，その方向の利きを更新する.
Definition numSimpleEffect.h:54
osl::effect::NumSimpleEffectTable::clearChangedEffects
void clearChangedEffects()
Definition numSimpleEffect.h:250
osl::effect::NumSimpleEffectTable::effectSetAt
const NumBitmapEffect effectSetAt(Square pos) const
ある位置の利きデータを取り出す.
Definition numSimpleEffect.h:219
osl::effect::NumSimpleEffectTable::doEffect
void doEffect(const SimpleState &state, Piece p)
ある駒が持つ利きを更新する.
Definition numSimpleEffect.h:198
osl::effect::NumSimpleEffectTable::invalidateChangedEffects
void invalidateChangedEffects()
Definition numSimpleEffect.h:255
osl::effect::NumSimpleEffectTable::changedPieces
const NumBitmapEffect changedPieces() const
Definition numSimpleEffect.h:238
osl::effect::NumSimpleEffectTable::effectedMask
const PieceMask effectedMask(Player pl) const
Definition numSimpleEffect.h:241
osl::effect::NumSimpleEffectTable::operator==
friend bool operator==(const NumSimpleEffectTable &et1, const NumSimpleEffectTable &et2)
osl::effect::NumSimpleEffectTable::NumSimpleEffectTable
NumSimpleEffectTable(const SimpleState &state)
コンストラクタ.
Definition numSimpleEffect.h:210
osl::effect::NumSimpleEffectTable::init
void init(const SimpleState &state)
盤面のデータを元に初期化する.
Definition numSimpleEffect.cc:11
osl::effect::NumSimpleEffectTable::doBlockAt
void doBlockAt(const SimpleState &state, Square pos, int piece_num)
posに駒を設置/削除して長い利きをブロック/延長する際の利きデータの更新.
Definition numSimpleEffect.h:286
osl::effect::NumSimpleEffectTable::doEffectBy
void doEffectBy(const SimpleState &state, Square pos, int num)
ある種類の駒が持つ利きを更新する.
osl::effect::NumSimpleEffectTable::effects
CArray< NumBitmapEffect, Square::SIZE > effects
Definition numSimpleEffect.h:33
osl::effect::NumSimpleEffectTable::effectedChanged
const PieceMask effectedChanged(Player pl) const
Definition numSimpleEffect.h:244
osl::effect::NumSimpleEffectTable::mobilityTable
mobility::MobilityTable mobilityTable
mobility
Definition numSimpleEffect.h:41
osl::effect::NumSimpleEffectTable::effected_mask
CArray< PieceMask, 2 > effected_mask
Definition numSimpleEffect.h:38
osl::effect::NumSimpleEffectTable::setChangedPieces
void setChangedPieces(NumBitmapEffect const &effect)
Definition numSimpleEffect.h:247
osl::effect::NumSimpleEffectTable::changed_effects
CArray< BoardMask, 2 > changed_effects
Definition numSimpleEffect.h:34
osl::effect::NumSimpleEffectTable::effected_changed_mask
CArray< PieceMask, 2 > effected_changed_mask
Definition numSimpleEffect.h:39
osl::effect::NumSimpleEffectTable::changed_effect_pieces
NumBitmapEffect changed_effect_pieces
set of pieces whose effect changed by previous move
Definition numSimpleEffect.h:36
osl::misc::GeneralMask::any
bool any() const
Definition mask.h:298
osl::misc::GeneralMask::takeOneBit
int takeOneBit()
non-zeroのmaskのsetされているビットをLSBから探し，その番号を返す 副作用としてmaskの対応するビットをクリアする
Definition mask.h:265
osl::mobility::MobilityTable
駒番号からMobilityContentを得る
Definition mobilityTable.h:52
effectedNumTable.h
mobilityTable.h
osl::checkmate
Definition king8Info.h:12
osl::effect
Definition effectedNumTable.h:8
osl::effect::operator<<
std::ostream & operator<<(std::ostream &, const EffectedNumTable &)
Definition effectedNumTable.cc:37
osl::effect::operator==
bool operator==(const EffectedNumTable &, const EffectedNumTable &)
Definition effectedNumTable.cc:47
osl::effect::operator!=
bool operator!=(const NumSimpleEffectTable &et1, const NumSimpleEffectTable &et2)
Definition numSimpleEffect.h:268
osl::misc::mask_t
GeneralMask< mask_int_t > mask_t
Definition mask.h:351
osl
Definition additionalEffect.h:6
osl::PPAWN
@ PPAWN
Definition basic_type.h:87
osl::EMPTY_NUM
const int EMPTY_NUM
Definition basic_type.h:778
osl::longToShort
constexpr Direction longToShort(Direction d)
Definition basic_type.h:380
osl::playerToIndex
constexpr int playerToIndex(Player player)
Definition basic_type.h:16
osl::Board_Table
const BoardTable Board_Table
Definition tables.cc:95
osl::Direction
Direction
Definition basic_type.h:310
osl::D
@ D
Definition basic_type.h:319
osl::UL
@ UL
Definition basic_type.h:313
osl::DR
@ DR
Definition basic_type.h:320
osl::U
@ U
Definition basic_type.h:314
osl::L
@ L
Definition basic_type.h:316
osl::UR
@ UR
Definition basic_type.h:315
osl::DL
@ DL
Definition basic_type.h:318
osl::Player
Player
Definition basic_type.h:8
osl::BLACK
@ BLACK
Definition basic_type.h:9
osl::__attribute__
const PtypeO PTYPEO_EDGE __attribute__((unused))
osl::PtypeO
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
Definition basic_type.h:199
numBitmapEffect.h
simpleState.h
osl::DirectionPlayerTraits
Definition directionTraits.h:242
osl::DirectionTraits
Definition directionTraits.h:225
osl::DirectionTraits::mask
static const unsigned int mask
Definition directionTraits.h:227
osl::PtypeTraits
Definition ptypeTraits.h:12