00001 #include "osl/move_generator/addEffectTable.h"
00002 #include "osl/ptypeTable.h"
00003 #include "osl/boardTable.h"
00004
00005 namespace osl
00006 {
00010 static const NearMask nearMaskOf(Ptype ptype,int dx, int dy,bool isPromote){
00011 unsigned int mask=0;
00015 if (dx==0 && dy==0)
00016 return NearMask::makeDirect(mask);
00017 for (int i=0;i<=SHORT_DIRECTION_MAX;i++){
00018
00019 Direction dir=static_cast<Direction>(i);
00021 if ((Ptype_Table.getMoveMask(isPromote ? promote(ptype) : ptype)&
00022 dirToMask(dir))==0) continue;
00023
00024
00025
00026
00027 int dx1=dx-Board_Table.getDxForBlack(dir);
00028 int dy1=dy-Board_Table.getDyForBlack(dir);
00029 if (dx1<-8 || 8<dx1 || dy1<-8 || 8<dy1) continue;
00030 const Offset32 offset32(dx1,dy1);
00031 const EffectContent effect
00032 =Ptype_Table.getEffect(newPtypeO(BLACK,ptype),offset32);
00033 if (effect.hasEffect()){
00038 Direction dir1=Board_Table.getLongDirection<BLACK>(offset32);
00040 if ((Ptype_Table.getMoveMask(ptype) &(1<<dir1))==0 ||
00041 longToShort(dir1)!=dir){
00042 mask |= dirToMask(dir);
00043 }
00044 }
00045 }
00046 return NearMask::makeDirect(mask);
00047 }
00048 namespace move_generator
00049 {
00053 void AddEffectTable::setNearMaskLong(Ptype ptype,int offsetX, int offsetY){
00057 if (offsetX==0 && offsetY==0)
00058 return;
00059 Offset32 offset32ForBlack(offsetX,offsetY);
00063 const EffectContent
00064 effect=Ptype_Table.getEffect(newPtypeO(BLACK,ptype),
00065 offset32ForBlack);
00066 if (effect.hasUnblockableEffect()) return;
00067 unsigned int maskLong=0,maskPBISHOP=0,maskPROOK=0;
00068 for (int i=0;i<=SHORT_DIRECTION_MAX;i++){
00069
00070 Direction dir=static_cast<Direction>(i);
00071 Direction longDir=shortToLong(dir);
00072 if ((Ptype_Table.getMoveMask(ptype)&dirToMask(longDir))==0) continue;
00073
00074 int offsetX1=Board_Table.getDxForBlack(dir);
00075 int offsetY1=Board_Table.getDyForBlack(dir);
00076 for (size_t j=1;j<=8;j++){
00077 int x=offsetX-offsetX1*j;
00078 int y=offsetY-offsetY1*j;
00079 Offset offset2FromPos=newOffset(x-offsetX,y-offsetY);
00080 if (x<-8 || 8<x || y<-8 || 8<y) goto retry;
00081 Offset offset2=newOffset(x,y);
00082 Offset offset3=Board_Table.getShortOffset(Offset32(x,y));
00083 if (offset3.zero()) continue;
00084 Direction dir1=Board_Table.getLongDirection<BLACK>(Offset32(x,y));
00086 if (dir1==longDir ||
00087 longDir==Board_Table.getLongDirection<BLACK>(Offset32(-x,-y)))
00088 goto retry;
00089 if (isShort(dir1)) continue;
00090 if (offset2==offset3 &&
00091 (Ptype_Table.getMoveMask(ptype)&dirToMask(longToShort(dir1)))!=0){
00092 assert(ptype==PROOK || ptype==PBISHOP);
00093 if (ptype==PROOK){
00094 if (j==1)
00095 maskPROOK|=dirToMask(dir);
00096 else
00097 maskPROOK|=dirToMask(dir)<<16;
00098 offsetPROOK[offset32ForBlack.index()][i]=offset2FromPos;
00099 break;
00100 }
00101 else{
00102 if (j==1)
00103 maskPBISHOP|=dirToMask(dir);
00104 else
00105 maskPBISHOP|=dirToMask(dir)<<16;
00106 offsetPBISHOP[offset32ForBlack.index()][i]=offset2FromPos;
00107 break;
00108 }
00109 }
00110 else if ((Ptype_Table.getMoveMask(ptype)&dirToMask(dir1))!=0){
00111 if (j==1)
00112 maskLong|=dirToMask(dir);
00113 else
00114 maskLong|=dirToMask(dir)<<16;
00115 offsetLong[ptype][offset32ForBlack.index()][i]=offset2FromPos;
00116 break;
00117 }
00118 }
00119 retry:;
00120 }
00121 nearMaskLong[ptype][offset32ForBlack.index()]=NearMask::makeDirect(maskLong);
00122 if (ptype==PBISHOP)
00123 nearMaskPBISHOP[offset32ForBlack.index()]=NearMask::makeDirect(maskPBISHOP);
00124 else if (ptype==PROOK)
00125 nearMaskPROOK[offset32ForBlack.index()]=NearMask::makeDirect(maskPROOK);
00126 }
00127 AddEffectTable::AddEffectTable()
00128 {
00129 nearMaskPBISHOP.fill();
00130 offsetPBISHOP.fill();
00131 nearMaskPROOK.fill();
00132 offsetPROOK.fill();
00133 nearMask.fill();
00134 nearMaskWithPromote.fill();
00135 nearMaskLong.fill();
00136 offsetLong.fill();
00137 for (int i=PTYPE_MAX;i>=PTYPE_PIECE_MIN;i--){
00138 Ptype ptype=static_cast<Ptype>(i);
00139 for (int dx= -8;dx<=8;dx++){
00140 for (int dy= -8;dy<=8;dy++){
00141 Offset32 offset32(dx,dy);
00142 int index=offset32.index();
00143 nearMask[i][index]=nearMaskOf(ptype,dx,dy,false);
00144 if (canPromote(ptype))
00145 nearMaskWithPromote[i][index]=nearMaskOf(ptype,dx,dy,true);
00146 if (Ptype_Table.hasLongMove(ptype)){
00147 setNearMaskLong(ptype,dx,dy);
00148 }
00149 }
00150 }
00151 }
00152 }
00153 }
00154 }
00155
00156
00157
00158
00159