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