00001 #include "osl/eval/ml/majorPiece.h"
00002 #include "osl/mobility/rookMobility.h"
00003 #include <algorithm>
00004 using osl::MultiInt;
00005
00006 template <bool Opening, osl::Ptype MajorBasic>
00007 osl::misc::CArray<int, 18>
00008 osl::eval::ml::MajorY<Opening, MajorBasic>::table;
00009
00010 template <bool Opening, osl::Ptype MajorBasic>
00011 void osl::eval::ml::
00012 MajorY<Opening, MajorBasic>::setUp(const Weights &weights)
00013 {
00014 for (size_t i = 0; i < weights.dimension(); ++i)
00015 {
00016 table[i] = weights.value(i);
00017 }
00018 }
00019
00020
00021 template <bool Opening>
00022 int osl::eval::ml::RookPawn<Opening>::weight;
00023
00024 template <bool Opening>
00025 void osl::eval::ml::
00026 RookPawn<Opening>::setUp(const Weights &weights)
00027 {
00028 weight = weights.value(0);
00029 }
00030
00031 template <bool Opening>
00032 int osl::eval::ml::RookPawn<Opening>::eval(const NumEffectState &state)
00033 {
00034 int result = 0;
00035 for (int i = PtypeTraits<ROOK>::indexMin;
00036 i < PtypeTraits<ROOK>::indexLimit;
00037 ++i)
00038 {
00039 const Piece piece = state.getPieceOf(i);
00040 if (piece.isOnBoard() && !piece.position().canPromote(piece.owner()) &&
00041 !state.isPawnMaskSet(piece.owner(), piece.position().x()))
00042 {
00043 if (piece.owner() == BLACK)
00044 result += weight;
00045 else
00046 result -= weight;
00047 }
00048 }
00049 return result;
00050 }
00051
00052
00053 osl::misc::CArray<MultiInt, 180> osl::eval::ml::RookPawnY::table;
00054 osl::misc::CArray<MultiInt, 1620> osl::eval::ml::
00055 RookPawnY::y_attack_table;
00056 osl::misc::CArray<MultiInt, 1620> osl::eval::ml::
00057 RookPawnY::y_defense_table;
00058
00059 void osl::eval::ml::
00060 RookPawnYX::setUp(const Weights &weights)
00061 {
00062 for (int i = 0; i < ONE_DIM; ++i)
00063 {
00064 for (int s=0; s<NStages; ++s)
00065 {
00066 RookPawnY::y_attack_table[i][s] = weights.value(i + ONE_DIM * 2 * s);
00067 RookPawnY::y_defense_table[i][s] = weights.value(i + ONE_DIM * 2 * s + ONE_DIM);
00068 }
00069 }
00070 }
00071
00072
00073 void osl::eval::ml::
00074 RookPawnY::setUp(const Weights &weights)
00075 {
00076 for (int i = 0; i < ONE_DIM; ++i)
00077 {
00078 for (int s=0; s<NStages; ++s)
00079 table[i][s] = weights.value(i + ONE_DIM*s);
00080 }
00081 }
00082
00083 MultiInt osl::eval::ml::
00084 RookPawnY::eval(const NumEffectState &state,
00085 const CArray2d<int, 2, 9> &pawns)
00086 {
00087 MultiInt result;
00088 const CArray<Position,2> kings = {{
00089 state.getKingPosition<BLACK>(),
00090 state.getKingPosition<WHITE>(),
00091 }};
00092 for (int i = PtypeTraits<ROOK>::indexMin;
00093 i < PtypeTraits<ROOK>::indexLimit;
00094 ++i)
00095 {
00096 const Piece piece = state.getPieceOf(i);
00097 if (piece.isOnBoard())
00098 {
00099 if (piece.owner() == BLACK)
00100 {
00101 const int pawn_y =
00102 pawns[PlayerTraits<BLACK>::index][piece.position().x() - 1];
00103 result +=
00104 table[index(piece, pawn_y)] +
00105 y_attack_table[indexY(kings[WHITE], piece, pawn_y)] +
00106 y_defense_table[indexY(kings[BLACK], piece, pawn_y)];
00107 }
00108 else
00109 {
00110 int y = pawns[PlayerTraits<WHITE>::index][piece.position().x() - 1];
00111 if (y != 0)
00112 y = 10 - y;
00113 result -=
00114 table[index(piece, y)] +
00115 y_attack_table[indexY(kings[BLACK], piece, y)] +
00116 y_defense_table[indexY(kings[WHITE], piece, y)];
00117 }
00118 }
00119 }
00120 return result;
00121 }
00122
00123
00124 MultiInt osl::eval::ml::AllMajor::weight;
00125
00126 void osl::eval::ml::
00127 AllMajor::setUp(const Weights &weights,int stage)
00128 {
00129 weight[stage] = weights.value(0);
00130 }
00131
00132
00133 template <bool Opening>
00134 osl::misc::CArray<int, 32> osl::eval::ml::MajorGoldSilverAttacked<Opening>::table;
00135
00136 template <bool Opening>
00137 void osl::eval::ml::
00138 MajorGoldSilverAttacked<Opening>::setUp(const Weights &weights)
00139 {
00140 for (size_t i = 0; i < weights.dimension(); ++i)
00141 {
00142 table[i] = weights.value(i);
00143 }
00144 }
00145
00146 template <bool Opening>
00147 int osl::eval::ml::
00148 MajorGoldSilverAttacked<Opening>::index(
00149 const NumEffectState &state, Piece piece)
00150 {
00151 return piece.ptype() + (state.getTurn() == piece.owner() ? 0 : PTYPE_SIZE);
00152 }
00153
00154 template <bool Opening>
00155 template <osl::Ptype PTYPE>
00156 int osl::eval::ml::
00157 MajorGoldSilverAttacked<Opening>::evalOne(const NumEffectState &state)
00158 {
00159 int result = 0;
00160 for (int i = PtypeTraits<PTYPE>::indexMin;
00161 i < PtypeTraits<PTYPE>::indexLimit;
00162 ++i)
00163 {
00164 const Piece piece = state.getPieceOf(i);
00165 if (piece.isOnBoard() &&
00166 state.hasEffectBy(alt(piece.owner()), piece.position()))
00167 {
00168 const int weight = table[index(state, piece)];
00169 if (piece.owner() == BLACK)
00170 result += weight;
00171 else
00172 result -= weight;
00173 }
00174 }
00175 return result;
00176 }
00177
00178 template <bool Opening>
00179 int osl::eval::ml::
00180 MajorGoldSilverAttacked<Opening>::eval(const NumEffectState &state)
00181 {
00182 int result = 0;
00183 result += evalOne<ROOK>(state);
00184 result += evalOne<BISHOP>(state);
00185 result += evalOne<GOLD>(state);
00186 result += evalOne<SILVER>(state);
00187
00188 return result;
00189 }
00190
00191 osl::misc::CArray<MultiInt, 612> osl::eval::ml::RookEffectBase::attack_table;
00192 osl::misc::CArray<MultiInt, 612> osl::eval::ml::RookEffectBase::defense_table;
00193 osl::misc::CArray<MultiInt, 32> osl::eval::ml::RookEffectBase::piece_table;
00194
00195 osl::misc::CArray<MultiInt, 23104> osl::eval::ml::RookEffectBase::attack_u;
00196 osl::misc::CArray<MultiInt, 23104> osl::eval::ml::RookEffectBase::attack_d;
00197 osl::misc::CArray<MultiInt, 23104> osl::eval::ml::RookEffectBase::attack_r;
00198 osl::misc::CArray<MultiInt, 23104> osl::eval::ml::RookEffectBase::attack_l;
00199 osl::misc::CArray<MultiInt, 23104> osl::eval::ml::RookEffectBase::defense_u;
00200 osl::misc::CArray<MultiInt, 23104> osl::eval::ml::RookEffectBase::defense_d;
00201 osl::misc::CArray<MultiInt, 23104> osl::eval::ml::RookEffectBase::defense_r;
00202 osl::misc::CArray<MultiInt, 23104> osl::eval::ml::RookEffectBase::defense_l;
00203 osl::misc::CArray<MultiInt, 722> osl::eval::ml::RookEffectBase::attack_nospace;
00204 osl::misc::CArray<MultiInt, 722> osl::eval::ml::RookEffectBase::defense_nospace;
00205
00206
00207 template<osl::Player P>
00208 inline
00209 MultiInt osl::eval::ml::RookEffectBase::evalOne(
00210 const NumEffectState& state,
00211 Position rook,
00212 Position myKing,
00213 Position opKing,
00214 Position up,
00215 Position dp,
00216 Position rp,
00217 Position lp,
00218 bool isP)
00219 {
00220 MultiInt result;
00221 PtypeO uPtypeO=state.getPieceAt(up).ptypeO();
00222 PtypeO dPtypeO=state.getPieceAt(dp).ptypeO();
00223 PtypeO rPtypeO=state.getPieceAt(rp).ptypeO();
00224 PtypeO lPtypeO=state.getPieceAt(lp).ptypeO();
00225 if(P==WHITE){
00226 uPtypeO=(PtypeO)(static_cast<int>(uPtypeO)^(~15));
00227 dPtypeO=(PtypeO)(static_cast<int>(dPtypeO)^(~15));
00228 rPtypeO=(PtypeO)(static_cast<int>(rPtypeO)^(~15));
00229 lPtypeO=(PtypeO)(static_cast<int>(lPtypeO)^(~15));
00230 up=up.rotate180EdgeOK();
00231 dp=dp.rotate180EdgeOK();
00232 rp=rp.rotate180EdgeOK();
00233 lp=lp.rotate180EdgeOK();
00234 rook=rook.rotate180();
00235 myKing=myKing.rotate180();
00236 opKing=opKing.rotate180();
00237 }
00238 assert((myKing.y()-dp.y())<(myKing.y()-up.y()));
00239 assert((myKing.x()-lp.x())<(myKing.x()-rp.x()));
00240 result+=attack_u[index1(opKing,up,uPtypeO,isP)]+
00241 attack_d[index1(opKing,dp,dPtypeO,isP)]+
00242 attack_l[index1(opKing,lp,lPtypeO,isP)]+
00243 attack_r[index1(opKing,rp,rPtypeO,isP)]+
00244 defense_u[index1(myKing,up,uPtypeO,isP)]+
00245 defense_d[index1(myKing,dp,dPtypeO,isP)]+
00246 defense_l[index1(myKing,lp,lPtypeO,isP)]+
00247 defense_r[index1(myKing,rp,rPtypeO,isP)]+
00248 attack_nospace[index2(opKing,rook,isP)]+
00249 defense_nospace[index2(myKing,rook,isP)];
00250 return result;
00251 }
00252
00253 MultiInt osl::eval::ml::
00254 RookEffectBase::eval(const NumEffectState &state)
00255 {
00256 const CArray<Position,2> kings = {{
00257 state.getKingPosition(BLACK),
00258 state.getKingPosition(WHITE),
00259 }};
00260 MultiInt result;
00261 for (int i = PtypeTraits<ROOK>::indexMin; i < PtypeTraits<ROOK>::indexLimit;
00262 ++i)
00263 {
00264 const Piece p = state.getPieceOf(i);
00265 if (! p.isOnBoard()) continue;
00266 const Position pos=p.position();
00267 Position up=state.getMobility(U,i);
00268 Position dp=state.getMobility(D,i);
00269 Position lp=state.getMobility(L,i);
00270 Position rp=state.getMobility(R,i);
00271 const bool isP=p.isPromoted();
00272 if(p.owner()==BLACK)
00273 result+=evalOne<BLACK>(state,pos,kings[0],kings[1],up,dp,rp,lp,isP);
00274 else
00275 result-=evalOne<WHITE>(state,pos,kings[1],kings[0],dp,up,lp,rp,isP);
00276 }
00277 return result;
00278 }
00279
00280 void osl::eval::ml::RookEffect::setUp(const Weights &weights,int stage)
00281 {
00282 for (size_t i = 0; i < ONE_DIM; ++i)
00283 {
00284 attack_table[i][stage] = weights.value(i);
00285 defense_table[i][stage] = weights.value(i + ONE_DIM);
00286 }
00287 }
00288
00289 void osl::eval::ml::RookEffectPiece::setUp(const Weights &weights)
00290 {
00291 for (size_t i = 0; i < 32; ++i)
00292 {
00293 for (int s=0; s<NStages; ++s)
00294 RookEffectBase::piece_table[i][s] = weights.value(i + 32*s);
00295 }
00296 }
00297
00298 void osl::eval::ml::
00299 RookEffectPieceKingRelative::setUp(const Weights &weights)
00300 {
00301 CArray<MultiInt, 19584> piece_attack_table;
00302 CArray<MultiInt, 19584> piece_defense_table;
00303 for (size_t i = 0; i < ONE_DIM; ++i)
00304 {
00305 for (int s=0; s<NStages; ++s)
00306 {
00307 piece_attack_table[i][s] = weights.value(i + ONE_DIM*2*s);
00308 piece_defense_table[i][s] = weights.value(i + ONE_DIM*2*s + ONE_DIM);
00309 }
00310 }
00311 for(int isP=0;isP<2;isP++)
00312 for(int y_diff=-9;y_diff<=9;y_diff++)
00313 for(int x_diff= -9;x_diff<=9;x_diff++){
00314 int i2=index2(x_diff,y_diff,isP);
00315 if(abs(x_diff)<9 && abs(y_diff)<9){
00316 attack_nospace[i2]=
00317 -(attack_table[index(abs(x_diff),y_diff,true,isP)]+
00318 attack_table[index(abs(x_diff),y_diff,false,isP)]);
00319 defense_nospace[i2]=
00320 -(defense_table[index(abs(x_diff),y_diff,true,isP)]+
00321 defense_table[index(abs(x_diff),y_diff,false,isP)]);
00322 }
00323 for(int ptypeo= PTYPEO_MIN;ptypeo<=PTYPEO_MAX;ptypeo++){
00324 if(getPtype((PtypeO)ptypeo)==(int)PTYPE_EMPTY) continue;
00325 int i1=index1(x_diff,y_diff,(PtypeO)ptypeo,isP);
00326 int indexPieceH,indexPieceV;
00327 int table_ptypeo=ptypeo;
00328 if(getPtype((PtypeO)ptypeo)==PTYPE_EDGE) table_ptypeo=PTYPEO_EDGE;
00329 if(getPtype((PtypeO)ptypeo)==PTYPE_EDGE || abs(x_diff)==9 || abs(y_diff)==9){
00330 indexPieceH= 0+0+(PTYPEO_EDGE-PTYPEO_MIN)*17*9+4896+isP*9792;
00331 indexPieceV= 0+0+(PTYPEO_EDGE-PTYPEO_MIN)*17*9+ isP*9792;
00332 }
00333 else{
00334 indexPieceH= index0(abs(x_diff),-y_diff,(PtypeO)ptypeo,true,isP);
00335 indexPieceV= index0(abs(x_diff),-y_diff,(PtypeO)ptypeo,false,isP);
00336 }
00337 attack_u[i1]=piece_attack_table[indexPieceV]+piece_table[table_ptypeo-PTYPEO_MIN];
00338 defense_u[i1]=piece_defense_table[indexPieceV];
00339 attack_d[i1]=piece_attack_table[indexPieceV]+piece_table[table_ptypeo-PTYPEO_MIN];
00340 defense_d[i1]=piece_defense_table[indexPieceV];
00341 if(abs(x_diff)<=8){
00342 for(int y_diff_1=y_diff+1;y_diff_1<=8;y_diff_1++){
00343 int i=index(abs(x_diff),y_diff_1,false,isP);
00344 attack_u[i1]+=attack_table[i];
00345 defense_u[i1]+=defense_table[i];
00346 }
00347 for(int y_diff_1=std::max(-8,y_diff);y_diff_1<=8;y_diff_1++){
00348 int i=index(abs(x_diff),y_diff_1,false,isP);
00349 attack_d[i1]-=attack_table[i];
00350 defense_d[i1]-=defense_table[i];
00351 }
00352 }
00353 attack_l[i1]=piece_attack_table[indexPieceH]+piece_table[table_ptypeo-PTYPEO_MIN];
00354 defense_l[i1]=piece_defense_table[indexPieceH];
00355 attack_r[i1]=piece_attack_table[indexPieceH]+piece_table[table_ptypeo-PTYPEO_MIN];
00356 defense_r[i1]=piece_defense_table[indexPieceH];
00357 if(abs(y_diff)<=8){
00358 for(int x_diff_1=x_diff+1;x_diff_1<=8;x_diff_1++){
00359 int i=index(abs(x_diff_1),y_diff,true,isP);
00360 attack_r[i1]+=attack_table[i];
00361 defense_r[i1]+=defense_table[i];
00362 }
00363 for(int x_diff_1=std::max(-8,x_diff);x_diff_1<=8;x_diff_1++){
00364 int i=index(abs(x_diff_1),y_diff,true,isP);
00365 attack_l[i1]-=attack_table[i];
00366 defense_l[i1]-=defense_table[i];
00367 }
00368 }
00369 }
00370 }
00371 }
00372
00373
00374
00375 osl::misc::CArray<MultiInt, 256> osl::eval::ml::RookPromoteDefense::promote_defense_table;
00376 osl::misc::CArray<MultiInt, 144> osl::eval::ml::RookPromoteDefense::promote_defense_rook_table;
00377
00378 void osl::eval::ml::RookPromoteDefense::setUp(const Weights &weights)
00379 {
00380 for (size_t i = 0; i < ONE_DIM; ++i)
00381 {
00382 for (int s=0; s<NStages; ++s)
00383 promote_defense_table[i][s] = weights.value(i + ONE_DIM*s);
00384 }
00385 }
00386
00387 void osl::eval::ml::RookPromoteDefenseRookH::setUp(const Weights &weights)
00388 {
00389 for (size_t i = 0; i < ONE_DIM; ++i)
00390 {
00391 for (int s=0; s<NStages; ++s)
00392 RookPromoteDefense::promote_defense_rook_table[i][s] =
00393 weights.value(i + ONE_DIM*s);
00394 }
00395 }
00396
00397 MultiInt osl::eval::ml::
00398 RookPromoteDefense::eval(const NumEffectState &state)
00399 {
00400 MultiInt result;
00401 for (int i = PtypeTraits<ROOK>::indexMin;
00402 i < PtypeTraits<ROOK>::indexLimit;
00403 ++i){
00404 const Piece rook = state.getPieceOf(i);
00405 if(rook.isOnBoardNotPromoted()){
00406 if(rook.owner()==BLACK){
00407 Position rookPos=rook.position();
00408 if(rookPos.y()>=4){
00409 Position pos=state.getMobility(U,i);
00410 const Piece attacked = state.getPieceAt(pos);
00411 if (attacked.canMoveOn<BLACK>()){
00412 const NumBitmapEffect effect = state.getEffect(pos);
00413 if (effect.countEffect(WHITE) == 1){
00414 PieceMask mask = effect & state.getOnBoardMask(WHITE);
00415 const Piece effect_piece = state.getPieceOf(mask.takeOneBit());
00416 const int index = attacked.ptype() * 16 + effect_piece.ptype();
00417 result += promote_defense_table[index];
00418 if (effect_piece.ptype() == ROOK &&
00419 effect_piece.position().x() != rookPos.x())
00420 {
00421 result +=
00422 promote_defense_rook_table[
00423 attacked.ptype() * 9 +
00424 mobility::RookMobility::countHorizontalAll<BLACK>(state,
00425 rook)];
00426 }
00427 }
00428 }
00429 }
00430 }
00431 else{
00432 Position rookPos=rook.position();
00433 if(rookPos.y()<=6){
00434 Position pos=state.getMobility(D,i);
00435 const Piece attacked = state.getPieceAt(pos);
00436 if (attacked.canMoveOn<WHITE>()){
00437 const NumBitmapEffect effect = state.getEffect(pos);
00438 if (effect.countEffect(BLACK) == 1){
00439 PieceMask mask = effect & state.getOnBoardMask(BLACK);
00440 const Piece effect_piece = state.getPieceOf(mask.takeOneBit());
00441 const int index = attacked.ptype() * 16 + effect_piece.ptype();
00442 result -= promote_defense_table[index];
00443 if (effect_piece.ptype() == ROOK &&
00444 effect_piece.position().x() != rookPos.x())
00445 {
00446 result -=
00447 promote_defense_rook_table[
00448 attacked.ptype() * 9 +
00449 mobility::RookMobility::countHorizontalAll<WHITE>(state,
00450 rook)];
00451 }
00452 }
00453 }
00454 }
00455 }
00456 }
00457 }
00458 return result;
00459 }
00460
00461
00462
00463 osl::misc::CArray<MultiInt, 612> osl::eval::ml::BishopEffectBase::attack_table;
00464 osl::misc::CArray<MultiInt, 612> osl::eval::ml::BishopEffectBase::defense_table;
00465 osl::misc::CArray<MultiInt, 32> osl::eval::ml::BishopEffectBase::piece_table;
00466 osl::misc::CArray<MultiInt, 23104> osl::eval::ml::BishopEffectBase::attack_ul;
00467 osl::misc::CArray<MultiInt, 23104> osl::eval::ml::BishopEffectBase::attack_ur;
00468 osl::misc::CArray<MultiInt, 23104> osl::eval::ml::BishopEffectBase::attack_dl;
00469 osl::misc::CArray<MultiInt, 23104> osl::eval::ml::BishopEffectBase::attack_dr;
00470 osl::misc::CArray<MultiInt, 23104> osl::eval::ml::BishopEffectBase::defense_ul;
00471 osl::misc::CArray<MultiInt, 23104> osl::eval::ml::BishopEffectBase::defense_ur;
00472 osl::misc::CArray<MultiInt, 23104> osl::eval::ml::BishopEffectBase::defense_dl;
00473 osl::misc::CArray<MultiInt, 23104> osl::eval::ml::BishopEffectBase::defense_dr;
00474 osl::misc::CArray<MultiInt, 722> osl::eval::ml::BishopEffectBase::attack_nospace;
00475 osl::misc::CArray<MultiInt, 722> osl::eval::ml::BishopEffectBase::defense_nospace;
00476
00477
00478 template<osl::Player P>
00479 inline
00480 MultiInt osl::eval::ml::BishopEffectBase::evalOne(
00481 const NumEffectState& state,
00482 Position bishop,
00483 Position myKing,
00484 Position opKing,
00485 Position ulp,
00486 Position urp,
00487 Position dlp,
00488 Position drp,
00489 bool isP)
00490 {
00491 MultiInt result;
00492 PtypeO ulPtypeO=state.getPieceAt(ulp).ptypeO();
00493 PtypeO urPtypeO=state.getPieceAt(urp).ptypeO();
00494 PtypeO dlPtypeO=state.getPieceAt(dlp).ptypeO();
00495 PtypeO drPtypeO=state.getPieceAt(drp).ptypeO();
00496 if(P==WHITE){
00497 ulPtypeO=(PtypeO)(static_cast<int>(ulPtypeO)^(~15));
00498 urPtypeO=(PtypeO)(static_cast<int>(urPtypeO)^(~15));
00499 dlPtypeO=(PtypeO)(static_cast<int>(dlPtypeO)^(~15));
00500 drPtypeO=(PtypeO)(static_cast<int>(drPtypeO)^(~15));
00501 ulp=ulp.rotate180EdgeOK();
00502 urp=urp.rotate180EdgeOK();
00503 dlp=dlp.rotate180EdgeOK();
00504 drp=drp.rotate180EdgeOK();
00505 bishop=bishop.rotate180();
00506 myKing=myKing.rotate180();
00507 opKing=opKing.rotate180();
00508 }
00509 result+=attack_ul[index1(opKing,ulp,ulPtypeO,isP)]+
00510 attack_ur[index1(opKing,urp,urPtypeO,isP)]+
00511 attack_dl[index1(opKing,dlp,dlPtypeO,isP)]+
00512 attack_dr[index1(opKing,drp,drPtypeO,isP)]+
00513 defense_ul[index1(myKing,ulp,ulPtypeO,isP)]+
00514 defense_ur[index1(myKing,urp,urPtypeO,isP)]+
00515 defense_dl[index1(myKing,dlp,dlPtypeO,isP)]+
00516 defense_dr[index1(myKing,drp,drPtypeO,isP)]+
00517 attack_nospace[index2(opKing,bishop,isP)]+
00518 defense_nospace[index2(myKing,bishop,isP)];
00519 return result;
00520 }
00521
00522 MultiInt osl::eval::ml::
00523 BishopEffectBase::eval(const NumEffectState &state)
00524 {
00525 const CArray<Position,2> kings = {{
00526 state.getKingPosition(BLACK),
00527 state.getKingPosition(WHITE),
00528 }};
00529
00530 MultiInt result;
00531 for (int i = PtypeTraits<BISHOP>::indexMin; i < PtypeTraits<BISHOP>::indexLimit;
00532 ++i)
00533 {
00534 const Piece p = state.getPieceOf(i);
00535 if (! p.isOnBoard()) continue;
00536 const Position pos=p.position();
00537 Position ulp=state.getMobility(UL,i);
00538 Position urp=state.getMobility(UR,i);
00539 Position dlp=state.getMobility(DL,i);
00540 Position drp=state.getMobility(DR,i);
00541 const bool isP=p.isPromoted();
00542 if(p.owner()==BLACK)
00543 result+=evalOne<BLACK>(state,pos,kings[0],kings[1],ulp,urp,dlp,drp,isP);
00544 else
00545 result-=evalOne<WHITE>(state,pos,kings[1],kings[0],drp,dlp,urp,ulp,isP);
00546 }
00547 return result;
00548 }
00549
00550 void osl::eval::ml::BishopEffect::setUp(const Weights &weights,int stage)
00551 {
00552 for (size_t i = 0; i < ONE_DIM; ++i)
00553 {
00554 attack_table[i][stage] = weights.value(i);
00555 defense_table[i][stage] = weights.value(i + ONE_DIM);
00556 }
00557 }
00558
00559 void osl::eval::ml::BishopEffectPiece::setUp(const Weights &weights)
00560 {
00561 for (size_t i = 0; i < 32; ++i)
00562 {
00563 for (int s=0; s<NStages; ++s)
00564 BishopEffectBase::piece_table[i][s] = weights.value(i + 32*s);
00565 }
00566 }
00567
00568
00569 void osl::eval::ml::
00570 BishopEffectPieceKingRelative::setUp(const Weights &weights)
00571 {
00572 CArray<MultiInt, 19584> piece_attack_table;
00573 CArray<MultiInt, 19584> piece_defense_table;
00574 for (size_t i = 0; i < ONE_DIM; ++i)
00575 {
00576 for (int s=0; s<NStages; ++s)
00577 {
00578 piece_attack_table[i][s] = weights.value(i + ONE_DIM * 2 * s);
00579 piece_defense_table[i][s] = weights.value(i + ONE_DIM * 2 * s + ONE_DIM);
00580 }
00581 }
00582 for(int isP=0;isP<2;isP++)
00583 for(int y_diff=-9;y_diff<=9;y_diff++)
00584 for(int x_diff= -9;x_diff<=9;x_diff++){
00585 int i2=index2(x_diff,y_diff,isP);
00586 if(abs(x_diff)<9 && abs(y_diff)<9){
00587 attack_nospace[i2]=
00588 -(attack_table[index(x_diff,y_diff,true,isP)]+
00589 attack_table[index(x_diff,y_diff,false,isP)]);
00590 defense_nospace[i2]=
00591 -(defense_table[index(x_diff,y_diff,true,isP)]+
00592 defense_table[index(x_diff,y_diff,false,isP)]);
00593 }
00594 for(int ptypeo= PTYPEO_MIN;ptypeo<=PTYPEO_MAX;ptypeo++){
00595 if(getPtype((PtypeO)ptypeo)==(int)PTYPE_EMPTY) continue;
00596 int i1=index1(x_diff,y_diff,(PtypeO)ptypeo,isP);
00597 int indexPieceUR,indexPieceUL;
00598 int table_ptypeo=ptypeo;
00599 if(getPtype((PtypeO)ptypeo)==PTYPE_EDGE) table_ptypeo=PTYPEO_EDGE;
00600 if(getPtype((PtypeO)ptypeo)==PTYPE_EDGE || abs(x_diff)==9 || abs(y_diff)==9){
00601 indexPieceUR= 0+0+(PTYPEO_EDGE-PTYPEO_MIN)*17*9+4896+isP*9792;
00602 indexPieceUL= 0+0+(PTYPEO_EDGE-PTYPEO_MIN)*17*9+ isP*9792;
00603 }
00604 else{
00605 indexPieceUR= index0(x_diff,y_diff,(PtypeO)ptypeo,true,isP);
00606 indexPieceUL= index0(x_diff,y_diff,(PtypeO)ptypeo,false,isP);
00607 }
00608 attack_ul[i1]=piece_attack_table[indexPieceUL]+piece_table[table_ptypeo-PTYPEO_MIN];
00609 defense_ul[i1]=piece_defense_table[indexPieceUL];
00610 attack_dr[i1]=piece_attack_table[indexPieceUL]+piece_table[table_ptypeo-PTYPEO_MIN];
00611 defense_dr[i1]=piece_defense_table[indexPieceUL];
00612 {
00613 int y_diff_1=y_diff+1, x_diff_1=x_diff-1;
00614 for(;y_diff_1<=8 && x_diff_1>=-8;y_diff_1++,x_diff_1--){
00615 if(std::abs(x_diff_1)<=8 && std::abs(y_diff_1)<=8){
00616 int i=index(x_diff_1,y_diff_1,false,isP);
00617 attack_ul[i1]+=attack_table[i];
00618 defense_ul[i1]+=defense_table[i];
00619 }
00620 }
00621 }
00622 {
00623 int y_diff_1=y_diff, x_diff_1=x_diff;
00624 for(;y_diff_1<=8 && x_diff_1>=-8;y_diff_1++,x_diff_1--){
00625 if(std::abs(x_diff_1)<=8 && std::abs(y_diff_1)<=8){
00626 int i=index(x_diff_1,y_diff_1,false,isP);
00627 attack_dr[i1]-=attack_table[i];
00628 defense_dr[i1]-=defense_table[i];
00629 }
00630 }
00631 }
00632 attack_ur[i1]=piece_attack_table[indexPieceUR]+piece_table[table_ptypeo-PTYPEO_MIN];
00633 defense_ur[i1]=piece_defense_table[indexPieceUR];
00634 attack_dl[i1]=piece_attack_table[indexPieceUR]+piece_table[table_ptypeo-PTYPEO_MIN];
00635 defense_dl[i1]=piece_defense_table[indexPieceUR];
00636 {
00637 int y_diff_1=y_diff+1, x_diff_1=x_diff+1;
00638 for(;y_diff_1<=8 && x_diff_1<=8;y_diff_1++,x_diff_1++){
00639 if(std::abs(x_diff_1)<=8 && std::abs(y_diff_1)<=8){
00640 int i=index(x_diff_1,y_diff_1,true,isP);
00641 attack_ur[i1]+=attack_table[i];
00642 defense_ur[i1]+=defense_table[i];
00643 }
00644 }
00645 }
00646 {
00647 int y_diff_1=y_diff, x_diff_1=x_diff;
00648 for(;y_diff_1<=8 && x_diff_1<=8;y_diff_1++,x_diff_1++){
00649 if(std::abs(x_diff_1)<=8 && std::abs(y_diff_1)<=8){
00650 int i=index(x_diff_1,y_diff_1,true,isP);
00651 attack_dl[i1]-=attack_table[i];
00652 defense_dl[i1]-=defense_table[i];
00653 }
00654 }
00655 }
00656 }
00657 }
00658 }
00659
00660 osl::misc::CArray<MultiInt, 32> osl::eval::ml::BishopHead::table;
00661 osl::misc::CArray<MultiInt, 4896> osl::eval::ml::BishopHead::king_table;
00662 osl::misc::CArray<MultiInt, 160> osl::eval::ml::BishopHead::x_table;
00663
00664 void osl::eval::ml::BishopHead::setUp(const Weights &weights)
00665 {
00666 for (size_t i = 0; i < ONE_DIM; ++i)
00667 {
00668 for (int s=0; s<NStages; ++s)
00669 table[i][s] = weights.value(i + ONE_DIM*s);
00670 }
00671 }
00672
00673 void osl::eval::ml::
00674 BishopHeadKingRelative::setUp(const Weights &weights)
00675 {
00676 for (size_t i = 0; i < ONE_DIM; ++i)
00677 {
00678 for (int s=0; s<NStages; ++s)
00679 BishopHead::king_table[i][s] = weights.value(i + ONE_DIM*s);
00680 }
00681 for(int x_diff=0;x_diff<=8;x_diff++)
00682 for(int y_diff=-8;y_diff<=8;y_diff++){
00683 for(int i=0;i<32;i++)
00684 BishopHead::king_table[(i*9+x_diff)*17+y_diff+8]+=BishopHead::table[i];
00685 }
00686 const PtypeO PTYPEO_EMPTY_R=newPtypeO(WHITE,PTYPE_EMPTY);
00687 const PtypeO PTYPEO_EDGE_R=newPtypeO(BLACK,PTYPE_EDGE);
00688 for(int x_diff=0;x_diff<=8;x_diff++)
00689 for(int y_diff=-8;y_diff<=8;y_diff++){
00690 BishopHead::king_table[(ptypeOIndex(PTYPEO_EMPTY_R)*9+x_diff)*17+y_diff+8]=
00691 BishopHead::king_table[(ptypeOIndex(PTYPEO_EMPTY)*9+x_diff)*17+y_diff+8];
00692 BishopHead::king_table[(ptypeOIndex(PTYPEO_EDGE_R)*9+x_diff)*17+y_diff+8]=
00693 BishopHead::king_table[(ptypeOIndex(PTYPEO_EDGE)*9+x_diff)*17+y_diff+8];
00694 }
00695 }
00696
00697 void osl::eval::ml::BishopHeadX::setUp(const Weights &weights)
00698 {
00699 for (size_t i = 0; i < ONE_DIM; ++i)
00700 {
00701 for (int s=0; s<NStages; ++s)
00702 BishopHead::x_table[i][s] = weights.value(i + ONE_DIM*s);
00703 }
00704 }
00705
00706 MultiInt osl::eval::ml::
00707 BishopHead::eval(const NumEffectState &state)
00708 {
00709 MultiInt result;
00710 for (int i = PtypeTraits<BISHOP>::indexMin;
00711 i < PtypeTraits<BISHOP>::indexLimit;
00712 ++i){
00713 const Piece p = state.getPieceOf(i);
00714 if (p.isOnBoardNotPromoted()){
00715 const Position pos=p.position();
00716 if (p.owner() == BLACK){
00717 if(pos.y()>=2){
00718 const Position up = pos+DirectionPlayerTraits<U,BLACK>::offset();
00719 if (!state.hasEffectBy(BLACK, up)){
00720 const Position king = state.getKingPosition(BLACK);
00721 const PtypeO ptypeo = state.getPieceAt(up).ptypeO();
00722 const int index_k = indexK(BLACK, ptypeo,
00723 std::abs(pos.x() - king.x()),
00724 pos.y() - king.y());
00725 result += king_table[index_k];
00726 result += x_table[indexX<BLACK>(ptypeo, pos.x())];
00727 }
00728 }
00729 }
00730 else if(pos.y()<=8) {
00731 const Position up = pos+DirectionPlayerTraits<U,WHITE>::offset();
00732 if (!state.hasEffectBy(WHITE, up)){
00733 const Position king = state.getKingPosition(WHITE);
00734 const PtypeO ptypeo = state.getPieceAt(up).ptypeO();
00735 const int index_k = indexK(WHITE, ptypeo,
00736 std::abs(pos.x() - king.x()),
00737 pos.y() - king.y());
00738 result -= king_table[index_k];
00739 result -= x_table[indexX<WHITE>(ptypeo, pos.x())];
00740 }
00741 }
00742 }
00743 }
00744 return result;
00745 }
00746
00747
00748 osl::misc::CArray<MultiInt, 374544> osl::eval::ml::KingRookBishop::table;
00749
00750 void osl::eval::ml::KingRookBishop::setUp(const Weights &weights)
00751 {
00752 for (size_t i = 0; i < ONE_DIM; ++i)
00753 {
00754 for (int s=0; s<NStages; ++s)
00755 table[i][s] = weights.value(i + ONE_DIM*s);
00756 }
00757 }
00758
00759 template<osl::Player P>
00760 MultiInt osl::eval::ml::
00761 KingRookBishop::evalOne(const NumEffectState &state)
00762 {
00763 const Position king=state.getKingPosition(P);
00764 MultiInt result;
00765 for (int i = PtypeTraits<ROOK>::indexMin;
00766 i < PtypeTraits<ROOK>::indexLimit;
00767 ++i)
00768 {
00769 const Piece rook = state.getPieceOf(i);
00770 if (!rook.isOnBoard())
00771 {
00772 continue;
00773 }
00774 for (int j = PtypeTraits<BISHOP>::indexMin;
00775 j < PtypeTraits<BISHOP>::indexLimit;
00776 ++j)
00777 {
00778 const Piece bishop = state.getPieceOf(j);
00779 if (!bishop.isOnBoard())
00780 {
00781 continue;
00782 }
00783 result += table[index<P>(king, rook, bishop)];
00784 }
00785 }
00786 return result;
00787 }
00788
00789 MultiInt osl::eval::ml::
00790 KingRookBishop::eval(const NumEffectState &state)
00791 {
00792 return evalOne<BLACK>(state)-evalOne<WHITE>(state);
00793 }
00794
00795
00796 osl::misc::CArray<MultiInt, 9> osl::eval::ml::NumPiecesBetweenBishopAndKing::self_table;
00797 osl::misc::CArray<MultiInt, 9> osl::eval::ml::NumPiecesBetweenBishopAndKing::opp_table;
00798 osl::misc::CArray<MultiInt, 9> osl::eval::ml::NumPiecesBetweenBishopAndKing::all_table;
00799
00800 void osl::eval::ml::
00801 NumPiecesBetweenBishopAndKingSelf::setUp(const Weights &weights)
00802 {
00803 for (size_t i = 0; i < ONE_DIM; ++i)
00804 {
00805 for (int s=0; s<NStages; ++s)
00806 NumPiecesBetweenBishopAndKing::self_table[i][s] =
00807 weights.value(i + ONE_DIM*s);
00808 }
00809 }
00810
00811 void osl::eval::ml::
00812 NumPiecesBetweenBishopAndKingOpp::setUp(const Weights &weights)
00813 {
00814 for (size_t i = 0; i < ONE_DIM; ++i)
00815 {
00816 for (int s=0; s<NStages; ++s)
00817 NumPiecesBetweenBishopAndKing::opp_table[i][s] =
00818 weights.value(i + ONE_DIM*s);
00819 }
00820 }
00821
00822 void osl::eval::ml::
00823 NumPiecesBetweenBishopAndKingAll::setUp(const Weights &weights)
00824 {
00825 for (size_t i = 0; i < ONE_DIM; ++i)
00826 {
00827 for (int s=0; s<NStages; ++s)
00828 NumPiecesBetweenBishopAndKing::all_table[i][s] =
00829 weights.value(i + ONE_DIM*s);
00830 }
00831 }
00832
00833 osl::MultiInt osl::eval::ml::
00834 NumPiecesBetweenBishopAndKing::eval(const NumEffectState &state)
00835 {
00836 MultiInt result;
00837 for (int i = PtypeTraits<BISHOP>::indexMin;
00838 i < PtypeTraits<BISHOP>::indexLimit;
00839 ++i)
00840 {
00841 const Piece bishop = state.getPieceOf(i);
00842 if (!bishop.isOnBoard())
00843 {
00844 continue;
00845 }
00846 int self, opp, all;
00847 countBetween(state,
00848 state.getKingPosition(alt(bishop.owner())),
00849 bishop, self, opp, all);
00850 if (bishop.owner() == BLACK)
00851 {
00852 result += (self_table[self] + opp_table[opp] + all_table[all]);
00853 }
00854 else
00855 {
00856 result -= (self_table[self] + opp_table[opp] + all_table[all]);
00857 }
00858 }
00859 return result;
00860 }
00861
00862 void osl::eval::ml::
00863 NumPiecesBetweenBishopAndKing::countBetween(
00864 const NumEffectState &state, Position king, Piece bishop,
00865 int &self_count, int &opp_count, int &total_count)
00866 {
00867 assert(bishop.isOnBoard());
00868 if ((king.x() + king.y() != bishop.position().x() + bishop.position().y()) &&
00869 (king.x() - king.y() != bishop.position().x() - bishop.position().y()))
00870 {
00871 self_count = opp_count = total_count = 8;
00872 return;
00873 }
00874 Direction dir;
00875 assert(king.x() != bishop.position().x());
00876 assert(king.y() != bishop.position().y());
00877 if (king.x() < bishop.position().x())
00878 {
00879 if (king.y() < bishop.position().y())
00880 {
00881 dir = UR;
00882 }
00883 else
00884 {
00885 dir = DR;
00886 }
00887 }
00888 else
00889 {
00890 if (king.y() < bishop.position().y())
00891 {
00892 dir = UL;
00893 }
00894 else
00895 {
00896 dir = DL;
00897 }
00898 }
00899 const Player player = bishop.owner();
00900 const Direction move_dir = (player == BLACK ? dir : inverse(dir));
00901 self_count = opp_count = total_count = 0;
00902 for (Position pos = state.getMobility(dir, bishop.number());
00903 pos != king; pos = Board_Table.nextPosition(player, pos, move_dir))
00904 {
00905 assert(pos.isOnBoard());
00906 const Piece piece = state.getPieceAt(pos);
00907 if (!piece.isEmpty())
00908 {
00909 ++total_count;
00910 if (piece.owner() == player)
00911 ++self_count;
00912 else
00913 ++opp_count;
00914 }
00915 }
00916 }
00917
00918
00919 osl::misc::CArray<MultiInt, 64>
00920 osl::eval::ml::BishopBishopPiece::table;
00921
00922 void osl::eval::ml::
00923 BishopBishopPiece::setUp(const Weights &weights)
00924 {
00925 for (size_t i = 0; i < ONE_DIM; ++i)
00926 {
00927 for (int s=0; s<NStages; ++s)
00928 table[i][s] = weights.value(i + ONE_DIM*s);
00929 }
00930 }
00931
00932 osl::MultiInt osl::eval::ml::
00933 BishopBishopPiece::eval(const NumEffectState &state)
00934 {
00935 MultiInt result;
00936 const Piece bishop1 = state.getPieceOf(PtypeTraits<BISHOP>::indexMin);
00937 const Piece bishop2 = state.getPieceOf(PtypeTraits<BISHOP>::indexMin + 1);
00938 if (!bishop1.isOnBoard() || !bishop2.isOnBoard() ||
00939 bishop1.owner() == bishop2.owner())
00940 return result;
00941 if (bishop1.position().x() + bishop1.position().y() !=
00942 bishop2.position().x() + bishop2.position().y() &&
00943 bishop1.position().x() - bishop1.position().y() !=
00944 bishop2.position().x() - bishop2.position().y())
00945 return result;
00946
00947 if (state.hasEffectByPtype<BISHOP>(bishop2.owner(), bishop1.position()))
00948 return result;
00949
00950 Direction dir;
00951 if (bishop1.position().x() < bishop2.position().x())
00952 {
00953 if (bishop1.position().y() < bishop2.position().y())
00954 {
00955 dir = UR;
00956 }
00957 else
00958 {
00959 dir = DR;
00960 }
00961 }
00962 else
00963 {
00964 if (bishop1.position().y() < bishop2.position().y())
00965 {
00966 dir = UL;
00967 }
00968 else
00969 {
00970 dir = DL;
00971 }
00972 }
00973 Position p1 = state.getMobility(inverse(dir), bishop1.number());
00974 Position p2 = state.getMobility(dir, bishop2.number());
00975 if (p1 == p2)
00976 {
00977 const Piece p = state.getPieceAt(p1);
00978 const bool black_with_support =
00979 state.hasEffectBy<BLACK>(bishop1.owner() == BLACK ?
00980 bishop1.position() : bishop2.position());
00981 const bool white_with_support =
00982 state.hasEffectBy<WHITE>(bishop1.owner() == WHITE ?
00983 bishop1.position() : bishop2.position());
00984 if (p.owner() == BLACK)
00985 {
00986 result += table[index(p.ptype(), black_with_support,
00987 white_with_support)];
00988 }
00989 else
00990 {
00991 result -= table[index(p.ptype(), white_with_support,
00992 black_with_support)];
00993 }
00994 }
00995 return result;
00996 }
00997
00998 osl::misc::CArray<MultiInt, 800>
00999 osl::eval::ml::RookRook::table;
01000
01001 void osl::eval::ml::
01002 RookRook::setUp(const Weights &weights)
01003 {
01004 CArray<MultiInt, 800> orig_table;
01005 for (size_t i = 0; i < ONE_DIM; ++i)
01006 {
01007 for (int s=0; s<NStages; ++s)
01008 orig_table[i][s] = weights.value(i + ONE_DIM*s);
01009 }
01010 for (int owner = 0; owner < 2; ++owner)
01011 {
01012 const bool same_player = (owner == 0);
01013 for (int y1 = 0; y1 < 10; ++y1)
01014 {
01015 for (int y2 = 0; y2 < 10; ++y2)
01016 {
01017 for (int promoted1 = 0; promoted1 < 2; ++promoted1)
01018 {
01019 for (int promoted2 = 0; promoted2 < 2; ++promoted2)
01020 {
01021 if (same_player)
01022 {
01023 int y1p = y1;
01024 int y2p = y2;
01025 int promoted1p = promoted1;
01026 int promoted2p = promoted2;
01027 if (y1 > y2 || (y1 == y2 && !promoted1 && promoted2))
01028 {
01029 std::swap(y1p, y2p);
01030 std::swap(promoted1p, promoted2p);
01031 }
01032 table[index(same_player, promoted1, promoted2,
01033 y1, y2)] =
01034 orig_table[index(same_player, promoted1p, promoted2p,
01035 y1p, y2p)];
01036 }
01037 else
01038 {
01039 if (y1 + y2 > 10 || y1 == 0 ||
01040 (y1 + y2 == 10 && promoted1))
01041 {
01042 const int idx = index(same_player, promoted1, promoted2,
01043 y1, y2);
01044 table[idx] = orig_table[idx];
01045 }
01046 else
01047 {
01048 table[index(same_player, promoted1, promoted2,
01049 y1, y2)] =
01050 -orig_table[index(same_player, promoted2, promoted1,
01051 (10 - y2) % 10, (10 - y1) % 10)];
01052 }
01053 }
01054 }
01055 }
01056 }
01057 }
01058 }
01059 }
01060
01061 osl::MultiInt osl::eval::ml::
01062 RookRook::eval(const NumEffectState &state)
01063 {
01064 MultiInt result;
01065 Piece rook1 = state.getPieceOf(PtypeTraits<ROOK>::indexMin);
01066 Piece rook2 = state.getPieceOf(PtypeTraits<ROOK>::indexMin + 1);
01067 if (rook1.owner() == rook2.owner())
01068 {
01069 if (rook1.owner() == BLACK)
01070 {
01071 result += table[index<true, BLACK>(rook1, rook2)];
01072 }
01073 else
01074 {
01075 result -= table[index<true, WHITE>(rook1, rook2)];
01076 }
01077 }
01078 else
01079 {
01080 if (rook1.owner() != BLACK)
01081 {
01082 std::swap(rook1, rook2);
01083 }
01084 result += table[index<false, BLACK>(rook1, rook2)];
01085 }
01086 return result;
01087 }
01088
01089
01090 osl::misc::CArray<MultiInt, 128>
01091 osl::eval::ml::RookRookPiece::table;
01092
01093 void osl::eval::ml::
01094 RookRookPiece::setUp(const Weights &weights)
01095 {
01096 for (size_t i = 0; i < ONE_DIM; ++i)
01097 {
01098 for (int s=0; s<NStages; ++s)
01099 table[i][s] = weights.value(i + ONE_DIM*s);
01100 }
01101 }
01102
01103 osl::MultiInt osl::eval::ml::
01104 RookRookPiece::eval(const NumEffectState &state)
01105 {
01106 MultiInt result;
01107 const Piece rook1 = state.getPieceOf(PtypeTraits<ROOK>::indexMin);
01108 const Piece rook2 = state.getPieceOf(PtypeTraits<ROOK>::indexMin + 1);
01109 if (!rook1.isOnBoard() || !rook2.isOnBoard() ||
01110 rook1.owner() == rook2.owner())
01111 return result;
01112
01113 if (state.hasEffectByPtype<ROOK>(rook2.owner(), rook1.position()))
01114 return result;
01115
01116 Direction dir;
01117 bool vertical = false;
01118 if (rook1.position().x() == rook2.position().x())
01119 {
01120 vertical = true;
01121 if (rook1.position().y() < rook2.position().y())
01122 {
01123 dir = D;
01124 }
01125 else
01126 {
01127 dir = U;
01128 }
01129 }
01130 else if (rook1.position().y() == rook2.position().y())
01131 {
01132 if (rook1.position().x() < rook2.position().x())
01133 {
01134 dir = L;
01135 }
01136 else
01137 {
01138 dir = R;
01139 }
01140 }
01141 else
01142 {
01143 return result;
01144 }
01145
01146 Position p1 = state.getMobility(dir, rook1.number());
01147 Position p2 = state.getMobility(inverse(dir), rook2.number());
01148 assert(p1.isOnBoard() && p2.isOnBoard());
01149 if (p1 == p2)
01150 {
01151 const Piece p = state.getPieceAt(p1);
01152 const bool black_with_support =
01153 state.hasEffectBy<BLACK>(rook1.owner() == BLACK ?
01154 rook1.position() : rook2.position());
01155 const bool white_with_support =
01156 state.hasEffectBy<WHITE>(rook1.owner() == WHITE ?
01157 rook1.position() : rook2.position());
01158 if (p.owner() == BLACK)
01159 {
01160 result += table[index(p.ptype(), black_with_support,
01161 white_with_support, vertical)];
01162 }
01163 else
01164 {
01165 result -= table[index(p.ptype(), white_with_support,
01166 black_with_support, vertical)];
01167 }
01168 }
01169 return result;
01170 }
01171
01172
01173 osl::misc::CArray<MultiInt, 32>
01174 osl::eval::ml::BishopStandFile5::table;
01175
01176 void osl::eval::ml::
01177 BishopStandFile5::setUp(const Weights &weights)
01178 {
01179 for (size_t i = 0; i < ONE_DIM; ++i)
01180 {
01181 for (int s=0; s<NStages; ++s)
01182 table[i][s] = weights.value(i + ONE_DIM*s);
01183 }
01184 }
01185
01186 osl::MultiInt osl::eval::ml::
01187 BishopStandFile5::eval(const NumEffectState &state)
01188 {
01189 MultiInt result;
01190 if (state.hasPieceOnStand<BISHOP>(BLACK))
01191 {
01192 result += table[ptypeOIndex(state.getPieceAt(Position(5, 3)).ptypeO())];
01193 }
01194 if (state.hasPieceOnStand<BISHOP>(WHITE))
01195 {
01196 PtypeO ptypeO = state.getPieceAt(Position(5, 7)).ptypeO();
01197 ptypeO = altIfPiece(ptypeO);
01198 result -= table[ptypeOIndex(ptypeO)];
01199 }
01200 return result;
01201 }
01202
01203
01204 namespace osl
01205 {
01206 namespace eval
01207 {
01208 namespace ml
01209 {
01210 template class MajorY<true, ROOK>;
01211 template class MajorY<false, ROOK>;
01212 template class MajorY<true, BISHOP>;
01213 template class MajorY<false, BISHOP>;
01214 template class RookPawn<true>;
01215 template class RookPawn<false>;
01216 template class MajorGoldSilverAttacked<false>;
01217 template MultiInt KingRookBishop::evalOne<BLACK>(const NumEffectState &state);
01218 template MultiInt KingRookBishop::evalOne<WHITE>(const NumEffectState &state);
01219 }
01220 }
01221 }
01222
01223
01224
01225
01226