00001
00002
00003
00004 #include "osl/progress/effect5x3Table.h"
00005 #include "osl/bits/centering5x3.h"
00006 #include "osl/basic_type.h"
00007 #include "osl/bits/ptypeTable.h"
00008 #include "osl/bits/boardTable.h"
00009 #include "osl/oslConfig.h"
00010
00011 #include <iostream>
00012
00013 osl::progress::Effect5x3Table osl::progress::Effect5x3_Table;
00014 static osl::SetUpRegister _initializer([](){ osl::progress::Effect5x3_Table.init(); });
00015
00016 namespace osl
00017 {
00018 namespace progress
00019 {
00020 namespace
00021 {
00028 int countShort(PtypeO ptypeO,int center_dx, int center_dy){
00029 int ret=0;
00030 for(int dy=std::max(-8,center_dy-1);
00031 dy<=std::min(8,center_dy+1);dy++)
00032 for(int dx=std::max(-8,center_dx-2);
00033 dx<=std::min(8,center_dx+2);dx++){
00034 EffectContent ec=Ptype_Table.getEffect(ptypeO,Offset32(dx,dy));
00035
00036 if(ec == EffectContent::DIRECT()){
00037 ret+=8;
00038 }
00039 }
00040 return ret;
00041 }
00048 LongEffect calcLong(Direction d,int center_dx, int center_dy){
00049 LongEffect ret;
00050 ret.minIndex=0;
00051 ret.maxIndex=0;
00052 int dy_min=std::max(-8,center_dy-1);
00053 int dy_max=std::min(8,center_dy+1);
00054 int dx_min=std::max(-8,center_dx-2);
00055 int dx_max=std::min(8,center_dx+2);
00056 int dx=Board_Table.getDxForBlack(d);
00057 int dy=Board_Table.getDyForBlack(d);
00058 assert(dx!=0 || dy!=0);
00059 int i;
00060
00061 for(i=1;i<9;i++){
00062 if(dx_min<=dx*i && dx*i <=dx_max &&
00063 dy_min<=dy*i && dy*i <=dy_max) break;
00064 }
00065 if(i==9) return ret;
00066 ret.minIndex=i;
00067 for(;i<9;i++){
00068 if(!(dx_min<=dx*i && dx*i <=dx_max &&
00069 dy_min<=dy*i && dy*i <=dy_max)) break;
00070 }
00071 ret.maxIndex=i-1;
00072 ret.offset=Offset(dx,dy);
00073 assert(!ret.offset.zero());
00074 return ret;
00075 }
00082 LongEffect4 calcLong4(PtypeO ptypeO,int center_dx, int center_dy){
00083 LongEffect4 ret;
00084 int index=0;
00085
00086 Player pl=getOwner(ptypeO);
00087 for(int i=0;i<8;i++){
00088 Direction d=static_cast<Direction>(i);
00092 Offset32 o32(Board_Table.getDxForBlack(d)*sign(pl),
00093 Board_Table.getDyForBlack(d)*sign(pl));
00094 Direction longD=Board_Table.getLongDirection<BLACK>(o32);
00095 if((Ptype_Table.getMoveMask(getPtype(ptypeO))&
00096 dirToMask(shortToLong(d)))!=0){
00097 assert(index<4);
00098 ret[index]=calcLong(longD,center_dx,center_dy);
00099 if(!ret[index].offset.zero())index++;
00100 }
00101 }
00102 return ret;
00103 }
00104 }
00105 #ifndef MINIMAL
00106 std::ostream& operator<<(std::ostream& os,LongEffect const& longEffect){
00107 return os << "(" << longEffect.offset << "," << longEffect.minIndex
00108 << "," << longEffect.maxIndex << ")";
00109 }
00110 #endif
00111 }
00112 }
00113
00114 void osl::progress::Effect5x3Table::setupOnStand()
00115 {
00116 onStand[PAWN] =StandPAWN;
00117 onStand[LANCE] =StandLANCE;
00118 onStand[KNIGHT]=StandKNIGHT;
00119 onStand[SILVER]=StandSILVER;
00120 onStand[GOLD] =StandGOLD;
00121 onStand[BISHOP]=StandBISHOP;
00122 onStand[ROOK] =StandROOK;
00123 for(int i=PTYPE_PIECE_MIN;i<=PTYPE_MAX;i++){
00124 Ptype ptype=static_cast<Ptype>(i);
00125 if(unpromote(ptype)!=ptype)
00126 onStand[ptype]=onStand[unpromote(ptype)];
00127 }
00128 }
00129
00130
00131 void osl::progress::Effect5x3Table::setupShortEffect()
00132 {
00133 Player pl=BLACK;
00134 for(int i=0;i<2;i++,pl=alt(pl)){
00135 for(int j=PTYPE_PIECE_MIN;j<=PTYPE_MAX;j++){
00136 PtypeO ptypeO=newPtypeO(pl,static_cast<Ptype>(j));
00137 for(int dy= -8;dy<=8;dy++)
00138 for(int dx= -8;dx<=8;dx++){
00139 Offset32 o32(dx,dy);
00140 shortEffect[ptypeOIndex(ptypeO)][o32.index()]=
00141 countShort(ptypeO,dx,dy);
00142 }
00143 }
00144 }
00145 }
00146 void osl::progress::Effect5x3Table::setupBlockEffect()
00147 {
00148 Player pl=BLACK;
00149 for(int i=0;i<2;i++,pl=alt(pl)){
00150 for(int j=0;j<8;j++){
00151 Direction d=static_cast<Direction>(j);
00152 for(int dy= -8;dy<=8;dy++)
00153 for(int dx= -8;dx<=8;dx++){
00154 Offset32 o32(dx,dy);
00155 blockEffect[j][o32.index()]=
00156 calcLong(d,dx,dy);
00157 }
00158 }
00159 }
00160 }
00161 void osl::progress::Effect5x3Table::setupLongEffect()
00162 {
00163 Player pl=BLACK;
00164 for(int i=0;i<2;i++,pl=alt(pl)){
00165 for(int j=PTYPE_PIECE_MIN;j<=PTYPE_MAX;j++){
00166 PtypeO ptypeO=newPtypeO(pl,static_cast<Ptype>(j));
00167 for(int dy= -8;dy<=8;dy++)
00168 for(int dx= -8;dx<=8;dx++){
00169 Offset32 o32(dx,dy);
00170 longEffect[ptypeOIndex(ptypeO)][o32.index()]=
00171 calcLong4(ptypeO,dx,dy);
00172 }
00173 }
00174 }
00175 }
00176
00177 void osl::progress::Effect5x3Table::setupAttackEffect()
00178 {
00179
00180
00181 for(int x=1;x<=9;x++)
00182 for(int y=1;y<=9;y++){
00183 const Square king(x,y);
00184 const Square center = Centering5x3::adjustCenter(king);
00185 for(int dx=0;dx<5;dx++){
00186 for(int dy=0;dy<3;dy++){
00187 const Square p(center.x()+dx-2,center.y()+dy-1);
00188 int val=16-std::abs(p.x()-king.x());
00189 attackEffect[BLACK][king.index()][dx*3+dy]=val;
00190 }
00191 }
00192 }
00193 for(int x=1;x<=9;x++)
00194 for(int y=1;y<=9;y++){
00195 const Square king(x,y);
00196 const Square r_king=king.rotate180();
00197 for(int dx=0;dx<5;dx++){
00198 for(int dy=0;dy<3;dy++){
00199 int r_dx=4-dx,r_dy=2-dy;
00200 attackEffect[WHITE][king.index()][dx*3+dy]=
00201 attackEffect[BLACK][r_king.index()][r_dx*3+r_dy];
00202 }
00203 }
00204 }
00205 }
00206 void osl::progress::Effect5x3Table::setupDefenseEffect()
00207 {
00208
00209
00210 for(int x=1;x<=9;x++)
00211 for(int y=1;y<=9;y++){
00212 const Square king(x,y);
00213 const Square center = Centering5x3::adjustCenter(king);
00214 for(int dx=0;dx<5;dx++){
00215 for(int dy=0;dy<3;dy++){
00216 const Square p(center.x()+dx-2,center.y()+dy-1);
00217 int val=16-std::abs(p.x()-king.x());
00218 defenseEffect[WHITE][king.index()][dx*3+dy]=val;
00219 }
00220 }
00221 }
00222 for(int x=1;x<=9;x++)
00223 for(int y=1;y<=9;y++){
00224 const Square king(x,y);
00225 const Square r_king=king.rotate180();
00226 for(int dx=0;dx<5;dx++){
00227 for(int dy=0;dy<3;dy++){
00228 int r_dx=4-dx,r_dy=2-dy;
00229 defenseEffect[BLACK][king.index()][dx*3+dy]=
00230 defenseEffect[WHITE][r_king.index()][r_dx*3+r_dy];
00231 }
00232 }
00233 }
00234 }
00235
00236 void osl::progress::Effect5x3Table::init()
00237 {
00238 setupOnStand();
00239 setupShortEffect();
00240 setupBlockEffect();
00241 setupLongEffect();
00242 setupAttackEffect();
00243 setupDefenseEffect();
00244 }
00245
00246
00247
00248
00249
00250