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