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)];
248 defense_relative[index_d+count+1]=
249 effect_per_effect_defense[indexPerEffect<BLACK>(king, target, count)];
255 for(
int king_x=1;king_x<=5;king_x++)
266 for (
int j=i+1; j<PTYPE_SIZE*2*
PTYPE_SIZE; ++j) {
271 for (
int i=2; i<10; ++i)
277 std::cerr <<
"Failed to load NewProgress data " << read_count
278 <<
" from file " << filename << std::endl;
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 =
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);
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);
363 updateAttack5x5Pieces<P>(mask, state);
366 template <osl::Player P>
385 template <osl::Player P>
392 king_x = 10 - king_x;
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]);
455 for (
size_t j=i+1; j<pieces.
size(); ++j) {
456 const int i1 = feature_t::index1(state, pieces[j]);
459 result_eval += feature_t::table[feature_t::index2(i0, i1)];
461 result_eval -= feature_t::table[feature_t::index2(i0, i1)];
471 updateNonPawnAttackedPtypePairOne<BLACK>(state);
472 updateNonPawnAttackedPtypePairOne<WHITE>(state);
490 template <osl::Player P>
496 for (
int x=1; x<=9; ++x) {
497 const Square target(x, rank);
498 if (! state[target].isEmpty())
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)
551 progressOne<BLACK>(state,
554 progressOne<WHITE>(state,
557 updateAttack5x5PiecesAndState<BLACK>(state);
558 updateAttack5x5PiecesAndState<WHITE>(state);
560 attack5x5Value<BLACK>(state);
561 attack5x5_progresses[
WHITE] =
562 attack5x5Value<WHITE>(state);
566 const int black_count =
567 state.countPiecesOnStand(
BLACK, ptype);
568 const int white_count =
569 state.countPiecesOnStand(
WHITE, ptype);
570 for (
int j = 0; j < black_count; ++j)
575 for (
int j = 0; j < white_count; ++j)
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;
640 const int index_attack =
641 indexRelative<P>(kings[altP],
643 const int index_defense =
644 indexRelative<P>(kings[P],
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;
665 const int index_attack =
666 indexRelative<altP>(kings[P],
668 const int index_defense =
669 indexRelative<altP>(kings[altP],
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);
703 attack5x5Value<WHITE>(new_state);
708 attack5x5Value<WHITE>(new_state);
710 if ((king_move && altP ==
WHITE) ||
714 updateAttack5x5PiecesAndState<BLACK>(new_state);
716 attack5x5Value<BLACK>(new_state);
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);
const BoardMaskTable5x3Center Board_Mask_Table5x3_Center
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す ...
void push_back(const T &e)
int countEffect(Player player, Square target) const
利きの数を数える.
int max(Player p, int v1, int v2)
void updatePieceKingRelativeBonus(const NumEffectState &state)
static int index(Square king, Square target)
GeneralMask< mask_int_t > mask_t
static int index5x5y(int rook, int bishop, int gold, int silver, int promoted, int king_y)
static void progressOne(const NumEffectState &state, int &attack, int &defense)
static CArray< int, 56 > piecestand7_weight
const BoardMask changedEffects(Player pl) const
constexpr Player alt(Player player)
CArray< int, 2 > king_relative_defense
CArray< int, 2 > promoted
static const Square adjustCenter(Square src)
int min(Player p, int v1, int v2)
NewProgressDebugInfo debugInfo() const
int countPiecesOnStand(Player pl, Ptype ptype) const
持駒の枚数を数える
const BoardMask & mask(Square p) const
p中心の5x3 の範囲のbitを立てたもの, centering
static bool hasEffect(const NumEffectState &, Square target, Player attack)
target に attack の追加利きが一つでもあるか. 相手の影利きが先にある場合は対象としない. ...
int y() const
将棋としてのY座標を返す.
CArray< int, 2 > effect_progresses
CArray< int, 2 > stand_progresses
void clearBit()
unpromote(PTYPE) の駒のbit を消す
CArray< int, FEATURE_LIMIT > white_values
void resetDimension(size_t new_dim)
static CArray< int, Piece::SIZE > stand_weight
int x() const
将棋としてのX座標を返す.
const Piece pieceOf(int num) const
Square kingSquare() const
const PtypeTable Ptype_Table
MultiInt promotion37_eval
const Square from() const
Ptype oldPtype() const
移動前のPtype, i.e., 成る手だった場合成る前
static int index5x5x(int rook, int bishop, int gold, int silver, int promoted, int king_x)
static int index2(int i0, int i1)
static CArray< int, 4284 > king_relative_weight
CArray< int, FEATURE_LIMIT > black_values
static CArray< int, 75 > effectstate_weight
void updatePromotion37(const NumEffectState &state)
void updateNonPawnAttackedPtypePairOne(const NumEffectState &state)
static bool initialized_flag
bool hasPieceOnStand(Player player, Ptype ptype) const
void updateSub(const NumEffectState &new_state, Move last_move)
const NumBitmapEffect effectSetAt(Square sq) const
const Square rotate180() const
static CArray< int, 81 *15 *10 > defense_relative
static int indexRelative(const Square king, const Ptype ptype, const Square pos)
void updateMain(const NumEffectState &new_state, Move last_move)
constexpr int sign(Player player)
CArray< int, 2 > attack5x5_progresses
CArray< MultiInt, 2 > non_pawn_ptype_attacked_pair_eval
void orMask(int index, mask_t val)
void updateAttack5x5PiecesAndState(const NumEffectState &state)
static const std::string & home(const std::string &initialize_if_first_invocation="")
compile時に指定されたディレクトリを返す.
CArray< int, 2 > non_pawn_ptype_attacked_pair
const Square square() const
Ptype capturePtype() const
const BoardMaskTable5x5 Board_Mask_Table5x5
constexpr Player indexToPlayer(int n)
int countEffect(Player pl) const
static std::string defaultFilename()
void fill(const T_simple &value=T_simple())
CArray< int, 2 > king_relative_attack
const PieceMask & piecesOnBoard(Player p) const
constexpr bool isPiece(Ptype ptype)
ptypeが空白やEDGEでないかのチェック
void updateAttack5x5Pieces(PieceMask, const NumEffectState &)
static CArray< int, 5625 > attack5x5_x_weight
bool hasEffectByPtypeStrict(Player attack, Square target) const
target に ptype の利きがあるか? 成不成を区別
const Piece findCheapAttack(Player P, Square square) const
bool isPromoted(Ptype ptype)
ptypeがpromote後の型かどうかのチェック
static CArray< int, 16 > promotion37_weight
const PieceMask effectedMask(Player pl) const
pl からの利きが(1つ以上)ある駒一覧
bool anyInRange(const BoardMask &mask) const
CArray< int, 2 > defenses
static CArray< int, 262144 > attacked_ptype_pair_weight
CArray< int, 2 > progresses
void updatePawnFacing(const NumEffectState &state)
static const CArray< Ptype, 7 > order
持駒の表示で良く使われる順番.
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に,ownerを反転する.
const mask_t getMask(int num) const
static CArray< int, 10125 > attack5x5_y_weight
static CArray< int, 81 *15 *10 > attack_relative
const Piece kingPiece() const
const mask_t selectBit() const
unpromote(PTYPE) の駒のbit だけ取り出す
NewProgress(const NumEffectState &state)
const PieceMask promotedPieces() const
int attack5x5Value(const NumEffectState &state) const
static CArray< int, 10 > pawn_facing_weight
void updateNonPawnAttackedPtypePair(const NumEffectState &state)
int getIndexMin(Ptype ptype) const
void updatePieceStand7(const NumEffectState &state)
bool operator==(const NewProgressData &l, const NewProgressData &r)
void promotion37One(const NumEffectState &state, int rank)
const BoardMask & mask(Square p) const
p中心の5x5 の範囲のbitを立てたもの, centeringなし
static CArray< int, 1125 > attack5x5_weight