minorPiece.h
Go to the documentation of this file.
1 /* testEval.h
2  */
3 
4 #ifndef EVAL_ML_MINORPIECE_H
5 #define EVAL_ML_MINORPIECE_H
6 
7 #include "osl/eval/midgame.h"
8 #include "osl/eval/weights.h"
10 #include "osl/numEffectState.h"
11 #include <cstdlib>
12 namespace osl
13 {
14  namespace eval
15  {
16  namespace ml
17  {
18  class PawnDrop
19  {
20  public:
21  enum { ONE_DIM = 9, DIM = ONE_DIM * 2};
22  static void setUp(const Weights &weights,int stage);
23  };
24 
25  class PawnDropY
26  {
27  public:
28  enum { ONE_DIM = 81, DIM = ONE_DIM * 2};
29  static void setUp(const Weights &weights,int stage);
30  };
31 
33  {
34  friend class PawnDrop;
35  friend class PawnDropY;
36  friend class PawnDropX;
37  friend class PawnDropPawnStand;
38  friend class PawnDropPawnStandX;
39  friend class PawnDropPawnStandY;
40  friend class PawnDropNonDrop;
41  friend class PawnStateKingRelative;
42  private:
43  enum { BOTH_ON_BOARD, SELF_ON_BOARD, OPP_ON_BOARD, BOTH_ON_STAND };
44  static CArray<MultiInt, 9> attack_table, defense_table;
45  static CArray<MultiInt, 81> attack_y_table, defense_y_table;
52  template <Player Owner>
53  static int indexY(const Piece king, int x)
54  {
55  assert(Owner == king.owner());
56  const int king_y = (Owner == BLACK ?
57  king.square().y() : 10 - king.square().y());
58  return std::abs(x - king.square().x()) * 9 + king_y - 1;
59  }
60  static int index(const Square king, int x)
61  {
62  return std::abs(x - king.x());
63  }
64  template <bool Attack>
65  static int indexX(const Piece king, int x)
66  {
67  const int king_x = king.square().x();
68  const int target_x = (king_x > 5 ? 10 - king_x : king_x);
69  if (king_x >= 6 || (king.owner() == WHITE && king_x == 5))
70  x = 10 - x;
71  return (x - 1) * 5 + target_x - 1 + (Attack ? 0 : 45);
72  }
73  public:
74  static MultiInt value(
75  int attack_index, int defense_index,
76  int attack_index_y, int defense_index_y,
77  int attack_index_x, int defense_index_x)
78  {
79  return (attack_table[attack_index] +
80  defense_table[defense_index] +
81  attack_y_table[attack_index_y] +
82  defense_y_table[defense_index_y] +
83  x_table[attack_index_x] +
84  x_table[defense_index_x]);
85  }
87  int attack_index, int defense_index,
88  int attack_index_y, int defense_index_y,
89  int attack_index_x, int defense_index_x)
90  {
91  return (stand_table[attack_index] +
92  stand_table[defense_index + 9] +
93  y_stand_table[attack_index_y] +
94  y_stand_table[defense_index_y + 81] +
95  x_stand_table[attack_index_x] +
96  x_stand_table[defense_index_x]);
97  }
98  static MultiInt eval(const NumEffectState &state);
99  template<Player P>
101  Move moved,
102  MultiInt &last_value)
103  {
104  const Player altP=alt(P);
105  Ptype captured = moved.capturePtype();
106  if (moved.ptype() == KING ||
107  (moved.isDrop() && moved.ptype() == PAWN &&
108  !state.hasPieceOnStand<PAWN>(P)) ||
109  (captured != PTYPE_EMPTY &&
110  unpromote(captured) == PAWN &&
111  state.countPiecesOnStand<PAWN>(P) == 1))
112  {
113  return eval(state);
114  }
115 
116  MultiInt result(last_value);
117  const CArray<Square, 2> king_bw = {{ state.kingSquare<BLACK>(), state.kingSquare<WHITE>() }};
118  const CArray<Square, 2> kings = {{ king_bw[playerToIndex(P)], king_bw[playerToIndex(alt(P))] }};
119  const CArray<Piece, 2> king_piece = {{ state.kingPiece(P),
120  state.kingPiece(alt(P)) }};
121  if (moved.oldPtype() == PAWN)
122  {
123  if (moved.isDrop())
124  {
125  const int attack_index = index(kings[1], moved.to().x());
126  const int defense_index = index(kings[0], moved.to().x());
127  const int attack_index_x =
128  indexX<true>(king_piece[1], moved.to().x());
129  const int defense_index_x =
130  indexX<false>(king_piece[0], moved.to().x());
131 
132  const int attack_index_y = indexY<altP>(king_piece[1], moved.to().x());
133  const int defense_index_y = indexY<P>(king_piece[0], moved.to().x());
134  const int index_x = (moved.to().x() > 5 ? 10 -
135  moved.to().x() : moved.to().x());
136  if (state.isPawnMaskSet<altP>(moved.to().x()))
137  {
138  if (P == BLACK)
139  {
140  result -= drop_non_drop_table[index_x - 1 + 5];
141  result += drop_non_drop_table[index_x - 1];
142  result -=
143  state_king_relative_table[std::abs(king_bw[BLACK].x() - moved.to().x()) +
144  OPP_ON_BOARD * 9];
145  result +=
146  state_king_relative_table[std::abs(king_bw[WHITE].x() - moved.to().x()) +
147  SELF_ON_BOARD * 9];
148  }
149  else
150  {
151  result -= drop_non_drop_table[index_x - 1];
152  result += drop_non_drop_table[index_x - 1 + 5];
153  result -=
154  state_king_relative_table[std::abs(king_bw[BLACK].x() - moved.to().x()) +
155  SELF_ON_BOARD * 9];
156  result +=
157  state_king_relative_table[std::abs(king_bw[WHITE].x() - moved.to().x()) +
158  OPP_ON_BOARD * 9];
159  }
160  result +=
161  state_king_relative_table[std::abs(king_bw[BLACK].x() -
162  moved.to().x()) +
163  BOTH_ON_BOARD * 9];
164  result -=
165  state_king_relative_table[std::abs(king_bw[WHITE].x() -
166  moved.to().x()) +
167  BOTH_ON_BOARD * 9];
168  }
169  else
170  {
171  result -=
172  state_king_relative_table[std::abs(king_bw[BLACK].x() -
173  moved.to().x()) +
174  BOTH_ON_STAND * 9];
175  result +=
176  state_king_relative_table[std::abs(king_bw[WHITE].x() -
177  moved.to().x()) +
178  BOTH_ON_STAND * 9];
179  if (P == BLACK)
180  {
181  result += drop_non_drop_table[index_x - 1];
182  result -= drop_non_drop_table[index_x - 1 + 5];
183  result +=
184  state_king_relative_table[std::abs(king_bw[BLACK].x() - moved.to().x()) +
185  SELF_ON_BOARD * 9];
186  result -=
187  state_king_relative_table[std::abs(king_bw[WHITE].x() - moved.to().x()) +
188  OPP_ON_BOARD * 9];
189  }
190  else
191  {
192  result += drop_non_drop_table[index_x - 1 + 5];
193  result -= drop_non_drop_table[index_x - 1];
194  result +=
195  state_king_relative_table[std::abs(king_bw[BLACK].x() - moved.to().x()) +
196  OPP_ON_BOARD * 9];
197  result -=
198  state_king_relative_table[std::abs(king_bw[WHITE].x() - moved.to().x()) +
199  SELF_ON_BOARD * 9];
200  }
201  }
202  if (P == BLACK)
203  {
204  result -= value(attack_index, defense_index, attack_index_y,
205  defense_index_y, attack_index_x, defense_index_x);
206  if (state.hasPieceOnStand<PAWN>(P))
207  {
208  result -= standValue(attack_index, defense_index, attack_index_y,
209  defense_index_y, attack_index_x, defense_index_x);
210  }
211  }
212  else
213  {
214  result += value(attack_index, defense_index, attack_index_y,
215  defense_index_y, attack_index_x, defense_index_x);
216  if (state.hasPieceOnStand<PAWN>(P))
217  {
218  result += standValue(attack_index, defense_index, attack_index_y,
219  defense_index_y, attack_index_x, defense_index_x);
220  }
221  }
222  }
223  if (moved.isPromotion())
224  {
225  const int attack_index = index(kings[1], moved.to().x());
226  const int defense_index = index(kings[0], moved.to().x());
227  const int attack_index_x =
228  indexX<true>(king_piece[1], moved.to().x());
229  const int defense_index_x =
230  indexX<false>(king_piece[0], moved.to().x());
231  const int attack_index_y = indexY<altP>(king_piece[1], moved.to().x());
232  const int defense_index_y = indexY<P>(king_piece[0], moved.to().x());
233  if (P == BLACK)
234  {
235  result += value(attack_index, defense_index, attack_index_y,
236  defense_index_y, attack_index_x, defense_index_x);
237  if (state.hasPieceOnStand<PAWN>(P))
238  {
239  result += standValue(attack_index, defense_index, attack_index_y,
240  defense_index_y, attack_index_x, defense_index_x);
241  }
242  }
243  else
244  {
245  result -= value(attack_index, defense_index, attack_index_y,
246  defense_index_y, attack_index_x, defense_index_x);
247  if (state.hasPieceOnStand<PAWN>(P))
248  {
249  result -= standValue(attack_index, defense_index, attack_index_y,
250  defense_index_y, attack_index_x, defense_index_x);
251  }
252  }
253  const int index_x = (moved.to().x() > 5 ? 10 -
254  moved.to().x() : moved.to().x());
255  if (state.isPawnMaskSet<altP>(moved.to().x()))
256  {
257  result -=
258  state_king_relative_table[std::abs(king_bw[BLACK].x() - moved.to().x()) +
259  BOTH_ON_BOARD * 9];
260  result +=
261  state_king_relative_table[std::abs(king_bw[WHITE].x() - moved.to().x()) +
262  BOTH_ON_BOARD * 9];
263  if (P == BLACK)
264  {
265  result += drop_non_drop_table[index_x - 1 + 5];
266  result -= drop_non_drop_table[index_x - 1];
267  result +=
268  state_king_relative_table[std::abs(king_bw[BLACK].x() - moved.to().x()) +
269  OPP_ON_BOARD * 9];
270  result -=
271  state_king_relative_table[std::abs(king_bw[WHITE].x() - moved.to().x()) +
272  SELF_ON_BOARD * 9];
273  }
274  else
275  {
276  result += drop_non_drop_table[index_x - 1];
277  result -= drop_non_drop_table[index_x - 1 + 5];
278  result +=
279  state_king_relative_table[std::abs(king_bw[BLACK].x() - moved.to().x()) +
280  SELF_ON_BOARD * 9];
281  result -=
282  state_king_relative_table[std::abs(king_bw[WHITE].x() - moved.to().x()) +
283  OPP_ON_BOARD * 9];
284  }
285  }
286  else
287  {
288  result +=
289  state_king_relative_table[std::abs(king_bw[BLACK].x() - moved.to().x()) +
290  BOTH_ON_STAND * 9];
291  result -=
292  state_king_relative_table[std::abs(king_bw[WHITE].x() - moved.to().x()) +
293  BOTH_ON_STAND * 9];
294  if (captured == PAWN)
295  {
296  result -=
297  state_king_relative_table[std::abs(king_bw[BLACK].x() - moved.to().x()) +
298  BOTH_ON_BOARD * 9];
299  result +=
300  state_king_relative_table[std::abs(king_bw[WHITE].x() - moved.to().x()) +
301  BOTH_ON_BOARD * 9];
302  }
303  else
304  {
305  if (P == BLACK)
306  {
307  result -= drop_non_drop_table[index_x - 1];
308  result += drop_non_drop_table[index_x - 1 + 5];
309  result -=
310  state_king_relative_table[std::abs(king_bw[BLACK].x() - moved.to().x()) +
311  SELF_ON_BOARD * 9];
312  result +=
313  state_king_relative_table[std::abs(king_bw[WHITE].x() - moved.to().x()) +
314  OPP_ON_BOARD * 9];
315  }
316  else
317  {
318  result -= drop_non_drop_table[index_x - 1 + 5];
319  result += drop_non_drop_table[index_x - 1];
320  result -=
321  state_king_relative_table[std::abs(king_bw[BLACK].x() - moved.to().x()) +
322  OPP_ON_BOARD * 9];
323  result +=
324  state_king_relative_table[std::abs(king_bw[WHITE].x() - moved.to().x()) +
325  SELF_ON_BOARD * 9];
326  }
327  }
328  }
329  }
330  }
331 
332  if (captured == PAWN)
333  {
334  const int attack_index = index(kings[0], moved.to().x());
335  const int defense_index = index(kings[1], moved.to().x());
336  const int attack_index_x =
337  indexX<true>(king_piece[0], moved.to().x());
338  const int defense_index_x =
339  indexX<false>(king_piece[1], moved.to().x());
340  const int attack_index_y = indexY<P>(king_piece[0], moved.to().x());
341  const int defense_index_y = indexY<altP>(king_piece[1], moved.to().x());
342  if (P == BLACK)
343  {
344  result -= value(attack_index, defense_index, attack_index_y,
345  defense_index_y, attack_index_x, defense_index_x);
346  if (state.hasPieceOnStand<PAWN>(alt(P)))
347  {
348  result -= standValue(attack_index, defense_index, attack_index_y,
349  defense_index_y, attack_index_x, defense_index_x);
350  }
351  }
352  else
353  {
354  result += value(attack_index, defense_index, attack_index_y,
355  defense_index_y, attack_index_x, defense_index_x);
356  if (state.hasPieceOnStand<PAWN>(alt(moved.player())))
357  {
358  result += standValue(attack_index, defense_index, attack_index_y,
359  defense_index_y, attack_index_x, defense_index_x);
360  }
361  }
362  if (!(moved.ptype() == PPAWN && moved.isPromotion())) // promote is already handled above
363  {
364  const int index_x =
365  (moved.to().x() > 5 ? 10 - moved.to().x() : moved.to().x());
366  if (state.isPawnMaskSet<P>(moved.to().x()))
367  {
368  result -=
369  state_king_relative_table[std::abs(king_bw[BLACK].x() -
370  moved.to().x()) +
371  BOTH_ON_BOARD * 9];
372  result +=
373  state_king_relative_table[std::abs(king_bw[WHITE].x() -
374  moved.to().x()) +
375  BOTH_ON_BOARD * 9];
376  if (P == BLACK)
377  {
378  result += drop_non_drop_table[index_x - 1];
379  result -= drop_non_drop_table[index_x - 1 + 5];
380  result +=
381  state_king_relative_table[std::abs(king_bw[BLACK].x() -
382  moved.to().x()) +
383  SELF_ON_BOARD * 9];
384  result -=
385  state_king_relative_table[std::abs(king_bw[WHITE].x() -
386  moved.to().x()) +
387  OPP_ON_BOARD * 9];
388  }
389  else
390  {
391  result += drop_non_drop_table[index_x - 1 + 5];
392  result -= drop_non_drop_table[index_x - 1];
393  result +=
394  state_king_relative_table[std::abs(king_bw[BLACK].x() -
395  moved.to().x()) +
396  OPP_ON_BOARD * 9];
397  result -=
398  state_king_relative_table[std::abs(king_bw[WHITE].x() -
399  moved.to().x()) +
400  SELF_ON_BOARD * 9];
401  }
402  }
403  else
404  {
405  if (P == BLACK)
406  {
407  result -= drop_non_drop_table[index_x - 1 + 5];
408  result += drop_non_drop_table[index_x - 1];
409  result -=
410  state_king_relative_table[std::abs(king_bw[BLACK].x() - moved.to().x()) +
411  OPP_ON_BOARD * 9];
412  result +=
413  state_king_relative_table[std::abs(king_bw[WHITE].x() - moved.to().x()) +
414  SELF_ON_BOARD * 9];
415  }
416  else
417  {
418  result -= drop_non_drop_table[index_x - 1];
419  result += drop_non_drop_table[index_x - 1 + 5];
420  result -=
421  state_king_relative_table[std::abs(king_bw[BLACK].x() - moved.to().x()) +
422  SELF_ON_BOARD * 9];
423  result +=
424  state_king_relative_table[std::abs(king_bw[WHITE].x() - moved.to().x()) +
425  OPP_ON_BOARD * 9];
426  }
427  result +=
428  state_king_relative_table[std::abs(king_bw[BLACK].x() - moved.to().x()) +
429  BOTH_ON_STAND * 9];
430  result -=
431  state_king_relative_table[std::abs(king_bw[WHITE].x() - moved.to().x()) +
432  BOTH_ON_STAND * 9];
433  }
434  }
435  }
436  return result;
437  }
438  };
439 
440  class PawnDropX
441  {
442  public:
443  enum { ONE_DIM = 90, DIM = ONE_DIM * EvalStages };
444  static void setUp(const Weights &weights);
445  };
446 
448  {
449  public:
450  enum { ONE_DIM = 18, DIM = ONE_DIM * EvalStages };
451  static void setUp(const Weights &weights);
452  };
454  {
455  public:
456  enum { ONE_DIM = 90, DIM = ONE_DIM * EvalStages };
457  static void setUp(const Weights &weights);
458  };
460  {
461  public:
462  enum { ONE_DIM = 162, DIM = ONE_DIM * EvalStages };
463  static void setUp(const Weights &weights);
464  };
465 
467  {
468  public:
469  enum { ONE_DIM = 10, DIM = ONE_DIM * EvalStages };
470  static void setUp(const Weights &weights);
471  };
472 
474  {
475  public:
476  enum { ONE_DIM = 36, DIM = ONE_DIM * EvalStages };
477  static void setUp(const Weights &weights);
478  };
479 
481  {
482  public:
483  enum { DIM = 1 };
484  private:
485  static MultiInt weight;
486  public:
487  static void setUp(const Weights &weights,int stage);
488  static MultiInt eval(const NumEffectState &state, int black_pawn_count)
489  {
490  if (black_pawn_count > 9 && !state.hasPieceOnStand<PAWN>(WHITE))
491  return -weight;
492  else if (black_pawn_count < 9 && !state.hasPieceOnStand<PAWN>(BLACK))
493  return weight;
494 
495  return MultiInt();
496  }
497  };
498 
500  {
501  static int index(Player P, Square pos)
502  {
503  return (P == BLACK ? (pos.y() - 1) : (9 - pos.y()));
504  }
505  static bool cantAdvance(const NumEffectState &state, const Piece pawn)
506  {
507  return cantAdvance(state, pawn.ptypeO(), pawn.square());
508  }
509  static bool cantAdvance(const NumEffectState &state,
510  const PtypeO ptypeO, const Square position)
511  {
512  assert(getPtype(ptypeO) == PAWN);
513  return state.pieceAt(Board_Table.nextSquare(getOwner(ptypeO),
514  position,
515  U)).isOnBoardByOwner(getOwner(ptypeO));
516  }
517  };
519  {
520  template <osl::Player P>
521  static void adjust(int index, MultiInt& values);
522  template<Player P>
523  static void evalWithUpdateBang(const NumEffectState &state, Move moved,
524  MultiInt& last_value);
525  };
526 
528  {
529  public:
530  enum { DIM = 9 };
531  private:
533  friend struct PawnAdvanceAll;
534  public:
535  static void setUp(const Weights &weights,int stage);
536  static MultiInt eval(const NumEffectState &state);
537  };
538 
540  {
541  public:
542  static MultiInt eval(const NumEffectState &state);
543  protected:
544  template <Player P>
545  static int indexRetreat(Square pos)
546  {
547  return (P == BLACK ? (pos.y() - 1) : (9 - pos.y()));
548  }
549  template<Player P>
550  static bool canRetreat(const NumEffectState &state,
551  const Piece silver);
552  template <Player P>
553  static MultiInt evalOne(const NumEffectState &state,
554  const Piece silver,
555  const CArray<Square, 2> &kings)
556  {
557  MultiInt result;
558  if (!canRetreat<P>(state,silver))
559  {
560  result += retreat_table[indexRetreat<P>(silver.square())];
561  }
562  const Square up =
564  if (up.isOnBoard())
565  {
566  const Piece up_piece = state.pieceAt(up);
567  if (up_piece.isEmpty() &&
568  (state.hasEffectByPtypeStrict<PAWN>(alt(P), up) ||
569  !state.isPawnMaskSet<alt(P)>(silver.square().x())))
570  {
571  const int x_diff =
572  std::abs(kings[P].x() - silver.square().x());
573  const int y_diff = (P == BLACK ?
574  silver.square().y() - kings[P].y() :
575  kings[P].y() - silver.square().y());
576  result += head_table[x_diff + 9 * (y_diff + 8)];
577  }
578  }
579  return result;
580  }
583  };
584 
586  {
587  public:
588  enum { ONE_DIM = 153, DIM = ONE_DIM * EvalStages };
589  static void setUp(const Weights &weights);
590  };
591 
593  {
594  public:
595  enum { DIM = 9 };
596  static void setUp(const Weights &weights,int stage);
597  };
598 
600  {
601  public:
602  static MultiInt eval(const NumEffectState &state);
603  protected:
604  template <Player P>
605  static int indexRetreat(Square pos)
606  {
607  return (P == BLACK ? (pos.y() - 1) : (9 - pos.y()));
608  }
609  static int indexSideX(Square pos)
610  {
611  return (pos.x() > 5 ? 9 - pos.x() : pos.x() - 1);
612  }
613  template <Player P>
614  static int indexSideY(Square pos)
615  {
616  return (P == BLACK ? (pos.y() - 1) : (9 - pos.y())) + 5;
617  }
618  template<Player P>
619  static bool canRetreat(const NumEffectState &state,
620  const Piece gold);
621  template<Player P>
622  static bool canMoveToSide(const NumEffectState &state,
623  const Piece gold)
624  {
627  // check effect is from lesser pieces?
628  if ((!r.isOnBoard() ||
629  state.pieceAt(r).isOnBoardByOwner(gold.owner()) ||
630  state.hasEffectAt(alt(gold.owner()), r)) &&
631  (!l.isOnBoard() ||
632  state.pieceAt(l).isOnBoardByOwner(gold.owner()) ||
633  state.hasEffectAt(alt(gold.owner()), l)))
634  {
635  return false;
636  }
637  return true;
638  }
639  template <Player P>
640  static MultiInt evalOne(const NumEffectState &state,
641  const Piece gold,
642  const CArray<Square, 2> &kings)
643  {
644  assert(P==gold.owner());
645  MultiInt result;
646  if (!canRetreat<P>(state, gold))
647  {
648  result += retreat_table[indexRetreat<P>(gold.square())];
649  }
650  if (!canMoveToSide<P>(state, gold))
651  {
652  result += side_table[indexSideX(gold.square())] +
653  side_table[indexSideY<P>(gold.square())];
654  }
655  const Square uur = gold.square().neighbor<P,UUR>();
656  const Square uul = gold.square().neighbor<P,UUL>();
657  if ((state.pieceAt(uul).isEmpty() && !state.hasEffectAt(P, uul))
658  || (state.pieceAt(uur).isEmpty() && !state.hasEffectAt(P, uur)))
659  {
660  assert(state.kingSquare(gold.owner()) == kings[gold.owner()]);
661  const Square king = kings[P];
662  const int x_diff = std::abs(king.x() - gold.square().x());
663  const int y_diff = (P == BLACK ?
664  gold.square().y() - king.y() :
665  king.y() - gold.square().y());
666  result += knight_table[x_diff + 9 * (y_diff + 8)];
667  }
668  return result;
669  }
673  };
674 
676  {
677  public:
678  enum { ONE_DIM = 153, DIM = ONE_DIM * EvalStages };
679  static void setUp(const Weights &weights);
680  };
681 
682  class GoldRetreat : public GoldFeatures
683  {
684  public:
685  enum { DIM = 9 };
686  static void setUp(const Weights &weights,int stage);
687  };
688 
689  class GoldSideMove : public GoldFeatures
690  {
691  public:
692  enum { ONE_DIM = 14, DIM = ONE_DIM * EvalStages };
693  static void setUp(const Weights &weights);
694  };
695 
697  {
698  public:
699  enum { DIM = 9 };
700  private:
702  static int index(Player P, Square pos)
703  {
704  return (P == BLACK ? (pos.y() - 1) : (9 - pos.y()));
705  }
706  template<Player P>
707  static bool cantAdvance(const NumEffectState &state,
708  const Piece knight);
709  public:
710  static void setUp(const Weights &weights,int stage);
711  static MultiInt eval(const NumEffectState &state);
712  };
713 
714  class AllGold
715  {
716  public:
717  enum { DIM = 1 };
718  static void setUp(const Weights &weights,int stage);
719  static MultiInt eval(int black_major_count)
720  {
721  if (black_major_count == 4)
722  return weight;
723  else if (black_major_count == 0)
724  return -weight;
725 
726  return MultiInt();
727  }
728  private:
729  static MultiInt weight;
730  };
731 
732  class PtypeY
733  {
734  public:
735  enum { DIM = PTYPE_SIZE * 9 };
736  static void setUp(const Weights &weights,int stage);
737  static MultiInt eval(const NumEffectState &state);
738  template<Player P>
739  static MultiInt evalWithUpdate(const NumEffectState &, Move moved,
740  MultiInt const& last_value);
741  private:
743  static int index(const Piece piece)
744  {
745  return index(piece.owner(), piece.ptype(), piece.square());
746  }
747  static int index(const Player player, const Ptype ptype, const Square pos)
748  {
749  const int y = (player == BLACK ? pos.y() : 10 - pos.y()) - 1;
750  return ptype * 9 + y;
751  }
752  };
753 
754  class PtypeX
755  {
756  public:
757  enum { DIM = PTYPE_SIZE * 5 };
758  static void setUp(const Weights &weights,int stage);
759  static MultiInt eval(const NumEffectState &state);
760  template<Player P>
761  static MultiInt evalWithUpdate(const NumEffectState &, Move moved,
762  MultiInt const& last_value);
763  private:
765  static int index(const Piece piece)
766  {
767  return index(piece.owner(), piece.ptype(), piece.square());
768  }
769  static int index(const Player, const Ptype ptype, const Square pos)
770  {
771  const int x = (pos.x() > 5 ? 10 - pos.x() : pos.x()) - 1;
772  return ptype * 5 + x;
773  }
774  };
775 
777  {
778  friend class KnightCheckY;
779  public:
780  enum { DIM = 1 };
781  static void setUp(const Weights &weights,int stage);
782  static MultiInt eval(const NumEffectState &state);
783  template <Player Defense>
784  static bool canCheck(const NumEffectState &state)
785  {
786  const Square king = state.kingSquare<Defense>();
787  const Player offense = alt(Defense);
788  const Square ul =
790  const Square ur =
792  if (ul.isOnBoard())
793  {
794  const Piece p = state.pieceAt(ul);
795  if (!state.hasEffectAt<Defense>(ul) &&
796  ((p.isEmpty() && state.hasPieceOnStand<KNIGHT>(offense)) ||
797  (!p.isOnBoardByOwner<offense>() &&
798  state.hasEffectByPtypeStrict<KNIGHT>(offense, ul))))
799  return true;
800  }
801  if (ur.isOnBoard())
802  {
803  const Piece p = state.pieceAt(ur);
804  if (!state.hasEffectAt<Defense>(ur) &&
805  ((p.isEmpty() && state.hasPieceOnStand<KNIGHT>(offense)) ||
806  (!p.isOnBoardByOwner<offense>() &&
807  state.hasEffectByPtypeStrict<KNIGHT>(offense, ur))))
808  return true;
809  }
810  return false;
811  }
812  static MultiInt value(int index_y) { return weight + y_table[index_y]; }
813  private:
814  static MultiInt weight;
815  template <Player King>
816  static int indexY(int y)
817  {
818  return (King == BLACK ? y - 1 : 9 - y) ;
819  }
821  };
822 
824  {
825  public:
826  enum { ONE_DIM = 9, DIM = ONE_DIM * EvalStages };
827  static void setUp(const Weights &weights);
828  };
829 
831  {
833  public:
834  enum { ONE_DIM = 9, DIM = ONE_DIM * EvalStages};
835  static void setUp(const Weights &weights);
836  static MultiInt eval(const NumEffectState &state);
837  private:
840  };
841 
843  {
844  public:
845  enum { ONE_DIM = 9 * 16, DIM = ONE_DIM * EvalStages};
846  static void setUp(const Weights &weights);
847  private:
848  };
849 
851  {
852  friend class PawnPtypeOPtypeOY;
853  public:
854  enum { ONE_DIM = 1024, DIM = ONE_DIM * EvalStages };
855  static void setUp(const Weights &weights);
856  static MultiInt eval(const NumEffectState &state);
857  template<Player P>
858  static MultiInt evalWithUpdate(const NumEffectState &state,
859  Move moved,
860  const CArray2d<int, 2, 9> &pawns,
861  const MultiInt &last_value);
862  private:
863  static int index(Player P, PtypeO up, PtypeO up_up)
864  {
865  if (P == WHITE)
866  {
867  up = altIfPiece(up);
868  up_up = altIfPiece(up_up);
869  }
870  return (up - PTYPEO_MIN) * 32 + (up_up - PTYPEO_MIN);
871  }
872  static int indexY(Player P, PtypeO up, PtypeO up_up, int y)
873  {
874  const int y_index = (P == BLACK ? y - 1 : 9 - y);
875  return index(P, up, up_up) + 1024 * y_index;
876  }
879  };
880 
882  {
883  friend class PromotedMinorPiecesY;
884  public:
885  enum { ONE_DIM = 9, DIM = ONE_DIM * EvalStages };
886  static void setUp(const Weights &weights);
887  static MultiInt eval(const NumEffectState &state);
888  static MultiInt evalWithUpdate(
889  const NumEffectState &state,
890  Move moved,
891  const MultiInt &last_values);
892  template <int Sign>
893  static void adjust(int index, int index_attack, int index_defense,
894  MultiInt &result);
895  private:
896  template <Player P>
897  static void evalOne(const NumEffectState &state,
898  const PieceMask promoted,
899  MultiInt &result);
900  template <bool attack, Player owner>
901  static int indexY(const Square king, int x_diff)
902  {
903  const int y = (owner == BLACK ? king.y() : 10 - king.y());
904  return x_diff + (y - 1) * 9 + (attack ? 0 : 81);
905  }
908  };
910  {
912  public:
913  enum { ONE_DIM = 64, DIM = ONE_DIM * EvalStages };
914  static void setUp(const Weights &weights);
915  static void eval(const NumEffectState &state, MultiIntPair& out);
916  template<Player P>
917  static void evalWithUpdateBang(
918  const NumEffectState &state,
919  Move moved,
920  const CArray<PieceMask, 2> &effected_mask,
921  MultiIntPair &last_value_and_out);
922  template <int Sign>
923  static void adjust(int black_turn_king_attack,
924  int black_turn_king_defense,
925  int white_turn_king_attack,
926  int white_turn_king_defense,
927  MultiIntPair &result);
928  private:
929  static int index(bool same_turn, bool has_support, Ptype ptype)
930  {
931  return ptype + (same_turn ? 0 : PTYPE_SIZE) +
932  (has_support ? 0 : PTYPE_SIZE * 2);
933  }
934  template <bool Attack>
935  static int indexK(Square king, bool same_turn, bool has_support,
936  Square position, Player owner, Ptype ptype)
937  {
938  const int x_diff = std::abs(position.x() - king.x());
939  const int y_diff = (owner == BLACK ?
940  position.y() - king.y() :
941  king.y() - position.y());
942  return ((ptype + (same_turn ? 0 : PTYPE_SIZE) +
943  (has_support ? 0 : PTYPE_SIZE * 2)) * 9 + x_diff) * 17 +
944  y_diff + 8 + (Attack ? 0 : 9792);
945  }
946  template <bool Attack>
947  static int indexK(Square king, bool same_turn, bool has_support,
948  Piece piece)
949  {
950  return indexK<Attack>(king, same_turn, has_support,
951  piece.square(), piece.owner(),
952  piece.ptype());
953  }
954 
955  template <Player Attacked>
956  static void updateEffectChanged(
957  const NumEffectState &state,
958  const CArray<PieceMask, 2> &effected_mask,
959  const CArray<PieceMask, 2> &new_mask,
960  int moved_piece_number,
961  MultiIntPair &result)
962  {
963  CArray<Square, 2> kings = {{ state.kingSquare<BLACK>(),
964  state.kingSquare<WHITE>() }};
965  // old without, new with
966  PieceMask black_old = (~effected_mask[alt(Attacked)]) & new_mask[alt(Attacked)] & state.piecesOnBoard(Attacked);
967  black_old.reset(moved_piece_number);
968  while (black_old.any())
969  {
970  const Piece piece = state.pieceOf(black_old.takeOneBit());
971  const bool has_support =
972  new_mask[Attacked].test(piece.number());
973  const int index_king_black_turn_attack =
974  indexK<true>(kings[alt(Attacked)], Attacked == BLACK, has_support, piece);
975  const int index_king_white_turn_attack =
976  indexK<true>(kings[alt(Attacked)], Attacked == WHITE, has_support, piece);
977  const int index_king_black_turn_defense =
978  indexK<false>(kings[Attacked], Attacked == BLACK, has_support, piece);
979  const int index_king_white_turn_defense =
980  indexK<false>(kings[Attacked], Attacked == WHITE, has_support, piece);
981  adjust<Attacked == BLACK ? 1 : -1>(
982  index_king_black_turn_attack, index_king_black_turn_defense,
983  index_king_white_turn_attack, index_king_white_turn_defense,
984  result);
985  }
986 
987  // old with, new without
988  PieceMask black_new = effected_mask[alt(Attacked)] & (~new_mask[alt(Attacked)]) & state.piecesOnBoard(Attacked);
989  black_new.reset(moved_piece_number);
990  while (black_new.any())
991  {
992  const Piece piece = state.pieceOf(black_new.takeOneBit());
993  const bool has_support =
994  effected_mask[Attacked].test(piece.number());
995  const int index_king_black_turn_attack =
996  indexK<true>(kings[alt(Attacked)], Attacked == BLACK, has_support, piece);
997  const int index_king_white_turn_attack =
998  indexK<true>(kings[alt(Attacked)], Attacked == WHITE, has_support, piece);
999  const int index_king_black_turn_defense =
1000  indexK<false>(kings[Attacked], Attacked == BLACK, has_support, piece);
1001  const int index_king_white_turn_defense =
1002  indexK<false>(kings[Attacked], Attacked == WHITE, has_support, piece);
1003  adjust<Attacked == BLACK ? -1 : 1>(
1004  index_king_black_turn_attack, index_king_black_turn_defense,
1005  index_king_white_turn_attack, index_king_white_turn_defense,
1006  result);
1007  }
1008  // old with, new with, self with, self without
1009  PieceMask black_self_old = effected_mask[alt(Attacked)] & new_mask[alt(Attacked)] &
1010  effected_mask[Attacked] & (~new_mask[Attacked]) & state.piecesOnBoard(Attacked);
1011  black_self_old.reset(moved_piece_number);
1012  while (black_self_old.any())
1013  {
1014  const Piece piece = state.pieceOf(black_self_old.takeOneBit());
1015  const int index_king_black_turn_attack =
1016  indexK<true>(kings[alt(Attacked)], Attacked == BLACK, false, piece);
1017  const int index_king_white_turn_attack =
1018  indexK<true>(kings[alt(Attacked)], Attacked == WHITE, false, piece);
1019  const int index_king_black_turn_defense =
1020  indexK<false>(kings[Attacked], Attacked == BLACK, false, piece);
1021  const int index_king_white_turn_defense =
1022  indexK<false>(kings[Attacked], Attacked == WHITE, false, piece);
1023  const int index_king_black_turn_attack_old =
1024  indexK<true>(kings[alt(Attacked)], Attacked == BLACK, true, piece);
1025  const int index_king_white_turn_attack_old =
1026  indexK<true>(kings[alt(Attacked)], Attacked == WHITE, true, piece);
1027  const int index_king_black_turn_defense_old =
1028  indexK<false>(kings[Attacked], Attacked == BLACK, true, piece);
1029  const int index_king_white_turn_defense_old =
1030  indexK<false>(kings[Attacked], Attacked == WHITE, true, piece);
1031  adjust<Attacked == BLACK ? -1 : 1>(
1032  index_king_black_turn_attack_old, index_king_black_turn_defense_old,
1033  index_king_white_turn_attack_old, index_king_white_turn_defense_old,
1034  result);
1035  adjust<Attacked == BLACK ? 1 : -1>(
1036  index_king_black_turn_attack, index_king_black_turn_defense,
1037  index_king_white_turn_attack, index_king_white_turn_defense,
1038  result);
1039  }
1040  // old with, new with, self without, self with
1041  PieceMask black_self_new = effected_mask[alt(Attacked)] & new_mask[alt(Attacked)] &
1042  (~effected_mask[Attacked]) & new_mask[Attacked] & state.piecesOnBoard(Attacked);
1043  black_self_new.reset(moved_piece_number);
1044  while (black_self_new.any())
1045  {
1046  const Piece piece = state.pieceOf(black_self_new.takeOneBit());
1047  const int index_king_black_turn_attack =
1048  indexK<true>(kings[alt(Attacked)], Attacked == BLACK, true, piece);
1049  const int index_king_white_turn_attack =
1050  indexK<true>(kings[alt(Attacked)], Attacked == WHITE, true, piece);
1051  const int index_king_black_turn_defense =
1052  indexK<false>(kings[Attacked], Attacked == BLACK, true, piece);
1053  const int index_king_white_turn_defense =
1054  indexK<false>(kings[Attacked], Attacked == WHITE, true, piece);
1055  const int index_king_black_turn_attack_old =
1056  indexK<true>(kings[alt(Attacked)], Attacked == BLACK, false, piece);
1057  const int index_king_white_turn_attack_old =
1058  indexK<true>(kings[alt(Attacked)], Attacked == WHITE, false, piece);
1059  const int index_king_black_turn_defense_old =
1060  indexK<false>(kings[Attacked], Attacked == BLACK, false, piece);
1061  const int index_king_white_turn_defense_old =
1062  indexK<false>(kings[Attacked], Attacked == WHITE, false, piece);
1063 
1064  adjust<Attacked == BLACK ? -1 : 1>(
1065  index_king_black_turn_attack_old, index_king_black_turn_defense_old,
1066  index_king_white_turn_attack_old, index_king_white_turn_defense_old,
1067  result);
1068  adjust<Attacked == BLACK ? 1 : -1>(
1069  index_king_black_turn_attack, index_king_black_turn_defense,
1070  index_king_white_turn_attack, index_king_white_turn_defense,
1071  result);
1072  }
1073  }
1076  };
1077 
1079  {
1080  public:
1081  enum { ONE_DIM = 19584, DIM = ONE_DIM * EvalStages};
1082  static void setUp(const Weights &weights);
1083  };
1084 
1086  {
1087  public:
1088  enum { ONE_DIM = 162, DIM = ONE_DIM * EvalStages };
1089  static void setUp(const Weights &weights);
1090  };
1091 
1093  {
1094  public:
1095  enum { ONE_DIM = 9216, DIM = ONE_DIM * EvalStages };
1096  static void setUp(const Weights &weights);
1097  };
1098 
1100  {
1101  public:
1102  enum { ONE_DIM = 1024, DIM = ONE_DIM * EvalStages};
1103  static void setUp(const Weights &weights);
1104  static void eval(const NumEffectState &state,
1105  CArray<PieceMask, 40> &attacked_mask,
1106  MultiIntPair& out);
1107  template<Player P>
1108  static void evalWithUpdateBang(
1109  const NumEffectState &state,
1110  Move moved,
1111  const CArray<PieceMask, 2> &effected_mask,
1112  CArray<PieceMask, 40> &attacked_mask,
1113  MultiIntPair &last_value_and_out);
1114  private:
1115  static int index(bool same_turn, bool has_support, Ptype ptype,
1116  Ptype attack_ptype)
1117  {
1118  return (ptype + (same_turn ? 0 : PTYPE_SIZE) +
1119  (has_support ? 0 : PTYPE_SIZE * 2)) * 16 + attack_ptype;
1120  }
1121  template <int Sign>
1122  static void adjust(int black, int white, MultiIntPair &result)
1123  {
1124  if(Sign>0){
1125  result[BLACK] += table[black];
1126  result[WHITE] += table[white];
1127  }
1128  else{
1129  result[BLACK] -= table[black];
1130  result[WHITE] -= table[white];
1131  }
1132  }
1133  template <bool Plus>
1134  static void evalOnePiece(const Player player,
1135  const Ptype ptype,
1136  const Ptype attack_ptype,
1137  bool with_support,
1138  MultiIntPair &result)
1139  {
1140  const int index_black_turn = index(BLACK == player, with_support,
1141  ptype, attack_ptype);
1142  const int index_white_turn = index(WHITE == player, with_support,
1143  ptype, attack_ptype);
1144  if (Plus)
1145  adjust<1>(index_black_turn, index_white_turn, result);
1146  else
1147  adjust<-1>(index_black_turn, index_white_turn, result);
1148  }
1149  template <Player P>
1150  static void updateChanged(const NumEffectState &state,
1151  const Piece p,
1152  Move moved,
1153  int captured_number,
1154  const CArray<PieceMask, 2> &effected_mask,
1155  const CArray<PieceMask, 2> &new_mask,
1156  CArray<PieceMask, 40> &attacked_mask,
1157  MultiIntPair &result)
1158  {
1159  // old without, new with
1160  PieceMask old = (~effected_mask[alt(P)]) & new_mask[alt(P)] & state.piecesOnBoard(P);
1161  old.reset(p.number());
1162  while (old.any())
1163  {
1164  const Piece piece = state.pieceOf(old.takeOneBit());
1165  const bool has_support =
1166  new_mask[P].test(piece.number());
1167  PieceMask attacking =
1168  state.effectSetAt(piece.square()) &
1169  state.piecesOnBoard(alt(P));
1170  attacked_mask[piece.number()] = attacking;
1171  while (attacking.any())
1172  {
1173  const Piece attack = state.pieceOf(attacking.takeOneBit());
1174  evalOnePiece<P == BLACK>(P, piece.ptype(), attack.ptype(),
1175  has_support, result);
1176  }
1177  }
1178  // old with, new without
1179  PieceMask new_without = effected_mask[alt(P)] & (~new_mask[alt(P)]) & state.piecesOnBoard(P);
1180  new_without.reset(p.number());
1181  while (new_without.any())
1182  {
1183  const Piece piece = state.pieceOf(new_without.takeOneBit());
1184  const bool has_support =
1185  effected_mask[P].test(piece.number());
1186  PieceMask attacking = attacked_mask[piece.number()];
1187  if (moved.isPromotion() && attacking.test(p.number()))
1188  {
1189  evalOnePiece<P != BLACK>(P, piece.ptype(), moved.oldPtype(),
1190  has_support, result);
1191  attacking.reset(p.number());
1192  }
1193  if (captured_number != -1 && attacking.test(captured_number))
1194  {
1195  evalOnePiece<P != BLACK>(P, piece.ptype(), moved.capturePtype(),
1196  has_support, result);
1197  attacking.reset(captured_number);
1198  }
1199  while (attacking.any())
1200  {
1201  const Piece attack = state.pieceOf(attacking.takeOneBit());
1202  evalOnePiece<P != BLACK>(P, piece.ptype(), attack.ptype(),
1203  has_support, result);
1204  }
1205  }
1206  // old with, new with, self with, self without
1207  PieceMask self_old = effected_mask[alt(P)] &
1208  new_mask[alt(P)] &
1209  effected_mask[P] & (~new_mask[P]) & state.piecesOnBoard(P);
1210  self_old.reset(p.number());
1211  while (self_old.any())
1212  {
1213  const Piece piece = state.pieceOf(self_old.takeOneBit());
1214  PieceMask old_attacking = attacked_mask[piece.number()];
1215  if (moved.isPromotion() && old_attacking.test(p.number()))
1216  {
1217  evalOnePiece<P != BLACK>(P, piece.ptype(), moved.oldPtype(),
1218  true, result);
1219  old_attacking.reset(p.number());
1220  }
1221  if (captured_number != -1 && old_attacking.test(captured_number))
1222  {
1223  evalOnePiece<P != BLACK>(P, piece.ptype(), moved.capturePtype(),
1224  true, result);
1225  old_attacking.reset(captured_number);
1226  }
1227  while (old_attacking.any())
1228  {
1229  const Piece attack = state.pieceOf(old_attacking.takeOneBit());
1230  evalOnePiece<P != BLACK>(P, piece.ptype(), attack.ptype(),
1231  true, result);
1232  }
1233  PieceMask new_attacking = state.effectSetAt(piece.square())
1234  & state.piecesOnBoard(alt(P));
1235  attacked_mask[piece.number()] = new_attacking;
1236  while (new_attacking.any())
1237  {
1238  const Piece attack = state.pieceOf(new_attacking.takeOneBit());
1239  evalOnePiece<P == BLACK>(P, piece.ptype(), attack.ptype(),
1240  false, result);
1241  }
1242  }
1243  // old with, new with, self without, self with
1244  PieceMask self_new_with = effected_mask[alt(P)] &
1245  new_mask[alt(P)] &
1246  (~effected_mask[P]) & new_mask[P] & state.piecesOnBoard(P);
1247  self_new_with.reset(p.number());
1248  while (self_new_with.any())
1249  {
1250  const Piece piece = state.pieceOf(self_new_with.takeOneBit());
1251  PieceMask old_attacking = attacked_mask[piece.number()];
1252  if (moved.isPromotion() && old_attacking.test(p.number()))
1253  {
1254  evalOnePiece<P != BLACK>(P, piece.ptype(), moved.oldPtype(),
1255  false, result);
1256  old_attacking.reset(p.number());
1257  }
1258  if (captured_number != -1 && old_attacking.test(captured_number))
1259  {
1260  evalOnePiece<P != BLACK>(P, piece.ptype(), moved.capturePtype(),
1261  false, result);
1262  old_attacking.reset(captured_number);
1263  }
1264  while (old_attacking.any())
1265  {
1266  const Piece attack = state.pieceOf(old_attacking.takeOneBit());
1267  evalOnePiece<P != BLACK>(P, piece.ptype(), attack.ptype(),
1268  false, result);
1269  }
1270  PieceMask new_attacking = state.effectSetAt(piece.square())
1271  & state.piecesOnBoard(alt(P));
1272  attacked_mask[piece.number()] = new_attacking;
1273  while (new_attacking.any())
1274  {
1275  const Piece attack = state.pieceOf(new_attacking.takeOneBit());
1276  evalOnePiece<P == BLACK>(P, piece.ptype(), attack.ptype(),
1277  true, result);
1278  }
1279  }
1280  // old with, new with, support unchanged, attack changed
1281  PieceMask effected = effected_mask[P];
1282  effected ^= new_mask[P];
1283  effected = ~effected;
1284  PieceMask attack_changed = effected_mask[alt(P)] &
1285  new_mask[alt(P)] &
1286  effected & state.piecesOnBoard(P) &
1287  state.effectedChanged(alt(P));
1288  attack_changed.reset(p.number());
1289  while (attack_changed.any())
1290  {
1291  const Piece attacked = state.pieceOf(attack_changed.takeOneBit());
1292  PieceMask attack_old_mask = attacked_mask[attacked.number()];
1293  PieceMask attack_new_mask = state.effectSetAt(attacked.square()) & state.piecesOnBoard(alt(P));
1294  if (captured_number != -1 &&
1295  attack_old_mask.test(captured_number))
1296  {
1297  evalOnePiece<P != BLACK>(P, attacked.ptype(),
1298  moved.capturePtype(),
1299  new_mask[P].test(attacked.number()),
1300  result);
1301  attack_old_mask.reset(captured_number);
1302  }
1303  if (moved.isPromotion() &&
1304  attack_old_mask.test(p.number()))
1305  {
1306  evalOnePiece<P != BLACK>(P, attacked.ptype(),
1307  moved.oldPtype(),
1308  new_mask[P].test(attacked.number()),
1309  result);
1310  attack_old_mask.reset(p.number());
1311  }
1312  if (moved.isPromotion() &&
1313  attack_new_mask.test(p.number()))
1314  {
1315  evalOnePiece<P == BLACK>(P, attacked.ptype(),
1316  moved.ptype(),
1317  new_mask[P].test(attacked.number()),
1318  result);
1319  attack_new_mask.reset(p.number());
1320  }
1321  PieceMask gone = attack_old_mask & (~attack_new_mask);
1322  while (gone.any())
1323  {
1324  const Piece attacking = state.pieceOf(gone.takeOneBit());
1325  evalOnePiece<P != BLACK>(P, attacked.ptype(),
1326  attacking.ptype(),
1327  effected_mask[P].test(attacked.number()),
1328  result);
1329  }
1330  PieceMask added = (~attack_old_mask) & attack_new_mask;
1331  while (added.any())
1332  {
1333  const Piece attacking = state.pieceOf(added.takeOneBit());
1334  evalOnePiece<P == BLACK>(P, attacked.ptype(),
1335  attacking.ptype(),
1336  new_mask[P].test(attacked.number()),
1337  result);
1338  }
1339 
1340  attacked_mask[attacked.number()] = state.effectSetAt(attacked.square()) & state.piecesOnBoard(alt(P));
1341  }
1342  }
1343 
1345  };
1346 
1348  {
1349  public:
1350  enum {
1353  };
1354  static void setUp(const Weights &weights);
1355  template <Player Owner>
1356  static MultiInt evalOne(const NumEffectState &state);
1357  static MultiInt eval(const NumEffectState &state);
1358  static int index1(const NumEffectState &state, Piece piece)
1359  {
1360  const Ptype attack_ptype
1361  = state.findCheapAttack(alt(piece.owner()), piece.square()).ptype();
1362  const bool has_support = state.hasEffectAt(piece.owner(),
1363  piece.square());
1364  return (piece.ptype() +
1365  (has_support ? 0 : PTYPE_SIZE)) * PTYPE_SIZE + attack_ptype;
1366  }
1367  static int index2(int i0, int i1)
1368  {
1369  return i0 * PTYPE_SIZE * 2 * PTYPE_SIZE + i1;
1370  }
1372  };
1373 
1375  {
1376  friend class PtypeCountXY;
1377  friend class PtypeCountXYAttack;
1378  public:
1379  enum { ONE_DIM = 160, DIM = ONE_DIM * EvalStages };
1380  static void setUp(const Weights &weights);
1381  template<osl::Player P,osl::Ptype T>
1382  static MultiInt evalPlayerPtype(const CArray2d<int, 2, PTYPE_SIZE> &ptype_count,
1383  const CArray2d<int, 2, PTYPE_SIZE> &ptype_board_count,
1384  const osl::CArray<int,2> &kings_x,
1385  const osl::CArray<int,2> &kings_y);
1386  static void eval(const NumEffectState &state,
1387  const CArray2d<int, 2, PTYPE_SIZE> &ptype_count,
1388  const CArray2d<int, 2, PTYPE_SIZE> &ptype_board_count,
1389  MultiInt &out);
1390  template<Player P>
1391  static void evalWithUpdateBang(
1392  const NumEffectState &state,
1393  Move last_move,
1394  CArray2d<int, 2, PTYPE_SIZE> &ptype_count,
1395  CArray2d<int, 2, PTYPE_SIZE> &ptype_board_count,
1396  MultiInt &last_value_and_out,unsigned int &ptypeo_mask);
1397  private:
1398  static int indexCount(Ptype ptype, int count)
1399  {
1400  return Ptype_Table.getIndexMin(unpromote(ptype)) +
1401  (isPromoted(ptype) ? 40 : 0) +
1402  count - 1;
1403  }
1404  static int indexBoardCount(Ptype ptype, int count)
1405  {
1406  return Ptype_Table.getIndexMin(unpromote(ptype)) +
1407  (isPromoted(ptype) ? 40 : 0) + 80 +
1408  count - 1;
1409  }
1410  static int indexCountX(Ptype ptype, int count, int x)
1411  {
1412  return x - 1 + 5 *
1413  (Ptype_Table.getIndexMin(unpromote(ptype)) +
1414  (isPromoted(ptype) ? 40 : 0) +
1415  count - 1);
1416  }
1417  static int indexCountY(Ptype ptype, int count, int y)
1418  {
1419  return y - 1 + 9 *
1420  (Ptype_Table.getIndexMin(unpromote(ptype)) +
1421  (isPromoted(ptype) ? 40 : 0) +
1422  count - 1) + 800;
1423  }
1424  static int indexBoardCountX(Ptype ptype, int count, int x)
1425  {
1426  return x - 1 + 5 *
1427  (Ptype_Table.getIndexMin(unpromote(ptype)) +
1428  (isPromoted(ptype) ? 40 : 0) +
1429  count - 1) + 400;
1430  }
1431  static int indexBoardCountY(Ptype ptype, int count, int y)
1432  {
1433  return y - 1 + 9 *
1434  (Ptype_Table.getIndexMin(unpromote(ptype)) +
1435  (isPromoted(ptype) ? 40 : 0) +
1436  count - 1) + 720 + 800;
1437  }
1438  template<Ptype T>
1439  static int indexCount(int count)
1440  {
1441  return PtypeTraits<T>::indexMin+ (isPromoted(T) ? 40 : 0) +
1442  count - 1;
1443  }
1444  template<Ptype T>
1445  static int indexBoardCount(int count)
1446  {
1447  return PtypeTraits<T>::indexMin+(isPromoted(T) ? 40 : 0)+ 80 +
1448  count - 1;
1449  }
1450  template<Ptype T>
1451  static int indexCountX(int count, int x)
1452  {
1453  return x - 1 + 5 *
1454  (PtypeTraits<T>::indexMin+(isPromoted(T) ? 40 : 0) +
1455  count - 1);
1456  }
1457  template<Ptype T>
1458  static int indexCountY(int count, int y)
1459  {
1460  return y - 1 + 9 *
1461  (PtypeTraits<T>::indexMin+(isPromoted(T) ? 40 : 0) +
1462  count - 1) + 800;
1463  }
1464  template<Ptype T>
1465  static int indexBoardCountX(int count, int x)
1466  {
1467  return x - 1 + 5 *
1468  (PtypeTraits<T>::indexMin+(isPromoted(T) ? 40 : 0) +
1469  count - 1) + 400;
1470  }
1471  template<Ptype T>
1472  static int indexBoardCountY(int count, int y)
1473  {
1474  return y - 1 + 9 *
1475  (PtypeTraits<T>::indexMin+(isPromoted(T) ? 40 : 0) +
1476  count - 1) + 720 + 800;
1477  }
1478  static MultiInt valueAll(Ptype ptype, int count, int my_king_x, int my_king_y, int op_king_x, int op_king_y)
1479  {
1480  assert(count>0);
1481  return
1482  xy_table_diff[indexCountX(ptype, count, my_king_x)]+
1483  xy_table_diff[indexCountY(ptype, count, my_king_y)]+
1484  xy_attack_table_diff[indexCountX(ptype,count, op_king_x)]+
1485  xy_attack_table_diff[indexCountY(ptype, count, op_king_y)];
1486  }
1487  static MultiInt valueBoardAll(Ptype ptype, int count, int my_king_x, int my_king_y, int op_king_x, int op_king_y)
1488  {
1489  assert(count>0);
1490  return
1491  xy_table_diff[indexBoardCountX(ptype, count, my_king_x)]+
1492  xy_table_diff[indexBoardCountY(ptype, count, my_king_y)]+
1493  xy_attack_table_diff[indexBoardCountX(ptype,count, op_king_x)]+
1494  xy_attack_table_diff[indexBoardCountY(ptype, count, op_king_y)];
1495  }
1501  };
1502 
1504  {
1505  public:
1506  enum { ONE_DIM = 2240, DIM = ONE_DIM * EvalStages };
1507  static void setUp(const Weights &weights);
1508  };
1510  {
1511  public:
1512  enum { ONE_DIM = 2240, DIM = ONE_DIM * EvalStages };
1513  static void setUp(const Weights &weights);
1514  };
1515 
1517  {
1518  public:
1519  enum { ONE_DIM = 9792, DIM = ONE_DIM * EvalStages };
1520  static void setUp(const Weights &weights);
1521  static MultiInt eval(const NumEffectState &state);
1522  private:
1523  static int index(Player p, Square pos, Square king,
1524  PtypeO ptypeO, bool attack)
1525  {
1526  const int y_diff = (p == BLACK ? king.y() - pos.y() : pos.y() - king.y());
1527  const int x_diff = std::abs(king.x() - pos.x());
1528  if (p == WHITE)
1529  {
1530  ptypeO = alt(ptypeO);
1531  }
1532  return y_diff + 8 + x_diff * 17 + (ptypeO - PTYPEO_MIN) * 17 * 9 +
1533  (attack ? 0 : 4896);
1534  }
1536  };
1537 
1539  {
1540  public:
1541  enum { ONE_DIM = 1440, DIM = ONE_DIM * EvalStages };
1542  static MultiInt eval(const NumEffectState &state,
1543  const CArray2d<int, 2, 9> &pawns);
1544  template<Player P>
1545  static void evalWithUpdateBang(const NumEffectState &state,
1546  Move moved,
1547  const CArray2d<int, 2, 9> &pawns,
1548  MultiInt& last_value);
1549  static void setUp(const Weights &weights);
1550  private:
1551  static int index(Player player, Ptype ptype, int y, int pawn_y)
1552  {
1553  if (player == WHITE)
1554  {
1555  y = 10 - y;
1556  pawn_y = (10 - pawn_y) % 10;
1557  }
1558  return pawn_y + 10 * (y - 1 + 9 * ptype);
1559  }
1561  };
1562 
1564  {
1566  public:
1567  enum { ONE_DIM = 1215, DIM = ONE_DIM * EvalStages };
1568  static void setUp(const Weights &weights);
1569  static MultiInt eval(const NumEffectState &state,
1570  const CArray2d<int, 2, 3> &gs_count);
1571  private:
1572  template <Player Defense>
1573  static int index(const Square king, int distance0, int count)
1574  {
1575  int king_x = (king.x() > 5 ? 10 - king.x() : king.x());
1576  int king_y = (Defense == WHITE ? 10 - king.y() : king.y());
1577  return king_x - 1 + 5 * (king_y - 1+ 9 * (distance0 + 3 * count));
1578  }
1579  template <Player P>
1580  static MultiInt evalOne(const NumEffectState &state,
1581  const CArray2d<int, 2, 3> &gs_count);
1582  template <Player Defense>
1583  static int indexCombination(const Square king, int count0,
1584  int count1, int count2)
1585  {
1586  int king_x = (king.x() > 5 ? 10 - king.x() : king.x());
1587  int king_y = (Defense == WHITE ? 10 - king.y() : king.y());
1588  return king_x + 5 * (king_y + 9 * (std::min(5,count0) + 6 *
1589  (std::min(5,count1) + 6 * std::min(5,count2))));
1590  }
1593  };
1594 
1596  {
1597  public:
1598  enum { ONE_DIM = 9720, DIM = ONE_DIM * EvalStages };
1599  static void setUp(const Weights &weights);
1600  private:
1601  };
1602 
1604  {
1605  public:
1606  enum { ONE_DIM = 8192, DIM = ONE_DIM * EvalStages };
1607  static void setUp(const Weights &weights);
1608  static MultiInt eval(unsigned int ptypeo_mask);
1609  private:
1610  template <Player P>
1611  static MultiInt evalOne(unsigned int ptypeo_mask)
1612  {
1613  int index = 0;
1614  if (P==BLACK) index=((ptypeo_mask>>19)&0x1fc0)|((ptypeo_mask>>18)&0x3f);
1615  else index=((ptypeo_mask>>3)&0x1fc0)|((ptypeo_mask>>2)&0x3f);
1616  if (P == BLACK)
1617  return table[index];
1618  else
1619  return -table[index];
1620  }
1622  };
1624  {
1625  static std::pair<int,int> matchRook(const NumEffectState& state, Piece rook,
1626  const CArray<bool,2>& has_silver,
1627  Square& silver_drop);
1628  static std::pair<int,int> matchGold(const NumEffectState& state, Piece gold,
1629  const CArray<bool,2>& has_silver,
1630  Square& silver_drop);
1631  public:
1632  enum { ONE_DIM = 5*2, DIM = ONE_DIM * EvalStages };
1633  static void setUp(const Weights &weights);
1634  static MultiIntPair eval(const NumEffectState& state,
1635  CArray<std::pair<Square,int>,2>& silver_drop);
1637  };
1639  {
1640  public:
1641  enum {
1642  DROP_DIM = PTYPE_SIZE*PTYPE_SIZE,
1643  ONE_DIM = 2*DROP_DIM*2, DIM = ONE_DIM * EvalStages
1644  };
1645  static const Square isBishopForkSquare(const NumEffectState& state, Player defense, const Square a, const Square b, bool maybe_empty=false);
1646  static const Square isRookForkSquare(const NumEffectState& state, Player defense, const Square a, const Square b);
1647  static int bishopIndex(Ptype a, Ptype b) { return a * PTYPE_SIZE + b; }
1648  static int rookIndex(Ptype a, Ptype b) { return bishopIndex(a,b) + DROP_DIM; }
1649  static void setUp(const Weights &weights);
1650  template <Player Defense>
1651  static MultiIntPair evalOne(const NumEffectState& state, const PieceVector& target,
1652  std::pair<Square,int>& bishop_drop,
1653  std::pair<Square,int>& rook_drop);
1654  static MultiIntPair eval(const NumEffectState& state,
1655  CArray<std::pair<Square,int>,2>& bishop_drop,
1656  CArray<std::pair<Square,int>,2>& rook_drop);
1658  private:
1659  static const Square findDropInLine
1660  (const NumEffectState& state, Player defense,
1661  const Square a, const Square b, Piece king);
1662  static bool testCenter(const NumEffectState& state, Player defense,
1663  const Square a, const Square b, Piece king,
1664  Square center, bool maybe_empty=false);
1665  };
1666 
1668  {
1669  public:
1670  enum {
1671  DROP_DIM = PTYPE_SIZE*PTYPE_SIZE, ONE_DIM = DROP_DIM*2*2,
1672  DIM = ONE_DIM * EvalStages
1673  };
1674  static void setUp(const Weights &weights);
1675  template <Player Defense>
1676  static MultiIntPair evalOne(const NumEffectState& state,
1677  bool has_knight,
1678  BoardMask& knight_fork_squares,
1679  std::pair<Square,int>& knight_drop);
1680  static MultiIntPair eval(const NumEffectState& state,
1681  CArray<BoardMask,2>& knight_fork_squares,
1682  CArray<std::pair<Square,int>,2>& knight_drop);
1683  template <Player P>
1684  static MultiIntPair evalWithUpdate(const NumEffectState& state,
1685  Move moved,
1686  CArray<BoardMask,2>& knight_fork_squares,
1687  CArray<std::pair<Square,int>,2>& knight_drop);
1689 
1690  static bool isForkSquare(const NumEffectState& state, Player defense,
1691  int y, int x0, int x1);
1692  static int index(Ptype a, Ptype b)
1693  {
1694  return a * PTYPE_SIZE + b;
1695  }
1696  static bool isTarget(Ptype ptype)
1697  {
1698  ptype = unpromote(ptype);
1699  return ptype != PAWN && ptype != LANCE && ptype != KNIGHT;
1700  }
1701  private:
1702  template <Player P, Player Defense>
1703  static void updateSquares
1704  (const NumEffectState& state, Move moved,
1705  BoardMask& knight_fork_squares);
1706  template <osl::Player Defense>
1707  static MultiIntPair accumulate
1708  (const NumEffectState& state,
1709  bool has_knight, const BoardMask& knight_fork_squares,
1710  std::pair<Square,int>& knight_drop);
1711  };
1712 
1714  {
1715  public:
1716  enum { ONE_DIM = 1, DIM = ONE_DIM*EvalStages };
1717  static void setUp(const Weights &weights);
1718  static MultiInt eval(const NumEffectState &state);
1719  private:
1721  };
1722 
1724  {
1725  public:
1727  static void setUp(const Weights &weights);
1728  static MultiInt eval(const NumEffectState &state);
1729  template<Player P>
1730  static MultiInt evalOne(const NumEffectState &state, int rank);
1731  template<Player P>
1732  static MultiInt evalWithUpdate(const NumEffectState &, Move moved,
1733  MultiInt const& last_value);
1734 
1736  };
1737  }
1738  }
1739 }
1740 
1741 #endif // EVAL_ML_MINORPIECE_H
1742 // ;;; Local Variables:
1743 // ;;; mode:c++
1744 // ;;; c-basic-offset:2
1745 // ;;; End:
static int rookIndex(Ptype a, Ptype b)
Definition: minorPiece.h:1648
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す ...
Definition: basic_type.h:157
CArray< PiecePair::IndexTable, 10 > & y_table
Definition: piecePair.cc:36
static MultiInt standValue(int attack_index, int defense_index, int attack_index_y, int defense_index_y, int attack_index_x, int defense_index_x)
Definition: minorPiece.h:86
static CArray< MultiInt, 162 > y_table
Definition: minorPiece.h:907
bool isOnBoardByOwner() const
piece がプレイヤーPの持ち物でかつボード上にある駒の場合は true.
Definition: basic_type.h:852
static int indexCountY(Ptype ptype, int count, int y)
Definition: minorPiece.h:1417
static bool canMoveToSide(const NumEffectState &state, const Piece gold)
Definition: minorPiece.h:622
bool hasEffectAt(Square target) const
対象とするマスにあるプレイヤーの利きがあるかどうか.
int number() const
Definition: basic_type.h:828
static MultiInt evalOne(const NumEffectState &state, const Piece silver, const CArray< Square, 2 > &kings)
Definition: minorPiece.h:553
PtypeO altIfPiece(PtypeO ptypeO)
Pieceの時にはowner を反転する
Definition: basic_type.h:281
static int indexBoardCountX(Ptype ptype, int count, int x)
Definition: minorPiece.h:1424
constexpr Player alt(Player player)
Definition: basic_type.h:13
static void setUp(const Weights &weights, int stage)
Definition: minorPiece.cc:38
static void updateChanged(const NumEffectState &state, const Piece p, Move moved, int captured_number, const CArray< PieceMask, 2 > &effected_mask, const CArray< PieceMask, 2 > &new_mask, CArray< PieceMask, 40 > &attacked_mask, MultiIntPair &result)
Definition: minorPiece.h:1150
static CArray< MultiInt, 9 > y_table
Definition: minorPiece.h:820
Ptype ptype() const
Definition: basic_type.h:821
static CArray< MultiInt, 90 > x_stand_table
Definition: minorPiece.h:48
static int index(Player p, Square pos, Square king, PtypeO ptypeO, bool attack)
Definition: minorPiece.h:1523
static CArray< MultiInt, 1440 > table
Definition: minorPiece.h:1560
int min(Player p, int v1, int v2)
Definition: evalTraits.h:92
static int indexY(Player P, PtypeO up, PtypeO up_up, int y)
Definition: minorPiece.h:872
Ptype getPtype(PtypeO ptypeO)
Definition: basic_type.h:217
int countPiecesOnStand(Player pl, Ptype ptype) const
持駒の枚数を数える
Definition: simpleState.h:182
static bool cantAdvance(const NumEffectState &state, const PtypeO ptypeO, const Square position)
Definition: minorPiece.h:509
const Piece pieceAt(Square sq) const
Definition: simpleState.h:167
PtypeO ptypeO() const
Definition: basic_type.h:824
static CArray< MultiInt, 19584 > king_table
Definition: minorPiece.h:1075
int y() const
将棋としてのY座標を返す.
Definition: basic_type.h:567
static int indexCount(int count)
Definition: minorPiece.h:1439
static CArray< MultiInt, 81 > defense_y_table
Definition: minorPiece.h:45
static CArray< MultiInt, 2240 > xy_table
Definition: minorPiece.h:1497
static CArray< MultiInt, 2240 > xy_table_diff
Definition: minorPiece.h:1499
bool test(int num) const
Definition: pieceMask.h:45
static MultiInt evalOne(const NumEffectState &state, const Piece gold, const CArray< Square, 2 > &kings)
Definition: minorPiece.h:640
const int PTYPE_SIZE
Definition: basic_type.h:107
static int indexY(const Square king, int x_diff)
Definition: minorPiece.h:901
static MultiInt eval(int black_major_count)
Definition: minorPiece.h:719
int x() const
将棋としてのX座標を返す.
Definition: basic_type.h:563
static CArray< MultiInt, 9 > retreat_table
Definition: minorPiece.h:582
static int index(Ptype a, Ptype b)
Definition: minorPiece.h:1692
static MultiInt value(int attack_index, int defense_index, int attack_index_y, int defense_index_y, int attack_index_x, int defense_index_x)
Definition: minorPiece.h:74
static int indexBoardCount(Ptype ptype, int count)
Definition: minorPiece.h:1404
static int indexCountY(int count, int y)
Definition: minorPiece.h:1458
Ptype
駒の種類を4ビットでコード化する
Definition: basic_type.h:83
static CArray< MultiInt, 9216 > y_table
Definition: minorPiece.h:878
static CArray< MultiInt, 9 > table
Definition: minorPiece.h:701
const Piece pieceOf(int num) const
Definition: simpleState.h:76
Square kingSquare() const
Definition: simpleState.h:94
Ptype ptype() const
Definition: basic_type.h:1155
const PtypeTable Ptype_Table
Definition: tables.cc:97
static bool canCheck(const NumEffectState &state)
Definition: minorPiece.h:784
static CArray< MultiInt, 8192 > table
Definition: minorPiece.h:1621
static int indexSideX(Square pos)
Definition: minorPiece.h:609
static CArray< MultiInt, ONE_DIM > table
Definition: minorPiece.h:1371
static CArray< MultiInt, 153 > knight_table
Definition: minorPiece.h:670
static int indexCountX(Ptype ptype, int count, int x)
Definition: minorPiece.h:1410
bool isOnBoard() const
盤面上を表すかどうかの判定. 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する. ...
Definition: basic_type.h:583
static int index(Player P, Square pos)
Definition: minorPiece.h:501
static int indexK(Square king, bool same_turn, bool has_support, Square position, Player owner, Ptype ptype)
Definition: minorPiece.h:935
static int indexBoardCount(int count)
Definition: minorPiece.h:1445
static MultiInt valueBoardAll(Ptype ptype, int count, int my_king_x, int my_king_y, int op_king_x, int op_king_y)
Definition: minorPiece.h:1487
Player getOwner(PtypeO ptypeO)
Definition: basic_type.h:256
static CArray< MultiInt, 9792 > table
Definition: minorPiece.h:1535
Ptype oldPtype() const
移動前のPtype, i.e., 成る手だった場合成る前
Definition: basic_type.h:1174
static CArray< MultiInt, ONE_DIM > table
Definition: minorPiece.h:1657
static int index2(int i0, int i1)
Definition: minorPiece.h:1367
圧縮していない moveの表現 .
Definition: basic_type.h:1051
const PieceMask effectedChanged(Player pl) const
前の指手でeffectedMask(pl)が変化したか.
static CArray< MultiInt, 153 > head_table
Definition: minorPiece.h:581
static CArray< MultiInt, 144 > opp_table
Definition: minorPiece.h:839
bool hasPieceOnStand(Player player, Ptype ptype) const
Definition: simpleState.h:191
const NumBitmapEffect effectSetAt(Square sq) const
static CArray< MultiInt, 9 > table
Definition: minorPiece.h:906
static CArray< MultiInt, 18 > stand_table
Definition: minorPiece.h:47
static int index(const Player, const Ptype ptype, const Square pos)
Definition: minorPiece.h:769
static MultiInt weight
Definition: minorPiece.h:814
static CArray< MultiInt, ONE_DIM > table
Definition: minorPiece.h:1735
static MultiInt value(int index_y)
Definition: minorPiece.h:812
static CArray< MultiInt, 1024 > table
Definition: minorPiece.h:877
static int index(const Piece piece)
Definition: minorPiece.h:765
駒番号のビットセット.
Definition: pieceMask.h:20
static int indexY(int y)
Definition: minorPiece.h:816
constexpr int playerToIndex(Player player)
Definition: basic_type.h:16
static MultiInt valueAll(Ptype ptype, int count, int my_king_x, int my_king_y, int op_king_x, int op_king_y)
Definition: minorPiece.h:1478
static CArray< MultiInt, 10 > drop_non_drop_table
Definition: minorPiece.h:50
Player player() const
Definition: basic_type.h:1195
const Square neighbor() const
Definition: basic_type.h:746
static int indexBoardCountY(int count, int y)
Definition: minorPiece.h:1472
static int index(bool same_turn, bool has_support, Ptype ptype)
Definition: minorPiece.h:929
static CArray< MultiInt, 2240 > xy_attack_table_diff
Definition: minorPiece.h:1500
static int indexCountX(int count, int x)
Definition: minorPiece.h:1451
QuadInt MultiInt
Definition: midgame.h:13
static int index(Player player, Ptype ptype, int y, int pawn_y)
Definition: minorPiece.h:1551
static CArray< MultiInt, 9 > defense_table
Definition: minorPiece.h:44
static MultiInt evalOne(unsigned int ptypeo_mask)
Definition: minorPiece.h:1611
利きを持つ局面
static int index(bool same_turn, bool has_support, Ptype ptype, Ptype attack_ptype)
Definition: minorPiece.h:1115
static int index(Player P, PtypeO up, PtypeO up_up)
Definition: minorPiece.h:863
static CArray< MultiInt, 162 > y_stand_table
Definition: minorPiece.h:49
static CArray< MultiInt, ONE_DIM > table
Definition: minorPiece.h:1636
static CArray< MultiInt, 144 > table
Definition: minorPiece.h:742
static int index(const Player player, const Ptype ptype, const Square pos)
Definition: minorPiece.h:747
const Square square() const
Definition: basic_type.h:832
Ptype capturePtype() const
Definition: basic_type.h:1180
static CArray< MultiInt, 9 > retreat_table
Definition: minorPiece.h:671
static CArray< MultiInt, 80 > table
Definition: minorPiece.h:764
bool isDrop() const
Definition: basic_type.h:1150
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
Definition: basic_type.h:199
const Square to() const
Definition: basic_type.h:1132
static MultiInt eval(const NumEffectState &state, int black_pawn_count)
Definition: minorPiece.h:488
static CArray< MultiInt, ONE_DIM > table
Definition: minorPiece.h:1720
static MultiInt weight
Definition: minorPiece.h:729
static void evalOnePiece(const Player player, const Ptype ptype, const Ptype attack_ptype, bool with_support, MultiIntPair &result)
Definition: minorPiece.h:1134
static int index1(const NumEffectState &state, Piece piece)
Definition: minorPiece.h:1358
bool isPawnMaskSet(Player player, int x) const
Definition: simpleState.h:146
static int indexBoardCountX(int count, int x)
Definition: minorPiece.h:1465
static CArray< MultiInt, 14 > side_table
Definition: minorPiece.h:672
const PieceMask & piecesOnBoard(Player p) const
void reset(int num)
Definition: pieceMask.h:54
static int index(const Square king, int x)
Definition: minorPiece.h:60
bool hasEffectByPtypeStrict(Player attack, Square target) const
target に ptype の利きがあるか? 成不成を区別
const Piece findCheapAttack(Player P, Square square) const
static int index(const Square king, int distance0, int count)
Definition: minorPiece.h:1573
bool isPromoted(Ptype ptype)
ptypeがpromote後の型かどうかのチェック
Definition: basic_type.h:137
bool isPromotion() const
Definition: basic_type.h:1147
bool isEmpty() const
Definition: basic_type.h:913
static CArray< MultiInt, 9 > table
Definition: minorPiece.h:838
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に,ownerを反転する.
Definition: basic_type.h:264
const Square nextSquare(Player P, Square pos, Direction dr) const
next position from pos for player P.
Definition: boardTable.h:61
static CArray< MultiInt, 90 > x_table
Definition: minorPiece.h:46
static CArray< MultiInt, 64 > table
Definition: minorPiece.h:1074
static CArray< MultiInt, 1215 > table
Definition: minorPiece.h:1591
bool any() const
Definition: pieceMask.h:57
Player
Definition: basic_type.h:8
static int indexK(Square king, bool same_turn, bool has_support, Piece piece)
Definition: minorPiece.h:947
static CArray< MultiInt, 9720 > combination_table
Definition: minorPiece.h:1592
static bool cantAdvance(const NumEffectState &state, const Piece pawn)
Definition: minorPiece.h:505
static int index(const Piece piece)
Definition: minorPiece.h:743
static int indexCount(Ptype ptype, int count)
Definition: minorPiece.h:1398
static int indexSideY(Square pos)
Definition: minorPiece.h:614
static bool isTarget(Ptype ptype)
Definition: minorPiece.h:1696
static CArray< MultiInt, 160 > table
Definition: minorPiece.h:1496
const int EvalStages
Definition: midgame.h:12
const Piece kingPiece() const
Definition: simpleState.h:83
static int indexRetreat(Square pos)
Definition: minorPiece.h:605
static int index(Player P, Square pos)
Definition: minorPiece.h:702
static int indexBoardCountY(Ptype ptype, int count, int y)
Definition: minorPiece.h:1431
static int indexX(const Piece king, int x)
Definition: minorPiece.h:65
static CArray< MultiInt, 36 > state_king_relative_table
Definition: minorPiece.h:51
int getIndexMin(Ptype ptype) const
Definition: ptypeTable.h:88
static CArray< MultiInt, ONE_DIM > table
Definition: minorPiece.h:1688
static void updateEffectChanged(const NumEffectState &state, const CArray< PieceMask, 2 > &effected_mask, const CArray< PieceMask, 2 > &new_mask, int moved_piece_number, MultiIntPair &result)
Definition: minorPiece.h:956
static int indexCombination(const Square king, int count0, int count1, int count2)
Definition: minorPiece.h:1583
static CArray< MultiInt, 9 > table
Definition: minorPiece.h:532
static int indexY(const Piece king, int x)
Definition: minorPiece.h:53
static int bishopIndex(Ptype a, Ptype b)
Definition: minorPiece.h:1647
static CArray< MultiInt, 1024 > table
Definition: minorPiece.h:1344
static int indexRetreat(Square pos)
Definition: minorPiece.h:545
static MultiInt evalWithUpdate(const NumEffectState &state, Move moved, MultiInt &last_value)
Definition: minorPiece.h:100
static CArray< MultiInt, 2240 > xy_attack_table
Definition: minorPiece.h:1498
static void adjust(int black, int white, MultiIntPair &result)
Definition: minorPiece.h:1122
const BoardTable Board_Table
Definition: tables.cc:95
Player owner() const
Definition: basic_type.h:963