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";
295template <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];
335template <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());
357 int index = std::max(std::min(effect_diff, 2), -2) + 2 + 5 * x_diff +
358 5 * 3 * (y_diff + 2);
359 effect_progresses[P] += effectstate_weight[index];
363 updateAttack5x5Pieces<P>(mask, state);
366template <osl::Player P>
377 (mask & ~state.promotedPieces()).selectBit<SILVER>().countBit();
382 std::min(promoted_pieces.
countBit(), 4);
385template <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];
434template <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];
490template <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);
588template<osl::Player P>
595 assert(new_state.
turn()==altP);
596 assert(last_move.
player()==P);
599 const bool king_move = last_move.
ptype() ==
KING;
600 if ((king_move && altP ==
BLACK) || mb.
anyInRange(Board_Mask_Table5x3_Center.
mask(kw)) || mw.anyInRange(Board_Mask_Table5x3_Center.
mask(kw)))
602 progressOne<WHITE>(new_state,progresses[
WHITE],defenses[
BLACK]);
604 if ((king_move && altP ==
WHITE) || mw.anyInRange(Board_Mask_Table5x3_Center.
mask(kb)) || mb.
anyInRange(Board_Mask_Table5x3_Center.
mask(kb)))
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);
683template<osl::Player P>
689 assert(new_state.
turn()==altP);
694 const bool king_move = last_move.
ptype() ==
KING;
697 if ((king_move && altP ==
BLACK) ||
699 mw.anyInRange(Board_Mask_Table5x5.
mask(kw)))
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) ||
711 mw.anyInRange(Board_Mask_Table5x5.
mask(kb)) ||
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);
void push_back(const T &e)
Ptype capturePtype() const
Ptype oldPtype() const
移動前のPtype, i.e., 成る手だった場合成る前
const Square from() const
const NumBitmapEffect effectSetAt(Square sq) const
const BoardMask changedEffects(Player pl) const
const PieceMask effectedMask(Player pl) const
pl からの利きが(1つ以上)ある駒一覧
int countEffect(Player player, Square target) const
利きの数を数える.
const Piece findCheapAttack(Player P, Square square) const
const PieceMask promotedPieces() const
const PieceMask & piecesOnBoard(Player p) const
bool hasEffectByPtypeStrict(Player attack, Square target) const
target に ptype の利きがあるか? 成不成を区別
const mask_t getMask(int num) const
void clearBit()
unpromote(PTYPE) の駒のbit を消す
void orMask(int index, mask_t val)
const mask_t selectBit() const
unpromote(PTYPE) の駒のbit だけ取り出す
static const CArray< Ptype, 7 > order
持駒の表示で良く使われる順番.
const Square square() const
int getIndexMin(Ptype ptype) const
bool hasPieceOnStand(Player player, Ptype ptype) const
const Piece kingPiece() const
const Piece pieceOf(int num) const
Square kingSquare() const
int countPiecesOnStand(Player pl, Ptype ptype) const
持駒の枚数を数える
int y() const
将棋としてのY座標を返す.
const Square rotate180() const
int x() const
将棋としてのX座標を返す.
const BoardMask & mask(Square p) const
p中心の5x3 の範囲のbitを立てたもの, centering
const BoardMask & mask(Square p) const
p中心の5x5 の範囲のbitを立てたもの, centeringなし
bool anyInRange(const BoardMask &mask) const
int countEffect(Player pl) const
static int index2(int i0, int i1)
void updateMain(const NumEffectState &new_state, Move last_move)
static CArray< int, 5625 > attack5x5_x_weight
void updatePawnFacing(const NumEffectState &state)
void promotion37One(const NumEffectState &state, int rank)
void updateAttack5x5PiecesAndState(const NumEffectState &state)
static CArray< int, 75 > effectstate_weight
static void progressOne(const NumEffectState &state, int &attack, int &defense)
void updateSub(const NumEffectState &new_state, Move last_move)
static CArray< int, 16 > promotion37_weight
void updateAttack5x5Pieces(PieceMask, const NumEffectState &)
static CArray< int, 10 > pawn_facing_weight
static CArray< int, 81 *15 *10 > defense_relative
NewProgress(const NumEffectState &state)
static std::string defaultFilename()
int attack5x5Value(const NumEffectState &state) const
void updateNonPawnAttackedPtypePairOne(const NumEffectState &state)
static CArray< int, 56 > piecestand7_weight
void updatePromotion37(const NumEffectState &state)
static CArray< int, 262144 > attacked_ptype_pair_weight
void updatePieceKingRelativeBonus(const NumEffectState &state)
void updatePieceStand7(const NumEffectState &state)
static CArray< int, 1125 > attack5x5_weight
static CArray< int, 81 *15 *10 > attack_relative
static CArray< int, Piece::SIZE > stand_weight
void updateNonPawnAttackedPtypePair(const NumEffectState &state)
static bool initialized_flag
static CArray< int, 4284 > king_relative_weight
static CArray< int, 10125 > attack5x5_y_weight
NewProgressDebugInfo debugInfo() const
bool operator==(const NewProgressData &l, const NewProgressData &r)
const PtypeTable Ptype_Table
constexpr Player indexToPlayer(int n)
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す
bool isPromoted(Ptype ptype)
ptypeがpromote後の型かどうかのチェック
constexpr int sign(Player player)
constexpr bool isPiece(Ptype ptype)
ptypeが空白やEDGEでないかのチェック
constexpr Player alt(Player player)
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に,ownerを反転する.
static const Square adjustCenter(Square src)
static const std::string & home(const std::string &initialize_if_first_invocation="")
compile時に指定されたディレクトリを返す.
static bool hasEffect(const NumEffectState &, Square target, Player attack)
target に attack の追加利きが一つでもあるか. 相手の影利きが先にある場合は対象としない.
void resetDimension(size_t new_dim)
CArray< int, 2 > effect_progresses
CArray< int, 2 > progresses
CArray< MultiInt, 2 > non_pawn_ptype_attacked_pair_eval
CArray< int, 2 > non_pawn_ptype_attacked_pair
CArray< int, 2 > king_relative_defense
CArray< int, 2 > promoted
CArray< int, 2 > attack5x5_progresses
CArray< int, 2 > king_relative_attack
CArray< int, 2 > defenses
CArray< int, 2 > stand_progresses
CArray< int, FEATURE_LIMIT > black_values
CArray< int, FEATURE_LIMIT > white_values