My Project
progress.cc
Go to the documentation of this file.
1 #include "osl/progress.h"
2 #include "osl/eval/weights.h"
3 #include "osl/eval/midgame.h"
4 #include "osl/eval/minorPiece.h"
5 #include "osl/additionalEffect.h"
7 #include "osl/oslConfig.h"
8 #include <iostream>
9 #include <fstream>
10 
12 operator==(const NewProgressData& l, const NewProgressData& r)
13 {
14  return l.progresses == r.progresses
18  && l.defenses == r.defenses
19  && l.rook == r.rook && l.bishop == r.bishop && l.gold == r.gold
20  && l.silver == r.silver && l.promoted == r.promoted
25 }
26 
53 
54 bool osl::progress::ml::NewProgress::setUp(const char *filename)
55 {
56  if (initialized_flag)
57  return true;
58 
59  static CArray<int, 25> effect_weight;
60  static CArray<int, 225> effect_x_weight, effect_y_weight;
61  static CArray<int, 25> effect_defense_weight;
62  static CArray<int, 225> effect_per_effect;
63  static CArray<int, 225> effect_per_effect_defense;
64  static CArray<int, 2025> effect_per_effect_y, effect_per_effect_x;
65  std::ifstream is(filename);
66  int read_count = 0;
67 
68  osl::eval::ml::Weights weights(25);
69  for (size_t i = 0; i < weights.dimension(); ++i)
70  {
71  int val;
72  is >> val;
73  effect_weight[i] = val;
74  ++read_count;
75  }
76  for (size_t i = 0; i < 225; ++i)
77  {
78  int val;
79  is >> val;
80  effect_x_weight[i] = val;
81  ++read_count;
82  }
83  for (size_t i = 0; i < 225; ++i)
84  {
85  int val;
86  is >> val;
87  effect_y_weight[i] = val;
88  ++read_count;
89  }
90  weights.resetDimension(25);
91  for (size_t i = 0; i < weights.dimension(); ++i)
92  {
93  int val;
94  is >> val;
95  effect_defense_weight[i] = val;
96  ++read_count;
97  }
98  weights.resetDimension(225);
99  for (size_t i = 0; i < weights.dimension(); ++i)
100  {
101  int val;
102  is >> val;
103  effect_per_effect[i] = val;
104  ++read_count;
105  }
106  weights.resetDimension(225);
107  for (size_t i = 0; i < weights.dimension(); ++i)
108  {
109  int val;
110  is >> val;
111  effect_per_effect_defense[i] = val;
112  ++read_count;
113  }
114 
115  weights.resetDimension(2025);
116  for (size_t i = 0; i < weights.dimension(); ++i)
117  {
118  int val;
119  is >> val;
120  effect_per_effect_y[i] = val;
121  ++read_count;
122  }
123  weights.resetDimension(2025);
124  for (size_t i = 0; i < weights.dimension(); ++i)
125  {
126  int val;
127  is >> val;
128  effect_per_effect_x[i] = val;
129  ++read_count;
130  }
131  weights.resetDimension(Piece::SIZE);
132  for (size_t i = 0; i < weights.dimension(); ++i)
133  {
134  int val;
135  is >> val;
136  stand_weight[i] = val;
137  ++read_count;
138  }
139  weights.resetDimension(1125);
140  for (size_t i = 0; i < weights.dimension(); ++i)
141  {
142  int val;
143  is >> val;
144  attack5x5_weight[i] = val;
145  ++read_count;
146  }
147  weights.resetDimension(75);
148  for (size_t i = 0; i < weights.dimension(); ++i)
149  {
150  int val;
151  is >> val;
152  effectstate_weight[i] = val;
153  ++read_count;
154  }
155  weights.resetDimension(5625);
156  for (size_t i = 0; i < weights.dimension(); ++i)
157  {
158  int val;
159  is >> val;
160  attack5x5_x_weight[i] = val;
161  ++read_count;
162  }
163  weights.resetDimension(10125);
164  for (size_t i = 0; i < weights.dimension(); ++i)
165  {
166  int val;
167  is >> val;
168  attack5x5_y_weight[i] = val;
169  ++read_count;
170  }
171  weights.resetDimension(4284);
172  for (size_t i = 0; i < weights.dimension(); ++i)
173  {
174  int val;
175  is >> val;
176  king_relative_weight[i] = val;
177  ++read_count;
178  }
179  weights.resetDimension(262144);
180  for (size_t i = 0; i < weights.dimension(); ++i)
181  {
182  int val;
183  is >> val;
185  ++read_count;
186  }
187  weights.resetDimension(10);
188  for (size_t i = 0; i < weights.dimension(); ++i)
189  {
190  int val;
191  is >> val;
192  pawn_facing_weight[i] = val;
193  ++read_count;
194  }
195  weights.resetDimension(16);
196  for (size_t i = 0; i < weights.dimension(); ++i)
197  {
198  int val;
199  is >> val;
200  promotion37_weight[i] = val;
201  ++read_count;
202  }
203  weights.resetDimension(56);
204  for (size_t i = 0; i < weights.dimension(); ++i)
205  {
206  int val;
207  is >> val;
208  piecestand7_weight[i] = val;
209  ++read_count;
210  }
211  {
212  int val;
213  is >> val;
214  max_progress = val;
215  ++read_count;
216 #ifdef EVAL_QUAD
217  while (((max_progress/ProgressScale) % 3) && max_progress > 0)
218  --max_progress;
219 #endif
220  }
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;
225  const Square center = Centering5x3::adjustCenter(king);
226  const int min_x = center.x() - 2;
227  const int min_y = center.y() - 1;
228  int i=0;
229  for (int dx=0; dx<5; ++dx)
230  {
231  for (int dy=0; dy<3; ++dy,++i)
232  {
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;
237  attack_relative[index_a]=
238  effect_weight[index<BLACK>(king, target)] +
239  effect_x_weight[indexX<BLACK>(king, target)] +
240  effect_y_weight[indexY<BLACK>(king, target)];
241  defense_relative[index_d]=
242  effect_defense_weight[index<BLACK>(king, target)];
243  for(int count=0;count<=8;count++){
244  attack_relative[index_a+count+1]=
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)];
250  }
251  }
252  }
253  }
254  }
255  for(int king_x=1;king_x<=5;king_x++)
256  for(int promoted=0;promoted<=4;promoted++)
257  for(int silver=0;silver<=4;silver++)
258  for(int gold=0;gold<=4;gold++)
259  for(int bishop=0;bishop<=2;bishop++)
260  for(int rook=0;rook<=2;rook++){
261  int index0=promoted + 5 * (silver + 5 * (gold + 5 * (bishop + 3 * rook)));
262  int index1=king_x - 1 + 5 * (promoted + 5 * (silver + 5 * (gold + 5 * (bishop + 3 * rook))));
263  attack5x5_x_weight[index1]+=attack5x5_weight[index0];
264  }
265  for (int i=0; i<PTYPE_SIZE*2*PTYPE_SIZE; ++i)
266  for (int j=i+1; j<PTYPE_SIZE*2*PTYPE_SIZE; ++j) {
269  }
270  // set sum of [1..i] into [i], keep [0] as is.
271  for (int i=2; i<10; ++i)
273 
274  initialized_flag = static_cast<bool>(is);
275  if (!initialized_flag)
276  {
277  std::cerr << "Failed to load NewProgress data " << read_count
278  << " from file " << filename << std::endl;
279  }
280  return initialized_flag;
281 }
282 
284 {
285  return setUp(defaultFilename().c_str());
286 }
287 
289 {
290  std::string filename = OslConfig::home();
291  filename += "/data/progress.txt";
292  return filename;
293 }
294 
295 template <osl::Player P>
297  const NumEffectState &state, int &attack, int &defense)
298 {
299  const Square king = state.kingSquare<P>();
300  const Square center = Centering5x3::adjustCenter(king);
301  const int min_x = center.x() - 2;
302  const int min_y = center.y() - 1;
303 
304  attack = defense = 0;
305  Square kingRel=king;
306  if(P==WHITE){
307  kingRel=kingRel.rotate180();
308  }
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)
312  {
313  for (int dy=0; dy<3; ++dy)
314  {
315  const Square target(min_x+dx,min_y+dy);
316  const int attack_count =
317  state.countEffect(alt(P), target);
318  const int defense_count =
319  state.countEffect(P, target);
320  attack += attack_count *attack_relative[index_a]+
321  attack_relative[index_a+std::min(attack_count,8)+1];
322  defense +=
323  defense_count * defense_relative[index_a]+
324  defense_relative[index_a+std::min(defense_count,8)+1];
325  if(P==BLACK){
326  index_a+=10;
327  }
328  else{
329  index_a-=10;
330  }
331  }
332  }
333 }
334 
335 template <osl::Player P>
337  const NumEffectState &state)
338 {
339  const Square king = state.kingSquare<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;
345 
346  PieceMask mask;
347  for (int y = min_y; y <= max_y; ++y)
348  {
349  for (int x = min_x; x <= max_x; ++x)
350  {
351  const Square target(x, y);
352  const NumBitmapEffect effect = state.effectSetAt(target);
353  const int effect_diff =
354  effect.countEffect(alt(P)) - effect.countEffect(P);
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];
360  mask |= effect;
361  }
362  }
363  updateAttack5x5Pieces<P>(mask, state);
364 }
365 
366 template <osl::Player P>
368  PieceMask mask, const NumEffectState& state)
369 {
370  const Player attack = alt(P);
371  mask &= state.piecesOnBoard(attack);
372 
373  rook[attack] = mask.selectBit<ROOK>().countBit();
374  bishop[attack] = mask.selectBit<BISHOP>().countBit();
375  gold[attack] = mask.selectBit<GOLD>().countBit();
376  silver[attack] =
377  (mask & ~state.promotedPieces()).selectBit<SILVER>().countBit();
378  PieceMask promoted_pieces = mask & state.promotedPieces();
379  promoted_pieces.clearBit<ROOK>();
380  promoted_pieces.clearBit<BISHOP>();
381  promoted[attack] =
382  std::min(promoted_pieces.countBit(), 4);
383 }
384 
385 template <osl::Player P>
387  const NumEffectState &state) const
388 {
389  const Player attack = alt(P);
390  int king_x = state.kingSquare<P>().x();
391  if (king_x > 5)
392  king_x = 10 - king_x;
393  const int king_y = (P == BLACK ? state.kingSquare<P>().y() :
394  10 - state.kingSquare<P>().y());
395  return (attack5x5_x_weight[index5x5x(
396  rook[attack] + state.countPiecesOnStand<ROOK>(attack),
397  bishop[attack] + state.countPiecesOnStand<BISHOP>(attack),
398  gold[attack] + state.countPiecesOnStand<GOLD>(attack),
399  silver[attack] + state.countPiecesOnStand<SILVER>(attack),
400  promoted[attack], king_x)] +
401  attack5x5_y_weight[index5x5y(
402  rook[attack] + state.countPiecesOnStand<ROOK>(attack),
403  bishop[attack] + state.countPiecesOnStand<BISHOP>(attack),
404  gold[attack] + state.countPiecesOnStand<GOLD>(attack),
405  silver[attack] + state.countPiecesOnStand<SILVER>(attack),
406  promoted[attack], king_y)]);
407 }
408 
409 void
411  const NumEffectState &state)
412 {
413  const CArray<Square,2> kings = {{
414  state.kingSquare(BLACK),
415  state.kingSquare(WHITE),
416  }};
417  king_relative_attack.fill(0);
418  king_relative_defense.fill(0);
419  for (int i = 0; i < Piece::SIZE; ++i)
420  {
421  const Piece piece = state.pieceOf(i);
422  if (piece.ptype() == osl::KING || !piece.isOnBoard())
423  continue;
424  Player pl = piece.owner();
425  const int index_attack = indexRelative(piece.owner(), kings[alt(pl)],
426  piece);
427  const int index_defense = indexRelative(piece.owner(), kings[pl],
428  piece) + 2142;
429  king_relative_attack[pl] += king_relative_weight[index_attack];
430  king_relative_defense[pl] += king_relative_weight[index_defense];
431  }
432 }
433 
434 template <osl::Player Owner>
437 {
438  PieceMask attacked = state.effectedMask(alt(Owner)) & state.piecesOnBoard(Owner);
439  attacked.reset(state.kingPiece<Owner>().number());
440  mask_t ppawn = state.promotedPieces().getMask<PAWN>() & attacked.selectBit<PAWN>();
441  attacked.clearBit<PAWN>();
442  attacked.orMask(PtypeFuns<PAWN>::indexNum, ppawn);
443  PieceVector pieces;
444  while (attacked.any())
445  {
446  const Piece piece = state.pieceOf(attacked.takeOneBit());
447  pieces.push_back(piece);
448  }
449  typedef eval::ml::NonPawnAttackedPtypePair feature_t;
450  int result = 0;
451  MultiInt result_eval;
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)];
458  if (Owner == BLACK)
459  result_eval += feature_t::table[feature_t::index2(i0, i1)];
460  else
461  result_eval -= feature_t::table[feature_t::index2(i0, i1)];
462  }
463  }
464  non_pawn_ptype_attacked_pair[Owner] = result;
465  non_pawn_ptype_attacked_pair_eval[Owner] = result_eval;
466 }
467 
470 {
471  updateNonPawnAttackedPtypePairOne<BLACK>(state);
472  updateNonPawnAttackedPtypePairOne<WHITE>(state);
473 }
474 
476 updatePawnFacing(const NumEffectState& state)
477 {
478  PieceMask attacked = state.effectedMask(WHITE) & state.piecesOnBoard(BLACK);
479  mask_t pawn = attacked.selectBit<PAWN>()
480  & ~(state.promotedPieces().getMask<PAWN>());
481  int count = 0;
482  while (pawn.any()) {
483  const Piece p(state.pieceOf(pawn.takeOneBit()+PtypeFuns<PAWN>::indexNum*32));
484  if (state.hasEffectByPtypeStrict<PAWN>(WHITE, p.square()))
485  ++count;
486  }
487  pawn_facing = pawn_facing_weight[count];
488 }
489 
490 template <osl::Player P>
492 NewProgress::promotion37One(const NumEffectState& state, int rank)
493 {
494  typedef eval::ml::Promotion37 feature_t;
495  CArray<int,PTYPE_SIZE> count = {{ 0 }};
496  for (int x=1; x<=9; ++x) {
497  const Square target(x, rank);
498  if (! state[target].isEmpty())
499  continue;
500  int a = state.countEffect(P, target);
501  const int d = state.countEffect(alt(P), target);
502  if (a > 0 && a == d)
503  a += AdditionalEffect::hasEffect(state, target, P);
504  if (a <= d)
505  continue;
506  const Ptype ptype = state.findCheapAttack(P, target).ptype();
507  if (isPiece(ptype) && ! isPromoted(ptype))
508  count[ptype]++;
509  }
510  for (int p=PTYPE_BASIC_MIN; p<=PTYPE_MAX; ++p) {
511  if (count[p] > 0) {
512  promotion37 += promotion37_weight[p];
513  promotion37_eval += feature_t::table[p]*sign(P);
514  }
515  if (count[p] > 1) {
516  promotion37 += promotion37_weight[p-8]*(count[p]-1);
517  promotion37_eval += feature_t::table[p-8]*(sign(P)*(count[p]-1));
518  }
519  }
520 }
521 
523 updatePromotion37(const NumEffectState& state)
524 {
525  promotion37 = 0;
526  promotion37_eval = MultiInt();
527  promotion37One<BLACK>(state, 3);
528  promotion37One<WHITE>(state, 7);
529 }
530 
532 updatePieceStand7(const NumEffectState& state)
533 {
534  piecestand7 = 0;
535  for (int z=0; z<2; ++z) {
536  CArray<int,7> stand = {{ 0 }};
537  int filled = 0;
538  for (Ptype ptype: PieceStand::order)
539  if (state.hasPieceOnStand(indexToPlayer(z), ptype))
540  stand[filled++] = ptype-PTYPE_BASIC_MIN;
541  for (int i=0; i<std::min(7,filled+1); ++i)
542  piecestand7 += piecestand7_weight[stand[i] + 8*i];
543  }
544 }
545 
547  const NumEffectState &state)
548 {
549  assert(initialized_flag);
550 
551  progressOne<BLACK>(state,
552  progresses[BLACK],
553  defenses[WHITE]);
554  progressOne<WHITE>(state,
555  progresses[WHITE],
556  defenses[BLACK]);
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);
564  for (Ptype ptype: PieceStand::order)
565  {
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)
571  {
572  stand_progresses[WHITE] +=
573  stand_weight[Ptype_Table.getIndexMin(ptype) + j];
574  }
575  for (int j = 0; j < white_count; ++j)
576  {
577  stand_progresses[BLACK] +=
578  stand_weight[Ptype_Table.getIndexMin(ptype) + j];
579  }
580  }
581  updatePieceKingRelativeBonus(state);
582  updateNonPawnAttackedPtypePair(state);
583  updatePawnFacing(state);
584  updatePromotion37(state);
585  updatePieceStand7(state);
586 }
587 
588 template<osl::Player P>
589 inline
591  const NumEffectState &new_state,
592  Move last_move)
593 {
594  const Player altP=alt(P);
595  assert(new_state.turn()==altP);
596  assert(last_move.player()==P);
597  const Square kb = new_state.kingSquare<BLACK>(), kw = new_state.kingSquare<WHITE>();
598  const BoardMask mb = new_state.changedEffects(BLACK), mw = new_state.changedEffects(WHITE);
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)))
601  {
602  progressOne<WHITE>(new_state,progresses[WHITE],defenses[BLACK]);
603  }
604  if ((king_move && altP == WHITE) || mw.anyInRange(Board_Mask_Table5x3_Center.mask(kb)) || mb.anyInRange(Board_Mask_Table5x3_Center.mask(kb)))
605  {
606  progressOne<BLACK>(new_state,progresses[BLACK],defenses[WHITE]);
607  }
608 
609  const Ptype captured = last_move.capturePtype();
610 
611  if (last_move.isDrop())
612  {
613  const int count =
614  new_state.countPiecesOnStand(P, last_move.ptype()) + 1;
615  const int value =
616  stand_weight[Ptype_Table.getIndexMin(last_move.ptype()) + count - 1];
617  stand_progresses[altP] -= value;
618  }
619  else if (captured != PTYPE_EMPTY)
620  {
621  Ptype ptype = unpromote(captured);
622  const int count = new_state.countPiecesOnStand(P, ptype);
623  const int value =
624  stand_weight[(Ptype_Table.getIndexMin(ptype) + count - 1)];
625  stand_progresses[altP] += value;
626  }
627 
628  if (king_move)
629  {
630  updatePieceKingRelativeBonus(new_state);
631  }
632  else
633  {
634  const CArray<Square,2> kings = {{
635  new_state.kingSquare(BLACK),
636  new_state.kingSquare(WHITE),
637  }};
638  if (!last_move.isDrop())
639  {
640  const int index_attack =
641  indexRelative<P>(kings[altP],
642  last_move.oldPtype(), last_move.from());
643  const int index_defense =
644  indexRelative<P>(kings[P],
645  last_move.oldPtype(), last_move.from()) + 2142;
646  king_relative_attack[P] -=
647  king_relative_weight[index_attack];
648  king_relative_defense[P] -=
649  king_relative_weight[index_defense];
650  }
651  {
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];
662  }
663  if (captured != PTYPE_EMPTY)
664  {
665  const int index_attack =
666  indexRelative<altP>(kings[P],
667  captured, last_move.to());
668  const int index_defense =
669  indexRelative<altP>(kings[altP],
670  captured, last_move.to()) + 2142;
671  king_relative_attack[altP] -=
672  king_relative_weight[index_attack];
673  king_relative_defense[altP] -=
674  king_relative_weight[index_defense];
675  }
676  }
677  updateNonPawnAttackedPtypePair(new_state);
678  updatePawnFacing(new_state);
679  updatePromotion37(new_state);
680  updatePieceStand7(new_state);
681 }
682 
683 template<osl::Player P>
685  const NumEffectState &new_state,
686  Move last_move)
687 {
688  const Player altP=alt(P);
689  assert(new_state.turn()==altP);
690  if (last_move.isPass())
691  return;
692  const Square kb = new_state.kingSquare<BLACK>(), kw = new_state.kingSquare<WHITE>();
693  const BoardMask mb = new_state.changedEffects(BLACK), mw = new_state.changedEffects(WHITE);
694  const bool king_move = last_move.ptype() == KING;
695  const Ptype captured = last_move.capturePtype();
696 
697  if ((king_move && altP == BLACK) ||
699  mw.anyInRange(Board_Mask_Table5x5.mask(kw)))
700  {
701  updateAttack5x5PiecesAndState<WHITE>(new_state);
702  attack5x5_progresses[WHITE] =
703  attack5x5Value<WHITE>(new_state);
704  }
705  else if (altP == WHITE &&(last_move.isDrop() || captured != PTYPE_EMPTY))
706  {
707  attack5x5_progresses[WHITE] =
708  attack5x5Value<WHITE>(new_state);
709  }
710  if ((king_move && altP == WHITE) ||
711  mw.anyInRange(Board_Mask_Table5x5.mask(kb)) ||
713  {
714  updateAttack5x5PiecesAndState<BLACK>(new_state);
715  attack5x5_progresses[BLACK] =
716  attack5x5Value<BLACK>(new_state);
717  }
718  else if (altP == BLACK && (last_move.isDrop() || captured != PTYPE_EMPTY))
719  {
720  attack5x5_progresses[BLACK] =
721  attack5x5Value<BLACK>(new_state);
722  }
723  updateMain<P>(new_state, last_move);
724 }
725 
727 {
729 
730  info.black_values[NewProgressDebugInfo::ATTACK_5X3] = progresses[0];
732  info.black_values[NewProgressDebugInfo::ATTACK5X5] = attack5x5_progresses[0];
733  info.black_values[NewProgressDebugInfo::STAND] = stand_progresses[0];
734  info.black_values[NewProgressDebugInfo::EFFECT5X5] = effect_progresses[0];
735  info.black_values[NewProgressDebugInfo::KING_RELATIVE_ATTACK] = king_relative_attack[0];
736  info.black_values[NewProgressDebugInfo::KING_RELATIVE_DEFENSE] = king_relative_defense[0];
737  info.black_values[NewProgressDebugInfo::NON_PAWN_ATTACKED_PAIR] = non_pawn_ptype_attacked_pair[0];
738 
739  info.white_values[NewProgressDebugInfo::ATTACK_5X3] = progresses[1];
741  info.white_values[NewProgressDebugInfo::ATTACK5X5] = attack5x5_progresses[1];
742  info.white_values[NewProgressDebugInfo::STAND] = stand_progresses[1];
743  info.white_values[NewProgressDebugInfo::EFFECT5X5] = effect_progresses[1];
744  info.white_values[NewProgressDebugInfo::KING_RELATIVE_ATTACK] = king_relative_attack[1];
745  info.white_values[NewProgressDebugInfo::KING_RELATIVE_DEFENSE] = king_relative_defense[1];
746  info.white_values[NewProgressDebugInfo::NON_PAWN_ATTACKED_PAIR] = non_pawn_ptype_attacked_pair[1];
747 
748  return info;
749 }
750 
751 namespace osl
752 {
753  namespace progress
754  {
755  namespace ml
756  {
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);
759  }
760  }
761 }
762 
763 // ;;; Local Variables:
764 // ;;; mode:c++
765 // ;;; c-basic-offset:2
766 // ;;; End:
size_t size() const
Definition: container.h:243
void push_back(const T &e)
Definition: container.h:204
圧縮していない moveの表現 .
Definition: basic_type.h:1052
Ptype ptype() const
Definition: basic_type.h:1155
Player player() const
Definition: basic_type.h:1195
bool isDrop() const
Definition: basic_type.h:1150
bool isPass() const
Definition: basic_type.h:1092
Ptype capturePtype() const
Definition: basic_type.h:1180
Ptype oldPtype() const
移動前のPtype, i.e., 成る手だった場合成る前
Definition: basic_type.h:1174
const Square to() const
Definition: basic_type.h:1132
const Square from() const
Definition: basic_type.h:1125
利きを持つ局面
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 PieceMask & piecesOnBoard(Player p) const
const Piece findCheapAttack(Player P, Square square) const
const PieceMask promotedPieces() const
bool hasEffectByPtypeStrict(Player attack, Square target) const
target に ptype の利きがあるか? 成不成を区別
駒番号のビットセット.
Definition: pieceMask.h:21
const mask_t getMask(int num) const
Definition: pieceMask.h:59
void clearBit()
unpromote(PTYPE) の駒のbit を消す
Definition: pieceMask.h:74
void orMask(int index, mask_t val)
Definition: pieceMask.h:42
bool any() const
Definition: pieceMask.h:57
const mask_t selectBit() const
unpromote(PTYPE) の駒のbit だけ取り出す
Definition: pieceMask.h:66
void reset(int num)
Definition: pieceMask.h:54
static const CArray< Ptype, 7 > order
持駒の表示で良く使われる順番.
Ptype ptype() const
Definition: basic_type.h:821
const Square square() const
Definition: basic_type.h:832
Player owner() const
Definition: basic_type.h:963
int number() const
Definition: basic_type.h:828
bool isOnBoard() const
Definition: basic_type.h:985
static const int SIZE
Definition: basic_type.h:794
int getIndexMin(Ptype ptype) const
Definition: ptypeTable.h:88
bool hasPieceOnStand(Player player, Ptype ptype) const
Definition: simpleState.h:191
const Piece kingPiece() const
Definition: simpleState.h:83
Player turn() const
Definition: simpleState.h:220
const Piece pieceOf(int num) const
Definition: simpleState.h:76
Square kingSquare() const
Definition: simpleState.h:94
int countPiecesOnStand(Player pl, Ptype ptype) const
持駒の枚数を数える
Definition: simpleState.h:182
int y() const
将棋としてのY座標を返す.
Definition: basic_type.h:567
const Square rotate180() const
Definition: basic_type.h:613
int x() const
将棋としてのX座標を返す.
Definition: basic_type.h:563
const BoardMask & mask(Square p) const
p中心の5x3 の範囲のbitを立てたもの, centering
Definition: boardMask.h:133
const BoardMask & mask(Square p) const
p中心の5x5 の範囲のbitを立てたもの, centeringなし
Definition: boardMask.h:113
bool anyInRange(const BoardMask &mask) const
Definition: boardMask.h:57
現在の定義 (2005/3/4以降)
int countEffect(Player pl) const
static int index2(int i0, int i1)
Definition: minorPiece.h:1367
void updateMain(const NumEffectState &new_state, Move last_move)
Definition: progress.cc:590
static CArray< int, 5625 > attack5x5_x_weight
Definition: progress.h:83
void updatePawnFacing(const NumEffectState &state)
Definition: progress.cc:476
void promotion37One(const NumEffectState &state, int rank)
Definition: progress.cc:492
void updateAttack5x5PiecesAndState(const NumEffectState &state)
Definition: progress.cc:336
static CArray< int, 75 > effectstate_weight
Definition: progress.h:85
static void progressOne(const NumEffectState &state, int &attack, int &defense)
Definition: progress.cc:296
void updateSub(const NumEffectState &new_state, Move last_move)
Definition: progress.cc:684
static CArray< int, 16 > promotion37_weight
Definition: progress.h:91
void updateAttack5x5Pieces(PieceMask, const NumEffectState &)
Definition: progress.cc:367
static CArray< int, 10 > pawn_facing_weight
Definition: progress.h:90
static CArray< int, 81 *15 *10 > defense_relative
Definition: progress.h:87
NewProgress(const NumEffectState &state)
Definition: progress.cc:546
static std::string defaultFilename()
Definition: progress.cc:288
int attack5x5Value(const NumEffectState &state) const
Definition: progress.cc:386
void updateNonPawnAttackedPtypePairOne(const NumEffectState &state)
Definition: progress.cc:436
static CArray< int, 56 > piecestand7_weight
Definition: progress.h:92
void updatePromotion37(const NumEffectState &state)
Definition: progress.cc:523
static CArray< int, 262144 > attacked_ptype_pair_weight
Definition: progress.h:89
void updatePieceKingRelativeBonus(const NumEffectState &state)
Definition: progress.cc:410
void updatePieceStand7(const NumEffectState &state)
Definition: progress.cc:532
static CArray< int, 1125 > attack5x5_weight
Definition: progress.h:82
static CArray< int, 81 *15 *10 > attack_relative
Definition: progress.h:86
static CArray< int, Piece::SIZE > stand_weight
Definition: progress.h:81
void updateNonPawnAttackedPtypePair(const NumEffectState &state)
Definition: progress.cc:469
static CArray< int, 4284 > king_relative_weight
Definition: progress.h:88
static CArray< int, 10125 > attack5x5_y_weight
Definition: progress.h:84
NewProgressDebugInfo debugInfo() const
Definition: progress.cc:726
const BoardMaskTable5x5 Board_Mask_Table5x5
Definition: tables.cc:119
const BoardMaskTable5x3Center Board_Mask_Table5x3_Center
Definition: tables.cc:121
int max(Player p, int v1, int v2)
Definition: evalTraits.h:84
int min(Player p, int v1, int v2)
Definition: evalTraits.h:92
GeneralMask< mask_int_t > mask_t
Definition: mask.h:351
bool operator==(const NewProgressData &l, const NewProgressData &r)
Definition: progress.cc:12
Ptype
駒の種類を4ビットでコード化する
Definition: basic_type.h:84
@ PTYPE_MAX
Definition: basic_type.h:105
@ ROOK
Definition: basic_type.h:100
@ BISHOP
Definition: basic_type.h:99
@ PAWN
Definition: basic_type.h:95
@ KING
Definition: basic_type.h:93
@ PTYPE_EMPTY
Definition: basic_type.h:85
@ SILVER
Definition: basic_type.h:98
@ PTYPE_BASIC_MIN
Definition: basic_type.h:103
@ GOLD
Definition: basic_type.h:94
const PtypeTable Ptype_Table
Definition: tables.cc:97
const int PTYPE_SIZE
Definition: basic_type.h:107
constexpr Player indexToPlayer(int n)
Definition: basic_type.h:19
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す
Definition: basic_type.h:157
bool isPromoted(Ptype ptype)
ptypeがpromote後の型かどうかのチェック
Definition: basic_type.h:137
QuadInt MultiInt
Definition: midgame.h:13
constexpr int sign(Player player)
Definition: basic_type.h:23
Player
Definition: basic_type.h:8
@ WHITE
Definition: basic_type.h:10
@ BLACK
Definition: basic_type.h:9
constexpr bool isPiece(Ptype ptype)
ptypeが空白やEDGEでないかのチェック
Definition: basic_type.h:120
constexpr Player alt(Player player)
Definition: basic_type.h:13
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に,ownerを反転する.
Definition: basic_type.h:264
static const Square adjustCenter(Square src)
Definition: centering5x3.h:23
static const std::string & home(const std::string &initialize_if_first_invocation="")
compile時に指定されたディレクトリを返す.
Definition: oslConfig.cc:239
static bool hasEffect(const NumEffectState &, Square target, Player attack)
target に attack の追加利きが一つでもあるか. 相手の影利きが先にある場合は対象としない.
size_t dimension() const
Definition: weights.h:29
void resetDimension(size_t new_dim)
Definition: weights.cc:26
CArray< int, 2 > effect_progresses
Definition: progress.h:70
CArray< MultiInt, 2 > non_pawn_ptype_attacked_pair_eval
Definition: progress.h:67
CArray< int, 2 > non_pawn_ptype_attacked_pair
Definition: progress.h:72
CArray< int, 2 > king_relative_defense
Definition: progress.h:72
CArray< int, 2 > attack5x5_progresses
Definition: progress.h:69
CArray< int, 2 > king_relative_attack
Definition: progress.h:72
CArray< int, 2 > stand_progresses
Definition: progress.h:69
CArray< int, FEATURE_LIMIT > black_values
Definition: progress.h:61
CArray< int, FEATURE_LIMIT > white_values
Definition: progress.h:62