ptypeTable.cc
Go to the documentation of this file.
/* ptypeTable.cc
*/
#include "osl/bits/ptypeTable.h"
#include "osl/bits/boardTable.h"
osl::PtypeTable::PtypeTable()
{
init();
{
// guard
assert(&effect(newPtypeO(WHITE,ROOK), Offset32(2,8))
== &getEffect(newPtypeO(WHITE,ROOK), Offset32(2,8)));
assert(getEffect(newPtypeO(BLACK,PPAWN),
Offset32(Square(7,1),Square(8,1)))
== EffectContent::DIRECT());
}
}
template<osl::Ptype T>
void osl::PtypeTable::initPtypeSub(Int2Type<true>)
{
initPtypeSub<T>(Int2Type<false>());
numMaskLows[static_cast<int>(T)]=mask_t::makeDirect(PtypeFuns<T>::indexMask);
numIndices[static_cast<int>(T)]=PtypeFuns<T>::indexNum;
if(canPromote(T)){
numMaskLows[static_cast<int>(promote(T))]=mask_t::makeDirect(PtypeFuns<T>::indexMask);
numIndices[static_cast<int>(promote(T))]=PtypeFuns<T>::indexNum;
}
canDropLimit[0][static_cast<int>(T)]=PtypeTraits<T>::dropBlackFromY;
canDropLimit[1][static_cast<int>(T)]=Square::reverseY(PtypeTraits<T>::dropBlackFromY);
indexMins[static_cast<int>(T)]=PtypeTraits<T>::indexMin;
indexLimits[static_cast<int>(T)]=PtypeTraits<T>::indexLimit;
}
template<osl::Ptype T>
void osl::PtypeTable::initPtypeSub(Int2Type<false> /*is_basic*/)
{
names[static_cast<int>(T)]=PtypeTraits<T>::name();
csaNames[static_cast<int>(T)]=PtypeTraits<T>::csaName();
moveMasks[static_cast<int>(T)]=PtypeTraits<T>::moveMask;
betterToPromote[static_cast<int>(T)]=PtypeTraits<T>::betterToPromote;
}
template<osl::Ptype T>
void osl::PtypeTable::initPtype()
{
initPtypeSub<T>(Int2Type<PtypeTraits<T>::isBasic>());
}
void osl::PtypeTable::init()
{
numMaskLows.fill();
numIndices.fill();
initPtype<PTYPE_EMPTY>();
initPtype<PTYPE_EDGE>();
initPtype<PPAWN>();
initPtype<PLANCE>();
initPtype<PKNIGHT>();
initPtype<PSILVER>();
initPtype<PBISHOP>();
initPtype<PROOK>();
initPtype<GOLD>();
initPtype<KING>();
initPtype<PAWN>();
initPtype<LANCE>();
initPtype<KNIGHT>();
initPtype<SILVER>();
initPtype<BISHOP>();
initPtype<ROOK>();
effectTable.fill();
effectTableNotLongU.fill();
shortMoveMask.fill();
static_assert(sizeof(EffectContent) == 4, "size");
assert(&effect(newPtypeO(WHITE,ROOK), Offset32(2,8))
== &getEffect(newPtypeO(WHITE,ROOK), Offset32(2,8)));
assert(! getEffect(newPtypeO(BLACK,ROOK), Offset32(-1,8)).hasEffect());
for(int ptype=PTYPE_MIN;ptype<=PTYPE_MAX;ptype++){
for(int j=DIRECTION_MIN;j<=DIRECTION_MAX;j++){
Direction dir=static_cast<Direction>(j);
if((moveMasks[ptype]&(1<<dir))!=0){
int dx=Board_Table.getDxForBlack(dir);
int dy=Board_Table.getDyForBlack(dir);
Offset32 offset32=Offset32(dx,dy);
Offset offset=newOffset(dx,dy);
if(isLong(dir)){
shortMoveMask[0][dir-10]|=1<<(ptype-PTYPEO_MIN);
shortMoveMask[1][dir-10]|=1<<(ptype-16-PTYPEO_MIN);
effectTable[ptype-PTYPEO_MIN][offset32.index()]=EffectContent::DIRECT(offset);
effectTable[ptype-16-PTYPEO_MIN][(-offset32).index()]=EffectContent::DIRECT(-offset);
for(int i=2;i<9;i++){
offset32=Offset32(dx*i,dy*i);
effectTable[ptype-PTYPEO_MIN][offset32.index()]=EffectContent(offset);
effectTable[ptype-16-PTYPEO_MIN][(-offset32).index()]=EffectContent(-offset);
if(static_cast<int>(dir)!=LONG_U){
effectTableNotLongU[ptype-PTYPEO_MIN][offset32.index()]=effectTable[ptype-PTYPEO_MIN][offset32.index()];
effectTableNotLongU[ptype-16-PTYPEO_MIN][(-offset32).index()]=effectTable[ptype-16-PTYPEO_MIN][(-offset32).index()];
}
}
}
else{
shortMoveMask[0][dir]|=1<<(ptype-PTYPEO_MIN);
shortMoveMask[1][dir]|=1<<(ptype-16-PTYPEO_MIN);
effectTable[ptype-PTYPEO_MIN][offset32.index()]=EffectContent::DIRECT();
effectTable[ptype-16-PTYPEO_MIN][(-offset32).index()]=EffectContent::DIRECT();
assert(! getEffect(newPtypeO(BLACK,ROOK),Offset32(-1,8)).hasEffect());
}
}
}
}
}
/* ------------------------------------------------------------------------- */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
boardTable.h
osl::EffectContent
Definition effectContent.h:11
osl::EffectContent::DIRECT
static const EffectContent DIRECT()
Definition effectContent.h:24
osl::Offset32Base::index
unsigned int index() const
Definition offset32.h:40
osl::Offset
座標の差分
Definition basic_type.h:430
osl::PtypeTable::numMaskLows
CArray< mask_t, PTYPE_SIZE > numMaskLows
Definition ptypeTable.h:18
osl::PtypeTable::effectTableNotLongU
CArray2d< EffectContent, PTYPEO_SIZE, Offset32::SIZE > effectTableNotLongU
Definition ptypeTable.h:30
osl::PtypeTable::init
void init()
Definition ptypeTable.cc:53
osl::PtypeTable::moveMasks
CArray< int, PTYPE_SIZE > moveMasks
Definition ptypeTable.h:23
osl::PtypeTable::initPtypeSub
void initPtypeSub(Int2Type< false > isBasic)
Definition ptypeTable.cc:39
osl::PtypeTable::numIndices
CArray< int, PTYPE_SIZE > numIndices
Definition ptypeTable.h:19
osl::PtypeTable::getEffect
const EffectContent getEffect(PtypeO ptypeo, Square from, Square to) const
fromにいるptypeoがtoに利きを持つか?
Definition ptypeTable.h:112
osl::PtypeTable::canDropLimit
CArray2d< int, 2, PTYPE_SIZE > canDropLimit
Definition ptypeTable.h:27
osl::PtypeTable::effect
EffectContent & effect(PtypeO ptypeo, Offset32 offset32)
Definition ptypeTable.h:123
osl::PtypeTable::PtypeTable
PtypeTable()
Definition ptypeTable.cc:6
osl::PtypeTable::names
CArray< const char *, PTYPE_SIZE > names
Definition ptypeTable.h:20
osl::PtypeTable::betterToPromote
CArray< bool, PTYPE_SIZE > betterToPromote
Definition ptypeTable.h:22
osl::PtypeTable::indexMins
CArray< int, PTYPE_SIZE > indexMins
Definition ptypeTable.h:24
osl::PtypeTable::effectTable
CArray2d< EffectContent, PTYPEO_SIZE, Offset32::SIZE > effectTable
Definition ptypeTable.h:29
osl::PtypeTable::shortMoveMask
CArray2d< unsigned int, 2, SHORT_DIRECTION_SIZE > shortMoveMask
Definition ptypeTable.h:31
osl::PtypeTable::csaNames
CArray< const char *, PTYPE_SIZE > csaNames
Definition ptypeTable.h:21
osl::PtypeTable::initPtype
void initPtype()
Definition ptypeTable.cc:48
osl::PtypeTable::indexLimits
CArray< int, PTYPE_SIZE > indexLimits
Definition ptypeTable.h:25
osl::Square
Definition basic_type.h:532
osl::Square::reverseY
static int reverseY(int y)
Definition basic_type.h:652
osl::misc::GeneralMask< mask_int_t >::makeDirect
static const GeneralMask makeDirect(mask_int_t value)
Definition mask.h:219
osl::PTYPE_MAX
@ PTYPE_MAX
Definition basic_type.h:105
osl::ROOK
@ ROOK
Definition basic_type.h:100
osl::PPAWN
@ PPAWN
Definition basic_type.h:87
osl::PTYPE_MIN
@ PTYPE_MIN
Definition basic_type.h:102
osl::canPromote
bool canPromote(Ptype ptype)
ptypeがpromote可能な型かどうかのチェック promote済みの場合はfalseを返す
Definition basic_type.h:147
osl::Board_Table
const BoardTable Board_Table
Definition tables.cc:95
osl::Direction
Direction
Definition basic_type.h:310
osl::DIRECTION_MAX
@ DIRECTION_MAX
Definition basic_type.h:337
osl::LONG_U
@ LONG_U
Definition basic_type.h:326
osl::DIRECTION_MIN
@ DIRECTION_MIN
Definition basic_type.h:334
osl::Offset32
Offset32Base< 8, 9 > Offset32
Definition offset32.h:63
osl::WHITE
@ WHITE
Definition basic_type.h:10
osl::BLACK
@ BLACK
Definition basic_type.h:9
osl::newOffset
Offset newOffset(int dx, int dy)
@obsolete
Definition basic_type.h:508
osl::PTYPEO_MIN
@ PTYPEO_MIN
Definition basic_type.h:200
osl::isLong
constexpr bool isLong(Direction d)
Definition basic_type.h:350
osl::newPtypeO
PtypeO newPtypeO(Player player, Ptype ptype)
Definition basic_type.h:211
osl::promote
Ptype promote(Ptype ptype)
promote可能なptypeに対して，promote後の型を返す promote不可のptypeを与えてはいけない．
Definition basic_type.h:173
ptypeTable.h
osl::PtypeFuns
Definition ptypeTraits.h:311
osl::PtypeFuns::indexMask
static const uint64_t indexMask
Definition ptypeTraits.h:318
osl::PtypeTraits
Definition ptypeTraits.h:12
osl::misc::Int2Type
Definition basic_type.h:69