8 #include <boost/foreach.hpp> 
   44 osl::CArray<int, 262144> 
 
   60   static CArray<int, 25> effect_weight;
 
   61   static CArray<int, 225> effect_x_weight, effect_y_weight;
 
   62   static CArray<int, 25> effect_defense_weight;
 
   63   static CArray<int, 225> effect_per_effect;
 
   64   static CArray<int, 225> effect_per_effect_defense;
 
   65   static CArray<int, 2025> effect_per_effect_y, effect_per_effect_x;
 
   66   std::ifstream is(filename);
 
   70   for (
size_t i = 0; i < weights.
dimension(); ++i)
 
   74     effect_weight[i] = val;
 
   77   for (
size_t i = 0; i < 225; ++i)
 
   81     effect_x_weight[i] = val;
 
   84   for (
size_t i = 0; i < 225; ++i)
 
   88     effect_y_weight[i] = val;
 
   92   for (
size_t i = 0; i < weights.
dimension(); ++i)
 
   96     effect_defense_weight[i] = val;
 
  100   for (
size_t i = 0; i < weights.
dimension(); ++i)
 
  104     effect_per_effect[i] = val;
 
  108   for (
size_t i = 0; i < weights.
dimension(); ++i)
 
  112     effect_per_effect_defense[i] = val;
 
  117   for (
size_t i = 0; i < weights.
dimension(); ++i)
 
  121     effect_per_effect_y[i] = val;
 
  125   for (
size_t i = 0; i < weights.
dimension(); ++i)
 
  129     effect_per_effect_x[i] = val;
 
  133   for (
size_t i = 0; i < weights.
dimension(); ++i)
 
  141   for (
size_t i = 0; i < weights.
dimension(); ++i)
 
  149   for (
size_t i = 0; i < weights.
dimension(); ++i)
 
  157   for (
size_t i = 0; i < weights.
dimension(); ++i)
 
  165   for (
size_t i = 0; i < weights.
dimension(); ++i)
 
  173   for (
size_t i = 0; i < weights.
dimension(); ++i)
 
  181   for (
size_t i = 0; i < weights.
dimension(); ++i)
 
  189   for (
size_t i = 0; i < weights.
dimension(); ++i)
 
  197   for (
size_t i = 0; i < weights.
dimension(); ++i)
 
  205   for (
size_t i = 0; i < weights.
dimension(); ++i)
 
  222   for(
int king_x=1;king_x<=9;king_x++){
 
  223     for(
int king_y=1;king_y<=9;king_y++){
 
  224       Square king(king_x,king_y);
 
  225       int king_index=(king_x-1)*9+king_y-1;
 
  227       const int min_x = center.
x() - 2;
 
  228       const int min_y = center.
y() - 1;
 
  230       for (
int dx=0; dx<5; ++dx)
 
  232         for (
int dy=0; dy<3; ++dy,++i)
 
  235           int index0=king_index*15+i;
 
  236           int index_a=index0*10;
 
  237           int index_d=index0*10;
 
  239             effect_weight[index<BLACK>(king, 
target)] +
 
  240             effect_x_weight[indexX<BLACK>(king, target)] +
 
  241             effect_y_weight[indexY<BLACK>(king, 
target)];
 
  243             effect_defense_weight[index<BLACK>(king, 
target)];
 
  246               effect_per_effect[indexPerEffect<BLACK>(king, 
target, 
count)] +
 
  247               effect_per_effect_y[indexPerEffectY<BLACK>(king, target, 
count)] +
 
  248               effect_per_effect_x[indexPerEffectX<BLACK>(king, 
target, 
count)];
 
  249             defense_relative[index_d+
count+1]=
 
  250               effect_per_effect_defense[indexPerEffect<BLACK>(king, 
target, 
count)];
 
  256   for(
int king_x=1;king_x<=5;king_x++)
 
  267     for (
int j=i+1; j<PTYPE_SIZE*2*
PTYPE_SIZE; ++j) {
 
  272   for (
int i=2; i<10; ++i)
 
  278     std::cerr << 
"Failed to load NewProgress data " << read_count
 
  279               << 
" from file " << filename << std::endl;
 
  286   return setUp(defaultFilename().c_str());  
 
  292   filename += 
"/data/progress.txt";
 
  296 template <osl::Player P>
 
  298   const NumEffectState &state, 
int &attack, 
int &defense)
 
  300   const Square king = state.kingSquare<P>();
 
  302   const int min_x = center.x() - 2;
 
  303   const int min_y = center.y() - 1;
 
  305   attack = defense = 0;
 
  310   int index0=((kingRel.
x()-1)*9+kingRel.
y()-1)*15;
 
  311   int index_a=index0*10 + (P==
WHITE ? 10*14 : 0);
 
  312   for (
int dx=0; dx<5; ++dx)
 
  314     for (
int dy=0; dy<3; ++dy)
 
  317       const int attack_count =
 
  318         state.countEffect(
alt(P), target);
 
  319       const int defense_count =
 
  320         state.countEffect(P, target);
 
  321       attack += attack_count *attack_relative[index_a]+
 
  322         attack_relative[index_a+
std::min(attack_count,8)+1];
 
  324         defense_count * defense_relative[index_a]+
 
  325         defense_relative[index_a+
std::min(defense_count,8)+1];
 
  336 template <osl::Player P>
 
  338   const NumEffectState &state)
 
  340   const Square king = state.kingSquare<P>();
 
  341   const int min_x = 
std::max(1, king.
x() - 2);
 
  342   const int max_x = 
std::min(9, king.
x() + 2);
 
  343   const int min_y = 
std::max(1, king.
y() - 2);
 
  344   const int max_y = 
std::min(9, king.
y() + 2);
 
  345   effect_progresses[P] = 0;
 
  348   for (
int y = min_y; y <= max_y; ++y)
 
  350     for (
int x = min_x; x <= max_x; ++x)
 
  353       const NumBitmapEffect effect = state.effectSetAt(target);
 
  354       const int effect_diff =
 
  355         effect.countEffect(
alt(P)) - effect.countEffect(P);
 
  356       const int x_diff = std::abs(x - king.
x());
 
  357       const int y_diff = (P == 
WHITE ? king.
y() - y : y - king.
y());
 
  359         5 * 3 * (y_diff + 2);
 
  360       effect_progresses[P] += effectstate_weight[index];
 
  364   updateAttack5x5Pieces<P>(mask, state);
 
  367 template <osl::Player P>
 
  369   PieceMask mask, 
const NumEffectState& state)
 
  372   mask &= state.piecesOnBoard(attack);
 
  374   rook[attack] = mask.selectBit<
ROOK>().countBit();
 
  375   bishop[attack] = mask.selectBit<
BISHOP>().countBit();
 
  376   gold[attack] = mask.selectBit<
GOLD>().countBit();
 
  378     (mask & ~state.promotedPieces()).selectBit<SILVER>().countBit();
 
  379   PieceMask promoted_pieces = mask & state.promotedPieces();
 
  380   promoted_pieces.clearBit<
ROOK>();
 
  381   promoted_pieces.clearBit<
BISHOP>();
 
  383     std::min(promoted_pieces.countBit(), 4);
 
  386 template <osl::Player P>
 
  388   const NumEffectState &state)
 const 
  391   int king_x = state.kingSquare<P>().x();
 
  393     king_x = 10 - king_x;
 
  394   const int king_y = (P == 
BLACK ? state.kingSquare<P>().y() :
 
  395                       10 - state.kingSquare<P>().y());
 
  396   return (attack5x5_x_weight[index5x5x(
 
  397               rook[attack] + state.countPiecesOnStand<
ROOK>(attack),
 
  398               bishop[attack] + state.countPiecesOnStand<
BISHOP>(attack),
 
  399               gold[attack] + state.countPiecesOnStand<
GOLD>(attack),
 
  400               silver[attack] + state.countPiecesOnStand<
SILVER>(attack),
 
  401               promoted[attack], king_x)] +
 
  402           attack5x5_y_weight[index5x5y(
 
  403               rook[attack] + state.countPiecesOnStand<
ROOK>(attack),
 
  404               bishop[attack] + state.countPiecesOnStand<
BISHOP>(attack),
 
  405               gold[attack] + state.countPiecesOnStand<
GOLD>(attack),
 
  406               silver[attack] + state.countPiecesOnStand<
SILVER>(attack),
 
  407               promoted[attack], king_y)]);
 
  412   const NumEffectState &state)
 
  414   const CArray<Square,2> kings = {{ 
 
  415       state.kingSquare(
BLACK),
 
  416       state.kingSquare(
WHITE),
 
  418   king_relative_attack.fill(0);
 
  419   king_relative_defense.fill(0);
 
  422     const Piece piece = state.pieceOf(i);
 
  426     const int index_attack = indexRelative(piece.
owner(), kings[
alt(pl)],
 
  428     const int index_defense = indexRelative(piece.
owner(), kings[pl],
 
  430     king_relative_attack[pl] += king_relative_weight[index_attack];
 
  431     king_relative_defense[pl] += king_relative_weight[index_defense];
 
  435 template <osl::Player Owner>
 
  439   PieceMask attacked = state.effectedMask(
alt(Owner)) & state.piecesOnBoard(Owner);
 
  440   attacked.reset(state.kingPiece<Owner>().number());
 
  441   mask_t ppawn = state.promotedPieces().getMask<
PAWN>() & attacked.selectBit<
PAWN>();
 
  442   attacked.clearBit<
PAWN>();
 
  445   while (attacked.any())
 
  447     const Piece piece = state.pieceOf(attacked.takeOneBit());
 
  448     pieces.push_back(piece);
 
  453   for (
size_t i=0; i<pieces.size(); ++i) {
 
  454     const int i0 = feature_t::index1(state, pieces[i]);
 
  455     result += attacked_ptype_pair_weight[feature_t::index2(0,i0)];
 
  456     for (
size_t j=i+1; j<pieces.size(); ++j) {
 
  457       const int i1 = feature_t::index1(state, pieces[j]);
 
  458       result += attacked_ptype_pair_weight[feature_t::index2(i0,i1)];
 
  460         result_eval += feature_t::table[feature_t::index2(i0, i1)];
 
  462         result_eval -= feature_t::table[feature_t::index2(i0, i1)];
 
  465   non_pawn_ptype_attacked_pair[Owner] = 
result;
 
  466   non_pawn_ptype_attacked_pair_eval[Owner] = result_eval;
 
  472   updateNonPawnAttackedPtypePairOne<BLACK>(state);
 
  473   updateNonPawnAttackedPtypePairOne<WHITE>(state);
 
  479   PieceMask attacked = state.effectedMask(
WHITE) & state.piecesOnBoard(
BLACK);
 
  481     & ~(state.promotedPieces().getMask<
PAWN>());
 
  488   pawn_facing = pawn_facing_weight[
count];
 
  491 template <osl::Player P>
 
  496   CArray<int,PTYPE_SIZE> 
count = {{ 0 }};
 
  497   for (
int x=1; x<=9; ++x) {
 
  499     if (! state[target].isEmpty())
 
  501     int a = state.countEffect(P, target);
 
  502     const int d = state.countEffect(
alt(P), target);
 
  507     const Ptype ptype = state.findCheapAttack(P, target).ptype();
 
  513       promotion37 += promotion37_weight[p];
 
  514       promotion37_eval += feature_t::table[p]*
playerToMul(P);
 
  517       promotion37 += promotion37_weight[p-8]*(count[p]-1);
 
  518       promotion37_eval += feature_t::table[p-8]*(
playerToMul(P)*(count[p]-1));
 
  528   promotion37One<BLACK>(state, 3);
 
  529   promotion37One<WHITE>(state, 7);
 
  536   for (
int z=0; z<2; ++z) {
 
  537     CArray<int,7> stand = {{ 0 }};
 
  542     for (
int i=0; i<
std::min(7,filled+1); ++i)
 
  543       piecestand7 += piecestand7_weight[stand[i] + 8*i];
 
  548   const NumEffectState &state)
 
  550   assert(initialized_flag);
 
  552   progressOne<BLACK>(state,
 
  555   progressOne<WHITE>(state,
 
  558   updateAttack5x5PiecesAndState<BLACK>(state);
 
  559   updateAttack5x5PiecesAndState<WHITE>(state);
 
  560   attack5x5_progresses[
BLACK] =
 
  561     attack5x5Value<BLACK>(state);
 
  562   attack5x5_progresses[
WHITE] =
 
  563     attack5x5Value<WHITE>(state);
 
  564   stand_progresses.fill(0);
 
  567     const int black_count =
 
  568       state.countPiecesOnStand(
BLACK, ptype);
 
  569     const int white_count =
 
  570       state.countPiecesOnStand(
WHITE, ptype);
 
  571     for (
int j = 0; j < black_count; ++j)
 
  573       stand_progresses[
WHITE] +=
 
  576     for (
int j = 0; j < white_count; ++j)
 
  578       stand_progresses[
BLACK] +=
 
  582   updatePieceKingRelativeBonus(state);
 
  583   updateNonPawnAttackedPtypePair(state);
 
  584   updatePawnFacing(state);
 
  585   updatePromotion37(state);
 
  586   updatePieceStand7(state);
 
  589 template<osl::Player P>
 
  592   const NumEffectState &new_state,
 
  596   assert(new_state.turn()==altP);
 
  597   assert(last_move.
player()==P);
 
  598   const Square kb = new_state.kingSquare<
BLACK>(), kw = new_state.kingSquare<
WHITE>();
 
  599   const BoardMask mb = new_state.changedEffects(
BLACK), mw = new_state.changedEffects(
WHITE);
 
  600   const bool king_move = last_move.
ptype() == 
KING;
 
  603     progressOne<WHITE>(new_state,progresses[
WHITE],defenses[
BLACK]);
 
  607     progressOne<BLACK>(new_state,progresses[
BLACK],defenses[
WHITE]);
 
  615       new_state.countPiecesOnStand(P, last_move.
ptype()) + 1;
 
  618     stand_progresses[altP] -= value;
 
  623     const int count = new_state.countPiecesOnStand(P, ptype);
 
  626     stand_progresses[altP] += value;
 
  631     updatePieceKingRelativeBonus(new_state);
 
  635     const CArray<Square,2> kings = {{ 
 
  636         new_state.kingSquare(
BLACK),
 
  637         new_state.kingSquare(
WHITE),
 
  641       const int index_attack =
 
  642         indexRelative<P>(kings[altP],
 
  644       const int index_defense =
 
  645         indexRelative<P>(kings[P],
 
  647       king_relative_attack[P] -=
 
  648         king_relative_weight[index_attack];
 
  649       king_relative_defense[P] -=
 
  650         king_relative_weight[index_defense];
 
  653       const int index_attack =
 
  654         indexRelative<P>(kings[altP],
 
  655                          last_move.
ptype(), last_move.
to());
 
  656       const int index_defense =
 
  657         indexRelative<P>(kings[P],
 
  658                          last_move.
ptype(), last_move.
to()) + 2142;
 
  659       king_relative_attack[P] +=
 
  660         king_relative_weight[index_attack];
 
  661       king_relative_defense[P] +=
 
  662         king_relative_weight[index_defense];
 
  666       const int index_attack =
 
  667         indexRelative<altP>(kings[P],
 
  669       const int index_defense =
 
  670         indexRelative<altP>(kings[altP],
 
  672       king_relative_attack[altP] -=
 
  673         king_relative_weight[index_attack];
 
  674       king_relative_defense[altP] -=
 
  675         king_relative_weight[index_defense];
 
  678   updateNonPawnAttackedPtypePair(new_state);
 
  679   updatePawnFacing(new_state);
 
  680   updatePromotion37(new_state);
 
  681   updatePieceStand7(new_state);
 
  684 template<osl::Player P>
 
  686   const NumEffectState &new_state,
 
  690   assert(new_state.turn()==altP);
 
  693   const Square kb = new_state.kingSquare<
BLACK>(), kw = new_state.kingSquare<
WHITE>();
 
  694   const BoardMask mb = new_state.changedEffects(
BLACK), mw = new_state.changedEffects(
WHITE);
 
  695   const bool king_move = last_move.
ptype() == 
KING;
 
  698   if ((king_move && altP == 
BLACK) ||
 
  702     updateAttack5x5PiecesAndState<WHITE>(new_state);
 
  703     attack5x5_progresses[
WHITE] =
 
  704       attack5x5Value<WHITE>(new_state);
 
  708     attack5x5_progresses[
WHITE] =
 
  709       attack5x5Value<WHITE>(new_state);
 
  711   if ((king_move && altP == 
WHITE) ||
 
  715     updateAttack5x5PiecesAndState<BLACK>(new_state);
 
  716     attack5x5_progresses[
BLACK] =
 
  717       attack5x5Value<BLACK>(new_state);
 
  721     attack5x5_progresses[
BLACK] =
 
  722       attack5x5Value<BLACK>(new_state);
 
  724   updateMain<P>(new_state, last_move);
 
  758       template void osl::progress::ml::NewProgress::updateSub<osl::BLACK>(
const NumEffectState &new_state,
Move last_move);
 
  759       template void osl::progress::ml::NewProgress::updateSub<osl::WHITE>(
const NumEffectState &new_state,
Move last_move);