65 std::ifstream is(filename);
69 for (
size_t i = 0; i < weights.
dimension(); ++i)
73 effect_weight[i] = val;
76 for (
size_t i = 0; i < 225; ++i)
80 effect_x_weight[i] = val;
83 for (
size_t i = 0; i < 225; ++i)
87 effect_y_weight[i] = val;
91 for (
size_t i = 0; i < weights.
dimension(); ++i)
95 effect_defense_weight[i] = val;
99 for (
size_t i = 0; i < weights.
dimension(); ++i)
103 effect_per_effect[i] = val;
107 for (
size_t i = 0; i < weights.
dimension(); ++i)
111 effect_per_effect_defense[i] = val;
116 for (
size_t i = 0; i < weights.
dimension(); ++i)
120 effect_per_effect_y[i] = val;
124 for (
size_t i = 0; i < weights.
dimension(); ++i)
128 effect_per_effect_x[i] = val;
132 for (
size_t i = 0; i < weights.
dimension(); ++i)
140 for (
size_t i = 0; i < weights.
dimension(); ++i)
148 for (
size_t i = 0; i < weights.
dimension(); ++i)
156 for (
size_t i = 0; i < weights.
dimension(); ++i)
164 for (
size_t i = 0; i < weights.
dimension(); ++i)
172 for (
size_t i = 0; i < weights.
dimension(); ++i)
180 for (
size_t i = 0; i < weights.
dimension(); ++i)
188 for (
size_t i = 0; i < weights.
dimension(); ++i)
196 for (
size_t i = 0; i < weights.
dimension(); ++i)
204 for (
size_t i = 0; i < weights.
dimension(); ++i)
221 for(
int king_x=1;king_x<=9;king_x++){
222 for(
int king_y=1;king_y<=9;king_y++){
223 Square king(king_x,king_y);
224 int king_index=(king_x-1)*9+king_y-1;
226 const int min_x = center.
x() - 2;
227 const int min_y = center.
y() - 1;
229 for (
int dx=0; dx<5; ++dx)
231 for (
int dy=0; dy<3; ++dy,++i)
233 const Square target(min_x+dx,min_y+dy);
234 int index0=king_index*15+i;
235 int index_a=index0*10;
236 int index_d=index0*10;
238 effect_weight[index<BLACK>(king, target)] +
239 effect_x_weight[indexX<BLACK>(king, target)] +
240 effect_y_weight[indexY<BLACK>(king, target)];
242 effect_defense_weight[index<BLACK>(king, target)];
243 for(
int count=0;count<=8;count++){
245 effect_per_effect[indexPerEffect<BLACK>(king, target, count)] +
246 effect_per_effect_y[indexPerEffectY<BLACK>(king, target, count)] +
247 effect_per_effect_x[indexPerEffectX<BLACK>(king, target, count)];
249 effect_per_effect_defense[indexPerEffect<BLACK>(king, target, count)];
255 for(
int king_x=1;king_x<=5;king_x++)
271 for (
int i=2; i<10; ++i)
277 std::cerr <<
"Failed to load NewProgress data " << read_count
278 <<
" from file " << filename << std::endl;
285 return setUp(defaultFilename().c_str());
291 filename +=
"/data/progress.txt";
295 template <osl::Player P>
301 const int min_x = center.x() - 2;
302 const int min_y = center.y() - 1;
304 attack = defense = 0;
309 int index0=((kingRel.
x()-1)*9+kingRel.
y()-1)*15;
310 int index_a=index0*10 + (P==
WHITE ? 10*14 : 0);
311 for (
int dx=0; dx<5; ++dx)
313 for (
int dy=0; dy<3; ++dy)
315 const Square target(min_x+dx,min_y+dy);
316 const int attack_count =
318 const int defense_count =
320 attack += attack_count *attack_relative[index_a]+
321 attack_relative[index_a+
std::min(attack_count,8)+1];
323 defense_count * defense_relative[index_a]+
324 defense_relative[index_a+
std::min(defense_count,8)+1];
335 template <osl::Player P>
340 const int min_x =
std::max(1, king.
x() - 2);
341 const int max_x =
std::min(9, king.
x() + 2);
342 const int min_y =
std::max(1, king.
y() - 2);
343 const int max_y =
std::min(9, king.
y() + 2);
344 effect_progresses[P] = 0;
347 for (
int y = min_y; y <= max_y; ++y)
349 for (
int x = min_x; x <= max_x; ++x)
351 const Square target(x, y);
353 const int effect_diff =
355 const int x_diff = std::abs(x - king.
x());
356 const int y_diff = (P ==
WHITE ? king.
y() - y : y - king.
y());
358 5 * 3 * (y_diff + 2);
359 effect_progresses[P] += effectstate_weight[index];
363 updateAttack5x5Pieces<P>(mask, state);
366 template <osl::Player P>
385 template <osl::Player P>
392 king_x = 10 - king_x;
395 return (attack5x5_x_weight[index5x5x(
400 promoted[attack], king_x)] +
401 attack5x5_y_weight[index5x5y(
406 promoted[attack], king_y)]);
417 king_relative_attack.fill(0);
418 king_relative_defense.fill(0);
425 const int index_attack = indexRelative(piece.
owner(), kings[
alt(pl)],
427 const int index_defense = indexRelative(piece.
owner(), kings[pl],
429 king_relative_attack[pl] += king_relative_weight[index_attack];
430 king_relative_defense[pl] += king_relative_weight[index_defense];
434 template <osl::Player Owner>
444 while (attacked.
any())
452 for (
size_t i=0; i<pieces.
size(); ++i) {
453 const int i0 = feature_t::index1(state, pieces[i]);
454 result += attacked_ptype_pair_weight[feature_t::index2(0,i0)];
455 for (
size_t j=i+1; j<pieces.
size(); ++j) {
456 const int i1 = feature_t::index1(state, pieces[j]);
457 result += attacked_ptype_pair_weight[feature_t::index2(i0,i1)];
459 result_eval += feature_t::table[feature_t::index2(i0, i1)];
461 result_eval -= feature_t::table[feature_t::index2(i0, i1)];
464 non_pawn_ptype_attacked_pair[Owner] = result;
465 non_pawn_ptype_attacked_pair_eval[Owner] = result_eval;
471 updateNonPawnAttackedPtypePairOne<BLACK>(state);
472 updateNonPawnAttackedPtypePairOne<WHITE>(state);
487 pawn_facing = pawn_facing_weight[count];
490 template <osl::Player P>
496 for (
int x=1; x<=9; ++x) {
497 const Square target(x, rank);
498 if (! state[target].isEmpty())
512 promotion37 += promotion37_weight[p];
513 promotion37_eval += feature_t::table[p]*
sign(P);
516 promotion37 += promotion37_weight[p-8]*(count[p]-1);
517 promotion37_eval += feature_t::table[p-8]*(
sign(P)*(count[p]-1));
527 promotion37One<BLACK>(state, 3);
528 promotion37One<WHITE>(state, 7);
535 for (
int z=0; z<2; ++z) {
541 for (
int i=0; i<
std::min(7,filled+1); ++i)
542 piecestand7 += piecestand7_weight[stand[i] + 8*i];
549 assert(initialized_flag);
551 progressOne<BLACK>(state,
554 progressOne<WHITE>(state,
557 updateAttack5x5PiecesAndState<BLACK>(state);
558 updateAttack5x5PiecesAndState<WHITE>(state);
559 attack5x5_progresses[
BLACK] =
560 attack5x5Value<BLACK>(state);
561 attack5x5_progresses[
WHITE] =
562 attack5x5Value<WHITE>(state);
563 stand_progresses.fill(0);
566 const int black_count =
568 const int white_count =
570 for (
int j = 0; j < black_count; ++j)
572 stand_progresses[
WHITE] +=
575 for (
int j = 0; j < white_count; ++j)
577 stand_progresses[
BLACK] +=
581 updatePieceKingRelativeBonus(state);
582 updateNonPawnAttackedPtypePair(state);
583 updatePawnFacing(state);
584 updatePromotion37(state);
585 updatePieceStand7(state);
588 template<osl::Player P>
595 assert(new_state.
turn()==altP);
596 assert(last_move.
player()==P);
599 const bool king_move = last_move.
ptype() ==
KING;
602 progressOne<WHITE>(new_state,progresses[
WHITE],defenses[
BLACK]);
606 progressOne<BLACK>(new_state,progresses[
BLACK],defenses[
WHITE]);
617 stand_progresses[altP] -= value;
625 stand_progresses[altP] += value;
630 updatePieceKingRelativeBonus(new_state);
640 const int index_attack =
641 indexRelative<P>(kings[altP],
643 const int index_defense =
644 indexRelative<P>(kings[P],
646 king_relative_attack[P] -=
647 king_relative_weight[index_attack];
648 king_relative_defense[P] -=
649 king_relative_weight[index_defense];
652 const int index_attack =
653 indexRelative<P>(kings[altP],
654 last_move.
ptype(), last_move.
to());
655 const int index_defense =
656 indexRelative<P>(kings[P],
657 last_move.
ptype(), last_move.
to()) + 2142;
658 king_relative_attack[P] +=
659 king_relative_weight[index_attack];
660 king_relative_defense[P] +=
661 king_relative_weight[index_defense];
665 const int index_attack =
666 indexRelative<altP>(kings[P],
668 const int index_defense =
669 indexRelative<altP>(kings[altP],
671 king_relative_attack[altP] -=
672 king_relative_weight[index_attack];
673 king_relative_defense[altP] -=
674 king_relative_weight[index_defense];
677 updateNonPawnAttackedPtypePair(new_state);
678 updatePawnFacing(new_state);
679 updatePromotion37(new_state);
680 updatePieceStand7(new_state);
683 template<osl::Player P>
689 assert(new_state.
turn()==altP);
694 const bool king_move = last_move.
ptype() ==
KING;
697 if ((king_move && altP ==
BLACK) ||
701 updateAttack5x5PiecesAndState<WHITE>(new_state);
702 attack5x5_progresses[
WHITE] =
703 attack5x5Value<WHITE>(new_state);
707 attack5x5_progresses[
WHITE] =
708 attack5x5Value<WHITE>(new_state);
710 if ((king_move && altP ==
WHITE) ||
714 updateAttack5x5PiecesAndState<BLACK>(new_state);
715 attack5x5_progresses[
BLACK] =
716 attack5x5Value<BLACK>(new_state);
720 attack5x5_progresses[
BLACK] =
721 attack5x5Value<BLACK>(new_state);
723 updateMain<P>(new_state, last_move);
757 template void osl::progress::ml::NewProgress::updateSub<osl::BLACK>(
const NumEffectState &new_state,
Move last_move);
758 template void osl::progress::ml::NewProgress::updateSub<osl::WHITE>(
const NumEffectState &new_state,
Move last_move);