numEffectState.h
Go to the documentation of this file.
1 /* numEffectState.h
2  */
3 #ifndef OSL_NUM_EFFECT_STATE_H
4 #define OSL_NUM_EFFECT_STATE_H
5 
8 #include "osl/bits/align16New.h"
9 
10 namespace osl
11 {
12  namespace checkmate
13  {
14  class King8Info;
15  }
16  class MoveVector;
17  class NumEffectState;
23  bool operator==(const NumEffectState& st1, const NumEffectState& st2);
24 
30  class NumEffectState : public SimpleState
31 #if OSL_WORDSIZE == 32
32  , public misc::Align16New
33 #endif
34  {
42 
43  friend bool operator==(const NumEffectState& st1,const NumEffectState& st2);
45  public:
46  // ----------------------------------------------------------------------
47  // 0. 将棋以外の操作
48  // ----------------------------------------------------------------------
49  explicit NumEffectState(const SimpleState& st=SimpleState(HIRATE));
50  ~NumEffectState();
52  void copyFrom(const NumEffectState& src);
53  void copyFrom(const SimpleState& src);
54  bool isConsistent(bool showError=true) const;
56  bool isConsistent(const NumEffectState& prev, Move moved, bool show_error=true) const;
57  void showEffect(std::ostream& os) const;
58 
59 
60  // ----------------------------------------------------------------------
61  // 1. 盤面全体の情報
62  // ----------------------------------------------------------------------
63  const PieceMask& piecesOnBoard(Player p) const { return pieces_onboard[p]; }
64  const PieceMask promotedPieces() const { return promoted; }
65  const PieceMask pin(Player king) const
66  {
67  return pin_or_open[king]&piecesOnBoard(king);
68  }
70  const PieceMask checkShadow(Player attack) const
71  {
72  return pin_or_open[alt(attack)]&piecesOnBoard(attack);
73  }
75  {
76  return pin_or_open[king];
77  }
78  uint64_t Iking8Info(Player king) const
79  {
80  return king8infos[king];
81  }
83 #ifdef __GNUC__
84  __attribute__ ((pure))
85 #endif
86  king8Info(Player king) const;
88  bool inCheck(Player P) const
89  {
90  const Square king = kingSquare(P);
91 #ifdef ALLOW_KING_ABSENCE
92  if (king.isPieceStand())
93  return false;
94 #endif
95  return hasEffectAt(alt(P), king);
96  }
98  bool inCheck() const { return inCheck(turn()); }
107  bool inUnblockableCheck(Player target) const {
108  const Square king_position = kingSquare(target);
109  Piece attacker_piece;
110  if (hasEffectAt(alt(target), king_position, attacker_piece)) {
111  if (attacker_piece == Piece::EMPTY())
112  return true; // multiple pieces
113  // sigle check
114  const Square from = attacker_piece.square();
115  const EffectContent effect
116  = Ptype_Table.getEffect(attacker_piece.ptypeO(),
117  from, king_position);
118  return effect.hasUnblockableEffect();
119  }
120  // no check
121  return false;
122  }
123 
125  {
126  return effects.effectedNumTable;
127  }
128 
130  const PieceMask effectedMask(Player pl) const
131  {
132  return effects.effected_mask[pl];
133  }
138  {
139  return effects.effected_changed_mask[pl];
140  }
141  bool hasChangedEffects() const {
142  return ! effects.changedEffects(BLACK).isInvalid();
143  }
144  const BoardMask changedEffects(Player pl) const{
145  assert(hasChangedEffects());
146  return effects.changedEffects(pl);
147  }
148  const BoardMask changedEffects() const{
149  BoardMask ret = changedEffects(BLACK);
150  return ret |= changedEffects(WHITE);
151  }
153  return effects.changedPieces();
154  }
155  template <Ptype PTYPE> bool longEffectChanged() const
156  {
157  return changedPieces().template hasLong<PTYPE>();
158  }
159  template <Ptype PTYPE> bool anyEffectChanged() const
160  {
161  return changedPieces().template hasAny<PTYPE>();
162  }
163 
165  const Piece findThreatenedPiece(Player P) const;
166 
167  // ----------------------------------------------------------------------
168  // 2. 駒に関する情報
169  // ----------------------------------------------------------------------
170  bool isOnBoardNum(int num) const
171  {
172  return piecesOnBoard(BLACK).test(num) || piecesOnBoard(WHITE).test(num);
173  }
174 
175  Square mobilityOf(Direction d,int num) const
176  {
177  return effects.mobilityTable.get(d,num);
178  }
180  {
181  return mobilityOf(d, p.number());
182  }
184  {
185  return Square::makeDirect(king_mobility[p][d]);
186  }
193  {
194  if (p == BLACK)
195  d = inverse(d);
196  return kingMobilityAbs(p, d);
197  }
202  template<Player P>
204  {
205  assert(p.owner() == P);
206  assert(pinOrOpen(P).test(p.number()));
207  Square king=kingSquare<P>();
208  return Board_Table.getShort8<P>(p.square(),king);
209  }
211  {
212  if (p.owner() == BLACK)
213  return pinnedDir<BLACK>(p);
214  else
215  return pinnedDir<WHITE>(p);
216  }
221  template<Player P>
222  bool pinnedCanMoveTo(Piece p,Square to) const
223  {
224  assert(p.owner() == P);
225  Direction d=pinnedDir<P>(p);
226  Square from=p.square();
227  return primDir(d)==primDirUnsafe(Board_Table.getShort8Unsafe<P>(from,to));
228  }
229  bool pinnedCanMoveTo(Piece p,Square to) const
230  {
231  if (p.owner() == BLACK)
232  return pinnedCanMoveTo<BLACK>(p, to);
233  else
234  return pinnedCanMoveTo<WHITE>(p, to);
235  }
239  template<Player P>
240  Piece pinAttacker(Piece pinned) const
241  {
242  assert(pinned.owner() == P);
243  assert(pinOrOpen(P).test(pinned.number()));
244  Direction d=pinnedDir<P>(pinned);
245  int attacker_num=longEffectNumTable()[pinned.number()][(P==BLACK ? d : inverseUnsafe(d))];
246  return pieceOf(attacker_num);
247  }
248  Piece pinAttacker(Piece pinned) const
249  {
250  if (pinned.owner() == BLACK)
251  return pinAttacker<BLACK>(pinned);
252  else
253  return pinAttacker<WHITE>(pinned);
254  }
255  // ----------------------------------------------------------------------
256  // 3. あるSquareへの利き
257  // ----------------------------------------------------------------------
259  {
260  return effects.effectSetAt(sq);
261  }
266  int countEffect(Player player,Square target) const
267  {
268  assert(target.isOnBoard());
269  return effectSetAt(target).countEffect(player);
270  }
276  int
277 #ifdef __GNUC__
278  __attribute__ ((pure))
279 #endif
280  countEffect(Player player,Square target, PieceMask pins) const
281  {
282  assert(target.isOnBoard());
283  const NumBitmapEffect effect = effectSetAt(target);
284  const int all = effect.countEffect(player);
285  pins &= effect;
286  return all - pins.countBit();
287  }
288 
289  // ----------------------------------------------------------------------
290  // 3.1 集合を返す
291  // ----------------------------------------------------------------------
292  template <Ptype PTYPE>
293  const mask_t allEffectAt(Player P, Square target) const
294  {
295  return effectSetAt(target).template selectBit<PTYPE>() & piecesOnBoard(P).template getMask<PTYPE>();
296  }
297  const mask_t allEffectAt(Player P, Ptype ptype, Square target) const;
298  template <Ptype PTYPE> const mask_t longEffectAt(Square target) const
299  {
300  return effectSetAt(target).selectLong<PTYPE>() >> 8;
301  }
302  template <Ptype PTYPE> const mask_t longEffectAt(Square target, Player owner) const
303  {
304  return longEffectAt<PTYPE>(target) & piecesOnBoard(owner).getMask(1);
305  }
306  const mask_t longEffectAt(Square target) const
307  {
308  return effectSetAt(target).selectLong() >> 8;
309  }
310  const mask_t longEffectAt(Square target, Player owner) const
311  {
312  return longEffectAt(target) & piecesOnBoard(owner).getMask(1);
313  }
314 
315  // ----------------------------------------------------------------------
316  // 3.2 bool を返す
317  // ----------------------------------------------------------------------
323  template<Player P>
324  bool hasEffectAt(Square target) const {
325  assert(target.isOnBoard());
326  mask_t mask=effectSetAt(target).getMask(1);
327  mask&=NumBitmapEffect::playerEffectMask<P>();
328  return !mask.none();
329  }
335  bool hasEffectAt(Player player,Square target) const {
336  assert(target.isOnBoard());
337  mask_t mask=effectSetAt(target).getMask(1);
338  mask&=NumBitmapEffect::playerEffectMask(player);
339  return !mask.none();
340  }
341 
345  template <Ptype PTYPE>
346  bool hasLongEffectAt(Player P, Square to) const {
347  static_assert((PTYPE == LANCE || PTYPE == BISHOP || PTYPE == ROOK), "ptype");
348  return longEffectAt<PTYPE>(to, P).any();
349  }
350 
354  template <Ptype PTYPE>
355  bool hasEffectByPtype(Player attack, Square target) const
356  {
357  return allEffectAt<PTYPE>(attack, target).any();
358  }
362  template <Ptype PTYPE>
363  bool hasEffectByPtypeStrict(Player attack, Square target) const
364  {
365  mask_t mask=allEffectAt<PTYPE>(attack, target);
366  if (isPromoted(PTYPE))
367  mask &= promoted.getMask<PTYPE>();
368  else
369  mask &= ~(promoted.getMask<PTYPE>());
370  return mask.any();
371  }
376  template<Direction Dir,Player P>
377  bool hasEffectInDirection(Square to) const {
378  static_assert((DirectionTraits<Dir>::isLong), "Dir");
379  const PieceMask& pieces_onboard=piecesOnBoard(P);
380  mask_t mask1=pieces_onboard.getMask(1);
382  ? mask_t::makeDirect(PtypeFuns<LANCE>::indexMask)
383  : mask_t::makeDirect(0))
385  ? mask_t::makeDirect(PtypeFuns<BISHOP>::indexMask)
386  : mask_t::makeDirect(0))
388  ? mask_t::makeDirect(PtypeFuns<ROOK>::indexMask)
389  : mask_t::makeDirect(0)));
390  mask1 <<= 8;
391  // 短い利きを排除
392  mask1&=effectSetAt(to).getMask(1)& NumBitmapEffect::longEffectMask();
393  while (mask1.any())
394  {
395  int num=mask1.takeOneBit()+NumBitmapEffect::longToNumOffset;
396  Square from = pieceOf(num).square();
399  return true;
400  }
401  return false;
402  }
409  bool hasEffectNotBy(Player player,Piece piece,Square target) const {
410  assert(piece.owner()==player);
411  PieceMask pieces_onboard=piecesOnBoard(player);
412  int num=piece.number();
413  pieces_onboard.reset(num);
414  return (pieces_onboard&effectSetAt(target)).any();
415  }
420  assert(target.isOnBoard());
421  PieceMask m=piecesOnBoard(pl)& ~pinOrOpen(pl) & effectSetAt(target);
422  m.clearBit<KING>();
423  return m.any();
424  }
428  bool hasEffectByNotPinned(Player pl,Square target) const{
429  assert(target.isOnBoard());
430  PieceMask m=piecesOnBoard(pl)& ~pinOrOpen(pl) & effectSetAt(target);
431  return m.any();
432  }
439  bool hasMultipleEffectAt(Player player,Square target) const
440  {
441  mask_t mask=effectSetAt(target).getMask(1);
442  mask&=NumBitmapEffect::playerEffectMask(player);
443  return NumBitmapEffect::playerEffect(player).getMask(1) < mask;
444  }
445 
450  bool hasEffectByPiece(Piece attack, Square target) const
451  {
452  assert(attack.isPiece());
453  assert(target.isOnBoard());
454  return effectSetAt(target).test(attack.number());
455  }
456 
457 
465  bool hasEffectIf(PtypeO ptypeo,Square attacker,
466  Square target) const
467 #ifdef __GNUC__
468  __attribute__ ((pure))
469 #endif
470  {
471  Offset32 offset32=Offset32(target,attacker);
472  EffectContent effect=Ptype_Table.getEffect(ptypeo,offset32);
473  if (! effect.hasEffect())
474  return false;
475  if (effect.hasUnblockableEffect())
476  return true;
477  assert(Board_Table.getShortOffset(offset32) == effect.offset());
478  return this->isEmptyBetween(attacker,target,effect.offset());
479  }
483  template<Player P>
484  bool
485 #ifdef __GNUC__
486  __attribute__ ((pure))
487 #endif
488  hasEffectByWithRemove(Square target,Square removed) const;
489 
490  bool hasEffectByWithRemove(Player player, Square target,Square removed) const{
491  if (player==BLACK)
492  return hasEffectByWithRemove<BLACK>(target,removed);
493  else
494  return hasEffectByWithRemove<WHITE>(target,removed);
495  }
496 
497 
498  // ----------------------------------------------------------------------
499  // 3.3 pieceを探す
500  // ----------------------------------------------------------------------
502  template <Ptype PTYPE>
503  const Piece findAttackAt(Player attack, Square target) const
504  {
505  mask_t mask=allEffectAt<PTYPE>(attack, target);
506  if (mask.none())
507  return Piece::EMPTY();
508  return pieceOf(mask.takeOneBit()+PtypeFuns<PTYPE>::indexNum*32);
509  }
510  template <Ptype PTYPE>
511  const Piece findAttackAtStrict(Player attack, Square target) const
512  {
513  mask_t mask=allEffectAt<PTYPE>(attack, target);
514  if (isPromoted(PTYPE))
515  mask &= promoted.getMask<PTYPE>();
516  else
517  mask &= ~(promoted.getMask<PTYPE>());
518  if (mask.none())
519  return Piece::EMPTY();
520  return pieceOf(mask.takeOneBit()+PtypeFuns<PTYPE>::indexNum*32);
521  }
526  const Piece findLongAttackAt(Player owner, int piece, Direction d) const
527  {
528  assert(pieceOf(piece).isOnBoardByOwner(owner));
529  if (owner == BLACK)
530  d = inverse(d);
531  const int num = effects.effectedNumTable[piece][d];
532  if (num == EMPTY_NUM)
533  return Piece::EMPTY();
534  return pieceOf(num);
535  }
536  const Piece findLongAttackAt(Player owner, Piece piece, Direction d) const
537  {
538  assert(piece.isPiece());
539  assert(piece.owner() == owner);
540  return findLongAttackAt(owner, piece.number(), d);
541  }
542  const Piece findLongAttackAt(Piece piece, Direction d) const
543  {
544  assert(piece.isPiece());
545  return findLongAttackAt(piece.owner(), piece, d);
546  }
547  const Piece findLongAttackAt(Square square, Direction d) const
548  {
549  return findLongAttackAt(pieceOnBoard(square), d);
550  }
554  const Piece selectCheapPiece(PieceMask effect) const;
560  const Piece findCheapAttack(Player P, Square square) const
561  {
562  return selectCheapPiece(piecesOnBoard(P) & effectSetAt(square));
563  }
569  const Piece findCheapAttackNotBy(Player P, Square square, const PieceMask& ignore) const
570  {
571  PieceMask pieces = piecesOnBoard(P);
572  pieces &= ~ignore;
573  return selectCheapPiece(pieces & effectSetAt(square));
574  }
575  const Piece findAttackNotBy(Player P, Square square, const PieceMask& ignore) const
576  {
577  PieceMask pieces = piecesOnBoard(P);
578  pieces &= ~ignore;
579  pieces &= effectSetAt(square);
580  if (pieces.none())
581  return Piece::EMPTY();
582  return pieceOf(pieces.takeOneBit());
583  }
592  template<Player P>
593  bool findCheckPiece(Piece& attack_piece) const
594  {
595  return hasEffectAt<alt(P)>(kingSquare(P),attack_piece);
596  }
597  bool hasEffectAt(Player P, Square target,Piece& attackerPiece) const
598  {
599  if (P == BLACK)
600  return hasEffectAt<BLACK>(target, attackerPiece);
601  else
602  return hasEffectAt<WHITE>(target, attackerPiece);
603  }
610  template<Player P>
611  bool hasEffectAt(Square target,Piece& attackerPiece) const {
612  attackerPiece=Piece::EMPTY();
613  const PieceMask& pieceMask=piecesOnBoard(P)&effectSetAt(target);
614  mask_t mask=pieceMask.getMask(0);
615  if (mask.none()) return false;
620  if (mask.hasMultipleBit())
621  return true;
622  int num=mask.bsf();
623  attackerPiece=pieceOf(num);
624  return true;
625  }
626 
627  // ----------------------------------------------------------------------
628  // 4. 指手の検査・生成・適用
629  // ----------------------------------------------------------------------
630  // --- 2014/03
631  bool isSafeMove(Move move) const;
632  bool isCheck(Move move) const;
633  bool isPawnDropCheckmate(Move move) const;
634  bool isDirectCheck(Move move) const;
635  bool isOpenCheck(Move move) const;
636  // ---
637 
648  template <bool show_error>
649  bool isAlmostValidMove(Move move) const;
650  bool isAlmostValidMove(Move move,bool show_error=true) const;
651 
657  void generateLegal(MoveVector&) const;
663  void generateWithFullUnpromotions(MoveVector&) const;
665  void generateAllUnsafe(MoveVector&) const;
666 
667  void makeMove(Move move);
669  {
670  changeTurn();
671  effects.clearChangedEffects();
672  effects.clearEffectedChanged();
673  }
674 
675  template <class Function>
676  void makeUnmakePass(Function &f)
677  {
678  changeTurn();
679  f(Square::STAND());
680  changeTurn();
681  }
682  template <class Function>
683  void makeUnmakeMove(Move move, Function &f)
684  {
685  if (move.player() == BLACK)
686  makeUnmakeMove(Player2Type<BLACK>(), move, f);
687  else
688  makeUnmakeMove(Player2Type<WHITE>(), move, f);
689  }
690  template <Player P, class Function>
691  void makeUnmakeMove(Player2Type<P> player, Move move, Function &f)
692  {
693  if (move.isPass())
694  return makeUnmakePass(f);
695  assert(move.isValid());
696  assert(isAlmostValidMove(move));
697  assert(P == move.player());
698  assert(P == turn());
699  Square from=move.from();
700  Square to=move.to();
701  if (from.isPieceStand())
702  {
703  assert(pieceAt(to) == Piece::EMPTY());
704  doUndoDropMove(player,to,move.ptype(),f);
705  }
706  else
707  {
708  assert(pieceAt(from) != Piece::EMPTY());
709  Piece captured=pieceAt(to);
710  if (captured != Piece::EMPTY())
711  {
712  doUndoCaptureMove(player,from,to,captured,move.promoteMask(),f);
713  }
714  else
715  {
716  doUndoSimpleMove(player,from,to,move.promoteMask(),f);
717  }
718  }
719  }
720  bool wasCheckEvasion(Move last_move) const;
721  // ----------------------------------------------------------------------
722  // 5. forEachXXX
723  // ----------------------------------------------------------------------
726  template<Player P,Ptype T,typename F>
727  void forEachOnBoard(F& func) const {
728  mask_t onMask=piecesOnBoard(P).template selectBit<T>() ;
729  while (onMask.any())
730  {
731  int num=onMask.takeOneBit()+((PtypeFuns<T>::indexNum)<<5);
732  Piece p = pieceOf(num);
733  func(p);
734  }
735  }
738  template<Player P,Ptype T,typename F>
739  void forEachOnBoardPtypeStrict(F& func) const
740  {
741  mask_t mask=piecesOnBoard(P).template selectBit<T>() ;
742  if (isPromoted(T))
743  mask &= promoted.getMask<T>();
744  else
745  mask &= ~(promoted.getMask<T>());
746  while (mask.any())
747  {
748  int num=mask.takeOneBit()+((PtypeFuns<T>::indexNum)<<5);
749  func(pieceOf(num));
750  }
751  }
752  private:
753  template<Player P,class Action>
754  void forEachEffect(const PieceMask& pieces, Square sq,Action & action) const
755  {
756 #if OSL_WORDSIZE == 64
757  mask_t mask=pieces.getMask(0);
758  while (mask.any())
759  {
760  const int num=mask.takeOneBit();
761  action.template doAction<P>(pieceOf(num),sq);
762  }
763 #elif OSL_WORDSIZE == 32
764  mask_t mask0=pieces.getMask(0);
765  while (mask0.any())
766  {
767  const int num=mask0.takeOneBit();
768  action.template doAction<P>(pieceOf(num),sq);
769  }
770  mask_t mask1=pieces.getMask(1);
771  while (mask1.any())
772  {
773  const int num=mask1.takeOneBit()+32;
774  action.template doAction<P>(pieceOf(num),sq);
775  }
776 #endif
777  }
778  public:
783  template<Player P,class Action>
784  void forEachEffect(Square sq,Action & action) const
785  {
786  const PieceMask pieceMask=piecesOnBoard(P)&effectSetAt(sq);
787  forEachEffect<P,Action>(pieceMask, sq, action);
788  }
794  template<Player P,class Action>
795  void forEachEffect(Square sq,Action & action,const PieceMask& pin) const
796  {
797  PieceMask pieceMask=piecesOnBoard(P)&effectSetAt(sq);
798  pieceMask &= ~pin;
799  forEachEffect<P,Action>(pieceMask, sq, action);
800  }
801 
807  template<Player P,class Action>
808  void forEachEffectNotBy(Square sq,Piece piece,Action & action) const {
809  PieceMask pieces=piecesOnBoard(P)&effectSetAt(sq);
810  pieces.reset(piece.number());
811  forEachEffect<P,Action>(pieces, sq, action);
812  }
813 
814  private:
815  template<Player P,Ptype Type,class Action,Direction Dir>
817  template<Player P,Ptype Type,class Action,Direction Dir>
818  void forEachEffectOfPieceDir(Square pieceSquare,Action & action,Int2Type<true>) const {
820  action.template doAction<P>(this->pieceAt(pieceSquare),pieceSquare+offset);
821  }
822 
823  template<Player P,Ptype Type,class Action,Direction Dir>
824  void forEachEffectOfPieceDir(Square pieceSquare,Action & action) const {
825  forEachEffectOfPieceDir<P,Type,Action,Dir>(pieceSquare,action,Int2Type<(PtypeTraits<Type>::moveMask & DirectionTraits<Dir>::mask)!=0>());
826  }
827  template<Player P,Ptype Type,class Action,Direction Dir>
829  template<Player P,Ptype Type,class Action,Direction Dir>
830  void forEachEffectOfPieceLongDir(Square pieceSquare,Action & action,Int2Type<true>) const {
831  Piece piece=this->pieceAt(pieceSquare);
833  assert(offset.intValue() != 35);
834  Square sq=pieceSquare+offset;
835  for (;this->pieceAt(sq).isEmpty();sq+=offset)
836  action.template doAction<P>(piece,sq);
837  action.template doAction<P>(piece,sq);
838  }
839 
840  template<Player P,Ptype Type,class Action,Direction Dir>
841  void forEachEffectOfPieceLongDir(Square pieceSquare,Action & action) const {
842  forEachEffectOfPieceLongDir<P,Type,Action,Dir>(pieceSquare,action,Int2Type<(PtypeTraits<Type>::moveMask & DirectionTraits<Dir>::mask)!=0>());
843  }
844  public:
852  template<Player P,Ptype Type,class Action>
853  void forEachEffectOfPiece(Square pieceSquare,Action & action) const;
854  template<class Action>
855  void forEachEffectOfPiece(Piece piece,Action & action) const;
856 
862  template <class Function, bool InterestEmpty>
863  void forEachEffectOfPtypeO(Square, PtypeO, Function& f) const;
864  template <Player P, class Function, bool InterestEmpty>
865  void forEachEffectOfPtypeO(Square, Ptype, Function& f) const;
866 
873  template <Player P>
874  Piece safeCaptureNotByKing(Square target, Piece king) const;
876  const Piece king = kingPiece(P);
877  if (P == BLACK)
878  return this->safeCaptureNotByKing<BLACK>(target, king);
879  else
880  return this->safeCaptureNotByKing<WHITE>(target, king);
881  }
887  template <class Action>
888  void forEachEffect(Player P, Square pos, Action& a) const {
889  if (P == BLACK)
890  this->template forEachEffect<BLACK>(pos,a);
891  else
892  this->template forEachEffect<WHITE>(pos,a);
893  }
897  void findEffect(Player P, Square target, PieceVector& out) const;
898 
899  private:
900  void doSimpleMove(Square from, Square to, int promoteMask);
901  void doDropMove(Square to,Ptype ptype);
902  void doCaptureMove(Square from, Square to, Piece target,int promoteMask);
903 
904  template <Player P, class Function>
905  void doUndoSimpleMove(Player2Type<P> player,
906  Square from, Square to, int promoteMask,Function& func);
907  template <Player P>
908  void prologueSimple(Player2Type<P>, Square from, Square to, int promoteMask,
909  Piece& oldPiece, int& num,
910  PtypeO& oldPtypeO, PtypeO& new_ptypeo,
911  CArray<PieceMask,2>& pin_or_open_backup,
912  KingMobility& king_mobility_backup,
913  PieceMask& promoted_backup,
914  CArray<PieceMask,2>& effected_mask_backup,
915  CArray<PieceMask,2>& effected_changed_mask_backup,
916  CArray<uint64_t,2>& king8infos_backup,
917  MobilityTable &mobility_backup
918  );
919  void epilogueSimple(Square from, Square to, Piece oldPiece,
920  int num, PtypeO oldPtypeO, PtypeO newPtypeO,
921  const CArray<PieceMask,2>& pin_or_open_backup,
922  const KingMobility& king_mobility_backup,
923  const PieceMask& promoted_backup,
924  const CArray<PieceMask,2>& effected_mask_backup,
925  const CArray<PieceMask,2>& effected_changed_mask_backup,
926  const CArray<uint64_t,2>& king8infos_backup,
927  const MobilityTable &mobility_backup
928  );
929  template <Player P, class Function>
930  void doUndoDropMove(Player2Type<P> player,
931  Square to, Ptype ptype, Function& func);
932  template <Player P>
933  void prologueDrop(Player2Type<P>, Square to, Ptype ptype,
934  Piece& oldPiece, int& num, PtypeO& ptypeO,
935  int& numIndex, mask_t& numMask,
936  CArray<PieceMask,2>& pin_or_open_backup,
937  KingMobility& king_mobility_backup,
938  CArray<PieceMask,2>& effected_mask_backup,
939  CArray<PieceMask,2>& effected_changed_mask_backup,
940  CArray<uint64_t,2>& king8infos_backup,
941  MobilityTable &mobility_backup);
942  template<Player P>
943  void epilogueDrop(Player2Type<P>, Square to, Ptype ptype, Piece oldPiece,
944  int num, PtypeO ptypeO, int numIndex, mask_t numMask,
945  const CArray<PieceMask,2>& pin_or_open_backup,
946  const KingMobility& king_mobility_backup,
947  const CArray<PieceMask,2>& effected_mask_backup,
948  const CArray<PieceMask,2>& effected_changed_mask_backup,
949  const CArray<uint64_t,2>& king8infos_backup,
950  const MobilityTable &mobility_backup);
951  template <Player P, class Function>
952  void doUndoCaptureMove(Player2Type<P> player, Square from,Square to,
953  Piece target, int promoteMask,Function& func);
954 
955  template<Player P>
956  void prologueCapture(Player2Type<P>, Square from, Square to, Piece target,
957  int promoteMask,
958  Piece& oldPiece, PtypeO& oldPtypeO, PtypeO& capturePtypeO,
959  PtypeO& new_ptypeo, int& num0, int& num1,
960  int& num1Index, mask_t& num1Mask,
961  CArray<PieceMask,2>& pin_or_open_backup,
962  KingMobility& king_mobility_backup,
963  PieceMask& promoted_backup,
964  CArray<PieceMask,2>& effected_mask_backup,
965  CArray<PieceMask,2>& effected_changed_mask_backup,
966  CArray<uint64_t,2>& king8infos_backup,
967  MobilityTable &mobility_backup);
968 
969  template<Player P>
970  void epilogueCapture(Player2Type<P>, Square from, Square to, Piece target,
971  Piece oldPiece, PtypeO oldPtypeO, PtypeO capturePtypeO,
972  PtypeO newPtypeO, int num0, int num1,
973  int num1Index, mask_t num1Mask,
974  const CArray<PieceMask,2>& pin_or_open_backup,
975  const KingMobility& king_mobility_backup,
976  const PieceMask& promoted_backup,
977  const CArray<PieceMask,2>& effected_mask_backup,
978  const CArray<PieceMask,2>& effected_changed_mask_backup,
979  const CArray<uint64_t,2>& king8infos_backup,
980  const MobilityTable &mobility_backup);
981  //
982  template<Direction DIR>
983  void makePinOpenDir(Square target,
984  PieceMask& pins, PieceMask const& onBoard,Player defense)
985  {
986  const Offset offset = DirectionTraits<DIR>::blackOffset();
987  Square sq=target-offset;
988  int num;
989  while(Piece::isEmptyNum(num=pieceAt(sq).number()))
990  sq-=offset;
991  king_mobility[defense][DIR]=static_cast<unsigned char>(sq.uintValue());
992  if(Piece::isEdgeNum(num)) return;
993  int num1=longEffectNumTable()[num][DIR];
994  if(Piece::isPieceNum(num1) && onBoard.test(num1)){
995  pins.set(num);
996  }
997  }
998  void recalcPinOpen(Square changed, Direction &lastDir, Player defense)
999  {
1000  Square target=kingSquare(defense);
1001 #ifdef ALLOW_KING_ABSENCE
1002  if (target.isPieceStand())
1003  return;
1004 #endif
1005  const Direction longD=Board_Table.getLongDirection<BLACK>(changed,target);
1006  if(!isLong(longD) || (lastDir!=UL && longD==lastDir)) return;
1007  lastDir=longD;
1008  Direction shortD=longToShort(longD);
1009  {
1010  // reset old pins
1011  Square oldPos=Square::makeDirect(king_mobility[defense][shortD]);
1012  int oldNum=pieceAt(oldPos).number();
1013  if(Piece::isPieceNum(oldNum))
1014  pin_or_open[defense].reset(oldNum);
1015  }
1016  const Offset offset = Board_Table.getOffsetForBlack(longD);
1017  Square sq=target-offset;
1018  int num;
1019  while(Piece::isEmptyNum(num=pieceAt(sq).number()))
1020  sq-=offset;
1021  king_mobility[defense][shortD]=static_cast<unsigned char>(sq.uintValue());
1022  if(Piece::isEdgeNum(num)) return;
1023  int num1=longEffectNumTable()[num][shortD];
1024  if(Piece::isPieceNum(num1) && piecesOnBoard(alt(defense)).test(num1)){
1025  pin_or_open[defense].set(num);
1026  }
1027  }
1028  PieceMask makePinOpen(Square target,Player defense);
1029  void makePinOpen(Player defense);
1030  template<Player P>
1031  void makeKing8Info();
1032  };
1033 
1034  inline bool operator!=(const NumEffectState& s1, const NumEffectState& s2)
1035  {
1036  return !(s1==s2);
1037  }
1038 } // namespace osl
1039 
1040 template <osl::Player P, typename Function>
1043  Square from, Square to, int promoteMask, Function& func)
1044 {
1045  Piece oldPiece;
1046  int num;
1047  PtypeO oldPtypeO, newPtypeO;
1048  CArray<PieceMask,2> pin_or_open_backup;
1049  KingMobility king_mobility_backup;
1050  PieceMask promoted_backup;
1051  CArray<PieceMask,2> effected_mask_backup;
1052  CArray<PieceMask,2> effected_changed_mask_backup;
1053  CArray<uint64_t,2> king8infos_backup;
1054  MobilityTable mobility_backup;
1055  prologueSimple(player, from, to, promoteMask, oldPiece, num, oldPtypeO, newPtypeO,
1056  pin_or_open_backup,
1057  king_mobility_backup,
1058  promoted_backup,
1059  effected_mask_backup, effected_changed_mask_backup,
1060  king8infos_backup,
1061  mobility_backup);
1062  if (promoteMask!=0 && num < PtypeTraits<PAWN>::indexLimit)
1063  {
1064  clearPawn(P,from);
1065  changeTurn();
1066  func(to);
1067  changeTurn();
1068  setPawn(P,from);
1069  }
1070  else
1071  {
1072  changeTurn();
1073  func(to);
1074  changeTurn();
1075  }
1076  epilogueSimple(from, to, oldPiece, num, oldPtypeO, newPtypeO,
1077  pin_or_open_backup,
1078  king_mobility_backup,
1079  promoted_backup, effected_mask_backup, effected_changed_mask_backup,
1080  king8infos_backup,
1081  mobility_backup);
1082 }
1083 
1084 template <osl::Player P, typename Function>
1086  Square to, Ptype ptype, Function& func)
1087 {
1088  Piece oldPiece;
1089  PtypeO ptypeO;
1090  int num, numIndex;
1091  mask_t numMask;
1092  CArray<PieceMask,2> pin_or_open_backup;
1093  KingMobility king_mobility_backup;
1094  CArray<PieceMask,2> effected_mask_backup;
1095  CArray<PieceMask,2> effected_changed_mask_backup;
1096  CArray<uint64_t,2> king8infos_backup;
1097  MobilityTable mobility_backup;
1098  prologueDrop(player, to, ptype, oldPiece, num, ptypeO, numIndex, numMask,
1099  pin_or_open_backup, king_mobility_backup,
1100  effected_mask_backup,effected_changed_mask_backup,
1101  king8infos_backup,
1102  mobility_backup);
1103  if (ptype==PAWN)
1104  {
1105  setPawn(P,to);
1106  changeTurn();
1107  func(to);
1108  changeTurn();
1109  clearPawn(P,to);
1110  }
1111  else
1112  {
1113  changeTurn();
1114  func(to);
1115  changeTurn();
1116  }
1117  epilogueDrop(player, to, ptype, oldPiece, num, ptypeO, numIndex, numMask,
1118  pin_or_open_backup, king_mobility_backup,
1119  effected_mask_backup,effected_changed_mask_backup,
1120  king8infos_backup,
1121  mobility_backup);
1122 }
1123 
1124 template <osl::Player P, typename Function>
1126  Square from,Square to, Piece target,
1127  int promoteMask,Function& func)
1128 {
1129  Piece oldPiece;
1130  PtypeO oldPtypeO, capturePtypeO, newPtypeO;
1131  int num0, num1, num1Index;
1132  mask_t num1Mask;
1133  CArray<PieceMask,2> pin_or_open_backup;
1134  KingMobility king_mobility_backup;
1135  PieceMask promoted_backup;
1136  CArray<PieceMask,2> effected_mask_backup;
1137  CArray<PieceMask,2> effected_changed_mask_backup;
1138  CArray<uint64_t,2> king8infos_backup;
1139  MobilityTable mobility_backup;
1140  prologueCapture(player, from, to, target, promoteMask, oldPiece, oldPtypeO,
1141  capturePtypeO, newPtypeO, num0, num1, num1Index,num1Mask,
1142  pin_or_open_backup, king_mobility_backup,
1143  promoted_backup,
1144  effected_mask_backup, effected_changed_mask_backup,
1145  king8infos_backup,
1146  mobility_backup);
1147 
1148  changeTurn();
1149  const Ptype capturePtype=target.ptype();
1150  if (capturePtype==PAWN)
1151  {
1152  clearPawn(alt(P),to);
1153  if (promoteMask!=0 && num0<PtypeTraits<PAWN>::indexLimit)
1154  {
1155  clearPawn(P,from);
1156  func(to);
1157  setPawn(P,from);
1158  }
1159  else
1160  {
1161  func(to);
1162  }
1163  setPawn(alt(P),to);
1164  }
1165  else if (promoteMask!=0 && num0<PtypeTraits<PAWN>::indexLimit)
1166  {
1167  clearPawn(P,from);
1168  func(to);
1169  setPawn(P,from);
1170  }
1171  else
1172  {
1173  func(to);
1174  }
1175  changeTurn();
1176 
1177  epilogueCapture(player, from, to, target, oldPiece, oldPtypeO, capturePtypeO, newPtypeO,
1178  num0, num1, num1Index,num1Mask,
1179  pin_or_open_backup, king_mobility_backup,
1180  promoted_backup,effected_mask_backup, effected_changed_mask_backup,
1181  king8infos_backup,
1182  mobility_backup);
1183 }
1184 
1185 template <class Action>
1187 forEachEffectOfPiece(Piece piece,Action & action) const
1188 {
1189  Square pieceSquare = piece.square();
1190  switch ((int)piece.ptypeO()) {
1191  case NEW_PTYPEO(WHITE,PAWN): forEachEffectOfPiece<WHITE,PAWN,Action>(pieceSquare,action); break;
1192  case NEW_PTYPEO(WHITE,LANCE): forEachEffectOfPiece<WHITE,LANCE,Action>(pieceSquare,action); break;
1193  case NEW_PTYPEO(WHITE,KNIGHT): forEachEffectOfPiece<WHITE,KNIGHT,Action>(pieceSquare,action); break;
1194  case NEW_PTYPEO(WHITE,SILVER): forEachEffectOfPiece<WHITE,SILVER,Action>(pieceSquare,action); break;
1195  case NEW_PTYPEO(WHITE,PPAWN): forEachEffectOfPiece<WHITE,PPAWN,Action>(pieceSquare,action); break;
1196  case NEW_PTYPEO(WHITE,PLANCE): forEachEffectOfPiece<WHITE,PLANCE,Action>(pieceSquare,action); break;
1197  case NEW_PTYPEO(WHITE,PKNIGHT): forEachEffectOfPiece<WHITE,PKNIGHT,Action>(pieceSquare,action); break;
1198  case NEW_PTYPEO(WHITE,PSILVER): forEachEffectOfPiece<WHITE,PSILVER,Action>(pieceSquare,action); break;
1199  case NEW_PTYPEO(WHITE,GOLD): forEachEffectOfPiece<WHITE,GOLD,Action>(pieceSquare,action); break;
1200  case NEW_PTYPEO(WHITE,BISHOP): forEachEffectOfPiece<WHITE,BISHOP,Action>(pieceSquare,action); break;
1201  case NEW_PTYPEO(WHITE,PBISHOP): forEachEffectOfPiece<WHITE,PBISHOP,Action>(pieceSquare,action); break;
1202  case NEW_PTYPEO(WHITE,ROOK): forEachEffectOfPiece<WHITE,ROOK,Action>(pieceSquare,action); break;
1203  case NEW_PTYPEO(WHITE,PROOK): forEachEffectOfPiece<WHITE,PROOK,Action>(pieceSquare,action); break;
1204  case NEW_PTYPEO(WHITE,KING): forEachEffectOfPiece<WHITE,KING,Action>(pieceSquare,action); break;
1205  case NEW_PTYPEO(BLACK,PAWN): forEachEffectOfPiece<BLACK,PAWN,Action>(pieceSquare,action); break;
1206  case NEW_PTYPEO(BLACK,LANCE): forEachEffectOfPiece<BLACK,LANCE,Action>(pieceSquare,action); break;
1207  case NEW_PTYPEO(BLACK,KNIGHT): forEachEffectOfPiece<BLACK,KNIGHT,Action>(pieceSquare,action); break;
1208  case NEW_PTYPEO(BLACK,SILVER): forEachEffectOfPiece<BLACK,SILVER,Action>(pieceSquare,action); break;
1209  case NEW_PTYPEO(BLACK,PPAWN): forEachEffectOfPiece<BLACK,PPAWN,Action>(pieceSquare,action); break;
1210  case NEW_PTYPEO(BLACK,PLANCE): forEachEffectOfPiece<BLACK,PLANCE,Action>(pieceSquare,action); break;
1211  case NEW_PTYPEO(BLACK,PKNIGHT): forEachEffectOfPiece<BLACK,PKNIGHT,Action>(pieceSquare,action); break;
1212  case NEW_PTYPEO(BLACK,PSILVER): forEachEffectOfPiece<BLACK,PSILVER,Action>(pieceSquare,action); break;
1213  case NEW_PTYPEO(BLACK,GOLD): forEachEffectOfPiece<BLACK,GOLD,Action>(pieceSquare,action); break;
1214  case NEW_PTYPEO(BLACK,BISHOP): forEachEffectOfPiece<BLACK,BISHOP,Action>(pieceSquare,action); break;
1215  case NEW_PTYPEO(BLACK,PBISHOP): forEachEffectOfPiece<BLACK,PBISHOP,Action>(pieceSquare,action); break;
1216  case NEW_PTYPEO(BLACK,ROOK): forEachEffectOfPiece<BLACK,ROOK,Action>(pieceSquare,action); break;
1217  case NEW_PTYPEO(BLACK,PROOK): forEachEffectOfPiece<BLACK,PROOK,Action>(pieceSquare,action); break;
1218  case NEW_PTYPEO(BLACK,KING): forEachEffectOfPiece<BLACK,KING,Action>(pieceSquare,action); break;
1219  default: assert(0);
1220  }
1221 }
1222 
1223 template <osl::Player P, osl::Ptype Type, class Action>
1225 forEachEffectOfPiece(Square pieceSquare,Action & action) const
1226 {
1227  forEachEffectOfPieceDir<P,Type,Action,UL>(pieceSquare,action);
1228  forEachEffectOfPieceDir<P,Type,Action,U>(pieceSquare,action);
1229  forEachEffectOfPieceDir<P,Type,Action,UR>(pieceSquare,action);
1230  forEachEffectOfPieceDir<P,Type,Action,L>(pieceSquare,action);
1231  forEachEffectOfPieceDir<P,Type,Action,R>(pieceSquare,action);
1232  forEachEffectOfPieceDir<P,Type,Action,DL>(pieceSquare,action);
1233  forEachEffectOfPieceDir<P,Type,Action,D>(pieceSquare,action);
1234  forEachEffectOfPieceDir<P,Type,Action,DR>(pieceSquare,action);
1235  forEachEffectOfPieceDir<P,Type,Action,UUL>(pieceSquare,action);
1236  forEachEffectOfPieceDir<P,Type,Action,UUR>(pieceSquare,action);
1237  forEachEffectOfPieceLongDir<P,Type,Action,LONG_UL>(pieceSquare,action);
1238  forEachEffectOfPieceLongDir<P,Type,Action,LONG_U>(pieceSquare,action);
1239  forEachEffectOfPieceLongDir<P,Type,Action,LONG_UR>(pieceSquare,action);
1240  forEachEffectOfPieceLongDir<P,Type,Action,LONG_L>(pieceSquare,action);
1241  forEachEffectOfPieceLongDir<P,Type,Action,LONG_R>(pieceSquare,action);
1242  forEachEffectOfPieceLongDir<P,Type,Action,LONG_DL>(pieceSquare,action);
1243  forEachEffectOfPieceLongDir<P,Type,Action,LONG_D>(pieceSquare,action);
1244  forEachEffectOfPieceLongDir<P,Type,Action,LONG_DR>(pieceSquare,action);
1245 }
1246 
1247 #include "osl/bits/pieceStand.h"
1248 #endif /* OSL_NUM_EFFECT_STATE_H */
1249 // ;;; Local Variables:
1250 // ;;; mode:c++
1251 // ;;; c-basic-offset:2
1252 // ;;; End:
constexpr Direction primDirUnsafe(Direction d)
8方向について,primitiveな4方向を求める dとしてknight, INVALIDなども来る
Definition: basic_type.h:374
const Piece findAttackAtStrict(Player attack, Square target) const
bool hasUnblockableEffect() const
短い利きがある.長い利きの隣も含む
Definition: effectContent.h:38
int countEffect(Player player, Square target) const
利きの数を数える.
void forEachEffectNotBy(Square sq, Piece piece, Action &action) const
sq に移動する move を生成して action の member を呼び出す
constexpr Direction inverseUnsafe(Direction d)
Definition: basic_type.h:354
bool hasLongEffectAt(Player P, Square to) const
あるマスにPTYPEの長い利きがあるかどうか.
void forEachEffect(Square sq, Action &action) const
sq への利きを持つ各駒に関して処理を行う.
Piece pinAttacker(Piece pinned) const
void forEachEffectOfPieceLongDir(Square, Action &, Int2Type< false >) const
bool isInvalid() const
Definition: boardMask.h:39
void doUndoDropMove(Player2Type< P > player, Square to, Ptype ptype, Function &func)
bool hasEffectIf(PtypeO ptypeo, Square attacker, Square target) const
attackerにptypeoの駒がいると仮定した場合にtargetに利きがあるかどうか を stateをupdateしないで確かめる...
bool hasEffectByWithRemove(Player player, Square target, Square removed) const
bool hasEffectByNotPinned(Player pl, Square target) const
pinされている駒以外からの利きがある.
const Piece findLongAttackAt(Player owner, Piece piece, Direction d) const
mobility::MobilityTable mobilityTable
mobility
GeneralMask< mask_int_t > mask_t
Definition: mask.h:351
bool hasEffectAt(Square target) const
対象とするマスにあるプレイヤーの利きがあるかどうか.
int number() const
Definition: basic_type.h:828
constexpr Direction inverse(Direction d)
Definition: basic_type.h:358
const BoardMask changedEffects(Player pl) const
PieceMask pinOrOpen(Player king) const
constexpr Player alt(Player player)
Definition: basic_type.h:13
void doUndoSimpleMove(Player2Type< P > player, Square from, Square to, int promoteMask, Function &func)
const Piece findAttackAt(Player attack, Square target) const
return a piece s.t.
bool pinnedCanMoveTo(Piece p, Square to) const
const PtypeO PTYPEO_EDGE __attribute__((unused))
void set(int num)
Definition: pieceMask.h:48
static const mask_t longEffectMask()
bool isOnBoardNum(int num) const
bool operator==(const ProofDisproof &l, const ProofDisproof &r)
Ptype ptype() const
Definition: basic_type.h:821
static const Offset blackOffset()
const PieceMask checkShadow(Player attack) const
attack の駒で動くと開き王手になる可能性がある集合
void recalcPinOpen(Square changed, Direction &lastDir, Player defense)
KingMobility king_mobility
bool inUnblockableCheck(Player target) const
target の王に合駒可能でない王手がかかっているかどうか.
static const Square makeDirect(int value)
Definition: basic_type.h:538
bool hasEffectByPtype(Player attack, Square target) const
target に ptype の利きがあるか? 成不成を区別しない
const PieceMask pin(Player king) const
void makePinOpenDir(Square target, PieceMask &pins, PieceMask const &onBoard, Player defense)
void forEachEffectOfPieceLongDir(Square pieceSquare, Action &action, Int2Type< true >) const
座標の差分
Definition: basic_type.h:429
static mask_t playerEffectMask()
const EffectedNumTable & longEffectNumTable() const
void makeUnmakeMove(Move move, Function &f)
bool hasEffect() const
短い利きがあるか,間がemptyなら長い利きがある
Definition: effectContent.h:34
const NumBitmapEffect changedPieces() const
const int EMPTY_NUM
Definition: basic_type.h:778
effect::NumSimpleEffectTable effects
Direction pinnedDir(Piece p) const
pinされた駒がPのKingから見てどの方向か? Pから見たdirectionを返す
bool isPiece() const
Definition: basic_type.h:953
PtypeO ptypeO() const
Definition: basic_type.h:824
差が uniqになるような座標の差分.
Definition: offset32.h:16
bool findCheckPiece(Piece &attack_piece) const
王手駒を探す
static const Piece EMPTY()
Definition: basic_type.h:797
bool hasChangedEffects() const
bool hasEffectByPiece(Piece attack, Square target) const
駒attack が target に利きを持つか (旧hasEffectToと統合)
CArray< PieceMask, 2 > effected_mask
void forEachOnBoard(F &func) const
T は isBasic でなくても動くが unpromote(T) の結果と同じ.
bool test(int num) const
Definition: pieceMask.h:45
bool hasEffectByNotPinnedAndKing(Player pl, Square target) const
{pinされている駒, 玉以外}からの利きがある.
void forEachOnBoardPtypeStrict(F &func) const
T の成不成を区別
CArray< PieceMask, 2 > pieces_onboard
const BoardMask changedEffects(Player pl) const
const NumBitmapEffect effectSetAt(Square pos) const
ある位置の利きデータを取り出す.
const mask_t longEffectAt(Square target) const
const Offset offset() const
返り値が0なら長い利きがない, 0以外なら辿るのに必要なoffset (2005/3/25 に仕様変更 - 長い利きだが隣の場...
Definition: effectContent.h:44
Offset32Base< 8, 9 > Offset32
Definition: offset32.h:63
PtypeO newPtypeO(Player player, Ptype ptype)
Definition: basic_type.h:211
void forEachEffectOfPieceDir(Square, Action &, Int2Type< false >) const
Ptype
駒の種類を4ビットでコード化する
Definition: basic_type.h:83
void forEachEffect(Player P, Square pos, Action &a) const
forEachEffect の Player のtemplate 引数を通常の引数にしたバージョン
const Offset getOffsetForBlack(Direction dir) const
黒にとってのoffsetを返す
Definition: boardTable.h:37
Ptype ptype() const
Definition: basic_type.h:1155
const mask_t longEffectAt(Square target) const
void forEachEffect(Square sq, Action &action, const PieceMask &pin) const
sq にある駒を取る move を生成して action の member を呼び出す.
static bool isEdgeNum(int num)
Definition: basic_type.h:922
bool hasMultipleEffectAt(Player player, Square target) const
二つ以上の駒から利きがある.
const PtypeTable Ptype_Table
Definition: tables.cc:97
void makeUnmakePass(Function &f)
Square mobilityOf(Direction d, int num) const
const Piece findLongAttackAt(Piece piece, Direction d) const
bool hasEffectAt(Player player, Square target) const
対象とするマスにあるプレイヤーの利きがあるかどうか.
bool isOnBoard() const
盤面上を表すかどうかの判定. 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する. ...
Definition: basic_type.h:583
const Square from() const
Definition: basic_type.h:1125
局面全体の利きデータ.
const BoardMask changedEffects() const
int countEffect(Player player, Square target, PieceMask pins) const
利きの数を数える.
圧縮していない moveの表現 .
Definition: basic_type.h:1051
const PieceMask effectedChanged(Player pl) const
前の指手でeffectedMask(pl)が変化したか.
Square kingMobilityOfPlayer(Player p, Direction d) const
玉がd方向にどこまで動けるかを返す
Square mobilityOf(Direction d, Piece p) const
Piece safeCaptureNotByKing(Player P, Square target) const
const Square get(Direction d, int num) const
Definition: mobilityTable.h:65
void forEachEffectOfPieceLongDir(Square pieceSquare, Action &action) const
bool hasEffectAt(Square target, Piece &attackerPiece) const
const NumBitmapEffect effectSetAt(Square sq) const
const Piece findAttackNotBy(Player P, Square square, const PieceMask &ignore) const
const EffectContent getEffect(PtypeO ptypeo, Square from, Square to) const
fromにいるptypeoがtoに利きを持つか?
Definition: ptypeTable.h:112
Direction pinnedDir(Piece p) const
bool isPass() const
Definition: basic_type.h:1092
駒番号のビットセット.
Definition: pieceMask.h:20
PieceMask promoted
成駒一覧
敵玉の8近傍の状態を表す.
Definition: king8Info.h:28
static bool isEmptyNum(int num)
Definition: basic_type.h:916
CArray< uint64_t, 2 > king8infos
Player player() const
Definition: basic_type.h:1195
int promoteMask() const
pieceに使うためのmaskなので
Definition: basic_type.h:1143
const Piece findLongAttackAt(Player owner, int piece, Direction d) const
pieceのd方向から長い利きがある場合にその駒を返す。
constexpr Direction primDir(Direction d)
8方向について,primitiveな4方向を求める
Definition: basic_type.h:366
Piece pinAttacker(Piece pinned) const
Pのpinされた駒から,そのpinの原因となっている長い利きを持つ駒を得る.
bool hasEffectInDirection(Square to) const
あるマスにあるDirectionでの長い利きがあるかどうか.
void makeUnmakeMove(Player2Type< P > player, Move move, Function &f)
constexpr Direction longToShort(Direction d)
Definition: basic_type.h:380
unsigned int square
Definition: basic_type.h:533
const Piece findCheapAttackNotBy(Player P, Square square, const PieceMask &ignore) const
const Piece findLongAttackAt(Square square, Direction d) const
利きを持つ局面
const mask_t longEffectAt(Square target, Player owner) const
bool inCheck(Player P) const
Pの玉が王手状態
駒番号からMobilityContentを得る
Definition: mobilityTable.h:51
uint64_t Iking8Info(Player king) const
#define NEW_PTYPEO(player, ptype)
Definition: basic_type.h:204
const Square square() const
Definition: basic_type.h:832
bool operator!=(const ProofDisproof &l, const ProofDisproof &r)
const mask_t longEffectAt(Square target, Player owner) const
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
Definition: basic_type.h:199
const Square to() const
Definition: basic_type.h:1132
Square kingMobilityAbs(Player p, Direction d) const
static NumBitmapEffect playerEffect()
int intValue() const
Definition: basic_type.h:448
CArray< PieceMask, 2 > effected_changed_mask
Direction
Definition: basic_type.h:310
const Offset getShortOffset(Offset32 offset32) const
Longの利きの可能性のあるoffsetの場合は, 反復に使う offsetを Shortの利きのoffsetの場合はそれ自身を返す...
Definition: boardTable.h:110
const PieceMask & piecesOnBoard(Player p) const
bool hasEffectAt(Player P, Square target, Piece &attackerPiece) const
void reset(int num)
Definition: pieceMask.h:54
const mask_t allEffectAt(Player P, Square target) const
bool hasEffectByPtypeStrict(Player attack, Square target) const
target に ptype の利きがあるか? 成不成を区別
const Piece findCheapAttack(Player P, Square square) const
constexpr bool isLong(Direction d)
Definition: basic_type.h:350
bool isPromoted(Ptype ptype)
ptypeがpromote後の型かどうかのチェック
Definition: basic_type.h:137
void forEachEffectOfPieceDir(Square pieceSquare, Action &action, Int2Type< true >) const
void doUndoCaptureMove(Player2Type< P > player, Square from, Square to, Piece target, int promoteMask, Function &func)
bool pinnedCanMoveTo(Piece p, Square to) const
pinされた駒pがtoに動けるか? pinに関係がなければtoへ動けるという前提
const PieceMask effectedMask(Player pl) const
pl からの利きが(1つ以上)ある駒一覧
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に,ownerを反転する.
Definition: basic_type.h:264
static bool isPieceNum(int num)
Definition: basic_type.h:926
Direction getShort8(Square from, Square to) const
Definition: boardTable.h:147
const mask_t getMask(int num) const
Definition: pieceMask.h:59
NumEffectState state_t
bool hasEffectNotBy(Player player, Piece piece, Square target) const
対象とするマスにあるプレイヤーの(ただしある駒以外)利きがあるかどうか.
EffectedNumTable effectedNumTable
effected num
bool inCheck() const
手番の玉が王手状態
Player
Definition: basic_type.h:8
bool isValid() const
Definition: basic_type.cc:246
現在の定義 (2005/3/4以降)
Direction getShort8Unsafe(Square from, Square to) const
8方向にいない場合も適当なものを返す.
Definition: boardTable.h:134
bool longEffectChanged() const
bool isPieceStand() const
Definition: basic_type.h:576
const PieceMask promotedPieces() const
const NumBitmapEffect changedPieces() const
Direction getLongDirection(Offset32 offset32) const
Definition: boardTable.h:71
bool anyEffectChanged() const
CArray< PieceMask, 2 > pin_or_open
void forEachEffectOfPiece(Square pieceSquare, Action &action) const
pieceSquareにある駒によって利きを受けるすべてのsquare (空白含む)について actionを実行する ...
void forEachEffectOfPieceDir(Square pieceSquare, Action &action) const
unsigned int uintValue() const
Definition: basic_type.h:539
static const Square STAND()
Definition: basic_type.h:548
const BoardTable Board_Table
Definition: tables.cc:95
void forEachEffect(const PieceMask &pieces, Square sq, Action &action) const
Player owner() const
Definition: basic_type.h:963