00001
00002
00003 #include "osl/checkmate/immediateCheckmateTable.h"
00004 #include "osl/boardTable.h"
00005 #include "osl/ptypeTable.h"
00006 namespace
00007 {
00008 using namespace osl;
00009 bool canCheckmate(Ptype ptype,Direction dir,unsigned int mask)
00010 {
00011
00012 if(ptype==KING || ptype==PAWN) return false;
00013
00014 if(!(Ptype_Table.getMoveMask(ptype)&
00015 (dirToMask(dir) | dirToMask(shortToLong(dir))))) return false;
00016 int dx=Board_Table.getDxForBlack(dir);
00017 int dy=Board_Table.getDyForBlack(dir);
00018 for(int l=0;l<8;l++){
00019 if((mask&(1<<l))==0) continue;
00020 Direction dir1=static_cast<Direction>(l);
00021 int dx1=Board_Table.getDxForBlack(dir1);
00022 int dy1=Board_Table.getDyForBlack(dir1);
00023 Offset32 o32(dx-dx1,dy-dy1);
00024 if(!Ptype_Table.getEffect(newPtypeO(BLACK,ptype),o32).hasEffect())
00025 return false;
00026 }
00027 return true;
00028 }
00029 }
00030
00031 osl::checkmate::ImmediateCheckmateTable::ImmediateCheckmateTable()
00032 {
00033
00034 for(int i=0;i<0x100;i++){
00035 for(int k=PTYPE_BASIC_MIN;k<=PTYPE_MAX;k++){
00036 unsigned char mask=0;
00037 Ptype ptype=static_cast<Ptype>(k);
00038 for(int j=0;j<8;j++){
00039
00040 if((i&(0x1<<j))!=0)continue;
00041 Direction dir=static_cast<Direction>(j);
00042 if(canCheckmate(ptype,dir,i))
00043 mask|=(1<<j);
00044 }
00045 ptypeDropMasks(i,ptype)=mask;
00046 }
00047 }
00048
00049 for(int i=0;i<0x10000;i++){
00050 PieceMask mask;
00051 for(int k=PTYPE_BASIC_MIN;k<=PTYPE_MAX;k++){
00052 Ptype ptype=static_cast<Ptype>(k);
00053 for(int j=0;j<8;j++){
00054
00055 if((i&(0x1<<j))==0) continue;
00056
00057 if((i&(0x100<<j))!=0)continue;
00058 Direction dir=static_cast<Direction>(j);
00059 if(canCheckmate(ptype,dir,(i>>8)&0xff)){
00060 for(int num=Ptype_Table.getIndexMin(ptype);
00061 num<Ptype_Table.getIndexLimit(ptype);num++)
00062 mask.set(num);
00063 goto nextPtype;
00064 }
00065 }
00066 nextPtype:;
00067 }
00068 dropMasks[i]=mask;
00069 }
00070
00071 for(int k=PTYPE_BASIC_MIN;k<=PTYPE_MAX;k++){
00072 Ptype ptype=static_cast<Ptype>(k);
00073 for(int j=0;j<8;j++){
00074 unsigned int mask=0;
00075 Direction dir=static_cast<Direction>(j);
00076 if(Ptype_Table.getMoveMask(ptype)&
00077 (dirToMask(dir) | dirToMask(shortToLong(dir)))){
00078 int dx=Board_Table.getDxForBlack(dir);
00079 int dy=Board_Table.getDyForBlack(dir);
00080 for(int l=0;l<8;l++){
00081 Direction dir1=static_cast<Direction>(l);
00082 int dx1=Board_Table.getDxForBlack(dir1);
00083 int dy1=Board_Table.getDyForBlack(dir1);
00084 Offset32 o32(dx-dx1,dy-dy1);
00085 if(!Ptype_Table.getEffect(newPtypeO(BLACK,ptype),o32).hasEffect()){
00086 if(!Board_Table.getShortOffsetNotKnight(o32).zero() &&
00087 !(dx==-dx1 && dy==-dy1)
00088 ){
00089 mask|=1<<l;
00090 }
00091 }
00092 }
00093 }
00094 blockingMasks(ptype,dir)=mask;
00095 }
00096 }
00097
00098 for(int k=PTYPE_PIECE_MIN;k<=PTYPE_MAX;k++){
00099 Ptype ptype=static_cast<Ptype>(k);
00100 for(int j=0;j<8;j++){
00101 unsigned int mask=0x1ff;
00102 Direction dir=static_cast<Direction>(j);
00103 if(Ptype_Table.getMoveMask(ptype)&
00104 (dirToMask(dir) | dirToMask(shortToLong(dir)))){
00105 mask=0;
00106 int dx=Board_Table.getDxForBlack(dir);
00107 int dy=Board_Table.getDyForBlack(dir);
00108 for(int l=0;l<8;l++){
00109 Direction dir1=static_cast<Direction>(l);
00110 int dx1=Board_Table.getDxForBlack(dir1);
00111 int dy1=Board_Table.getDyForBlack(dir1);
00112 Offset32 o32(dx-dx1,dy-dy1);
00113 if(dir!= dir1 &&
00114 !Ptype_Table.getEffect(newPtypeO(BLACK,ptype),o32).hasEffect()){
00115 mask|=1<<l;
00116 }
00117 }
00118 }
00119 noEffectMasks(ptype,dir)=mask;
00120 }
00121 }
00122 }
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132