説明を見る。00001
00002
00003 #include "osl/bits/ptypeTable.h"
00004 #include "osl/bits/boardTable.h"
00005
00006 osl::PtypeTable::PtypeTable()
00007 {
00008 init();
00009
00010 {
00011
00012 assert(&effect(newPtypeO(WHITE,ROOK), Offset32(2,8))
00013 == &getEffect(newPtypeO(WHITE,ROOK), Offset32(2,8)));
00014 assert(getEffect(newPtypeO(BLACK,PPAWN),
00015 Offset32(Square(7,1),Square(8,1)))
00016 == EffectContent::DIRECT());
00017 }
00018 }
00019
00020 template<osl::Ptype T>
00021 void osl::PtypeTable::initPtypeSub(Int2Type<true>)
00022 {
00023 initPtypeSub<T>(Int2Type<false>());
00024 numMaskLows[static_cast<int>(T)]=mask_t::makeDirect(PtypeFuns<T>::indexMask);
00025 numIndices[static_cast<int>(T)]=PtypeFuns<T>::indexNum;
00026 if(canPromote(T)){
00027 numMaskLows[static_cast<int>(promote(T))]=mask_t::makeDirect(PtypeFuns<T>::indexMask);
00028 numIndices[static_cast<int>(promote(T))]=PtypeFuns<T>::indexNum;
00029 }
00031 canDropLimit[0][static_cast<int>(T)]=PtypeTraits<T>::dropBlackFromY;
00033 canDropLimit[1][static_cast<int>(T)]=Square::reverseY(PtypeTraits<T>::dropBlackFromY);
00034 indexMins[static_cast<int>(T)]=PtypeTraits<T>::indexMin;
00035 indexLimits[static_cast<int>(T)]=PtypeTraits<T>::indexLimit;
00036 }
00037
00038 template<osl::Ptype T>
00039 void osl::PtypeTable::initPtypeSub(Int2Type<false> )
00040 {
00041 names[static_cast<int>(T)]=PtypeTraits<T>::name();
00042 csaNames[static_cast<int>(T)]=PtypeTraits<T>::csaName();
00043 moveMasks[static_cast<int>(T)]=PtypeTraits<T>::moveMask;
00044 betterToPromote[static_cast<int>(T)]=PtypeTraits<T>::betterToPromote;
00045 }
00046
00047 template<osl::Ptype T>
00048 void osl::PtypeTable::initPtype()
00049 {
00050 initPtypeSub<T>(Int2Type<PtypeTraits<T>::isBasic>());
00051 }
00052
00053 void osl::PtypeTable::init()
00054 {
00055 numMaskLows.fill();
00056 numIndices.fill();
00057
00058 initPtype<PTYPE_EMPTY>();
00059 initPtype<PTYPE_EDGE>();
00060 initPtype<PPAWN>();
00061 initPtype<PLANCE>();
00062 initPtype<PKNIGHT>();
00063 initPtype<PSILVER>();
00064 initPtype<PBISHOP>();
00065 initPtype<PROOK>();
00066 initPtype<GOLD>();
00067 initPtype<KING>();
00068 initPtype<PAWN>();
00069 initPtype<LANCE>();
00070 initPtype<KNIGHT>();
00071 initPtype<SILVER>();
00072 initPtype<BISHOP>();
00073 initPtype<ROOK>();
00074 effectTable.fill();
00075 effectTableNotLongU.fill();
00076 shortMoveMask.fill();
00077 static_assert(sizeof(EffectContent) == 4, "size");
00078 assert(&effect(newPtypeO(WHITE,ROOK), Offset32(2,8))
00079 == &getEffect(newPtypeO(WHITE,ROOK), Offset32(2,8)));
00080 assert(! getEffect(newPtypeO(BLACK,ROOK), Offset32(-1,8)).hasEffect());
00081
00082 for(int ptype=PTYPE_MIN;ptype<=PTYPE_MAX;ptype++){
00083 for(int j=DIRECTION_MIN;j<=DIRECTION_MAX;j++){
00084 Direction dir=static_cast<Direction>(j);
00085
00086 if((moveMasks[ptype]&(1<<dir))!=0){
00087 int dx=Board_Table.getDxForBlack(dir);
00088 int dy=Board_Table.getDyForBlack(dir);
00089 Offset32 offset32=Offset32(dx,dy);
00090 Offset offset=newOffset(dx,dy);
00091 if(isLong(dir)){
00092 shortMoveMask[0][dir-10]|=1<<(ptype-PTYPEO_MIN);
00093 shortMoveMask[1][dir-10]|=1<<(ptype-16-PTYPEO_MIN);
00094
00095 effectTable[ptype-PTYPEO_MIN][offset32.index()]=EffectContent::DIRECT(offset);
00096 effectTable[ptype-16-PTYPEO_MIN][(-offset32).index()]=EffectContent::DIRECT(-offset);
00097
00098 for(int i=2;i<9;i++){
00099 offset32=Offset32(dx*i,dy*i);
00100 effectTable[ptype-PTYPEO_MIN][offset32.index()]=EffectContent(offset);
00101 effectTable[ptype-16-PTYPEO_MIN][(-offset32).index()]=EffectContent(-offset);
00102
00103 if(static_cast<int>(dir)!=LONG_U){
00104 effectTableNotLongU[ptype-PTYPEO_MIN][offset32.index()]=effectTable[ptype-PTYPEO_MIN][offset32.index()];
00105 effectTableNotLongU[ptype-16-PTYPEO_MIN][(-offset32).index()]=effectTable[ptype-16-PTYPEO_MIN][(-offset32).index()];
00106 }
00107 }
00108 }
00109 else{
00110 shortMoveMask[0][dir]|=1<<(ptype-PTYPEO_MIN);
00111 shortMoveMask[1][dir]|=1<<(ptype-16-PTYPEO_MIN);
00112 effectTable[ptype-PTYPEO_MIN][offset32.index()]=EffectContent::DIRECT();
00113 effectTable[ptype-16-PTYPEO_MIN][(-offset32).index()]=EffectContent::DIRECT();
00114
00115 assert(! getEffect(newPtypeO(BLACK,ROOK),Offset32(-1,8)).hasEffect());
00116 }
00117 }
00118 }
00119 }
00120 }
00121
00122
00123
00124
00125
00126