basic_type.h
Go to the documentation of this file.
1 #ifndef OSL_BASIC_TYPE_H
2 #define OSL_BASIC_TYPE_H
3 #include "osl/config.h"
4 #include <type_traits>
5 #include <cassert>
6 #include <iosfwd>
7 namespace osl{
8  enum Player{
9  BLACK=0,
10  WHITE= -1
11  };
12 
13  constexpr Player alt(Player player){
14  return static_cast<Player>(-1-static_cast<int>(player));
15  }
16  constexpr int playerToIndex(Player player){
17  return -static_cast<int>(player);
18  }
19  constexpr Player indexToPlayer(int n) {
20  // assert(n == 0 || n == 1)
21  return static_cast<Player>(-n);
22  }
23  constexpr int sign(Player player){
24  // int ret=1+(static_cast<int>(player)<<1);
25  // assert(ret==1 || ret== -1);
26  return 1+(static_cast<int>(player)<<1);
27  }
28  constexpr int playerToMask(Player player){
29  return static_cast<int>(player);
30  }
31 
32  // These codes are intentionally DECLARED and NOT IMPLEMENTED.
33  // you will get link error here if you write code such as "value += v * piece.owner() == BLACK ? 1.0 : -1.0;"
34  int operator+(Player, int); int operator+(int, Player);
35  int operator-(Player, int); int operator-(int, Player);
36  int operator*(Player, int); int operator*(int, Player);
37  int operator/(Player, int); int operator/(int, Player);
38 
42  bool isValid(Player player);
43 #if 0
44  template<Player P>
45  struct PlayerTraits;
46 
47  template<>
48  struct PlayerTraits<BLACK>{
49  static const int offsetMul=1;
50  static const int index=0;
51  static const int mask=0;
52  static const Player opponent=WHITE;
53  };
54 
55  template<>
56  struct PlayerTraits<WHITE>{
57  static const int offsetMul=-1;
58  static const int index=1;
59  static const int mask= -1;
60  static const Player opponent=BLACK;
61  };
62 #endif
63  std::ostream& operator<<(std::ostream& os,Player player);
64 
65  namespace misc
66  {
67 // Int2Type by LOKI
68  template<int v>
69  struct Int2Type{ enum { value=v }; };
70 
71  template<typename T>
72  struct Type2Type{};
73 
74  template<Player P>
75  struct Player2Type{ enum { value=P }; };
76 
77  struct EmptyType{};
78  } // namespace misc
79  using misc::Int2Type;
80  using misc::Player2Type;
81 
83  enum Ptype
84  {
87  PPAWN=2,
88  PLANCE=3,
92  PROOK=7,
93  KING=8,
94  GOLD=9,
95  PAWN=10,
96  LANCE=11,
97  KNIGHT=12,
98  SILVER=13,
99  BISHOP=14,
100  ROOK=15,
101 
106  };
108 
109  std::istream& operator>>(std::istream& is, Ptype& ptype);
110  std::ostream& operator<<(std::ostream& os,const Ptype ptype);
111 
115  bool isValid(Ptype ptype);
116 
120  constexpr bool isPiece(Ptype ptype)
121  {
122  // assert(isValid(ptype));
123  return static_cast<int>(ptype)>=PTYPE_PIECE_MIN;
124  }
128  inline bool isBasic(Ptype ptype)
129  {
130  assert(isValid(ptype));
131  return static_cast<int>(ptype)>PROOK;
132  }
133 
137  inline bool isPromoted(Ptype ptype)
138  {
139  assert(isPiece(ptype));
140  return static_cast<int>(ptype)<KING;
141  }
142 
147  inline bool canPromote(Ptype ptype)
148  {
149  assert(isPiece(ptype));
150  return static_cast<int>(ptype)>GOLD;
151  }
152 
157  inline Ptype unpromote(Ptype ptype)
158  {
159  assert(isPiece(ptype));
160  Ptype ret=static_cast<Ptype>(static_cast<int>(ptype)|8);
161  assert(isPiece(ret));
162  return ret;
163  }
164  constexpr Ptype unpromoteSafe(Ptype ptype)
165  {
166  return (! isPiece(ptype)) ? ptype : unpromote(ptype);
167  }
168 
173  inline Ptype promote(Ptype ptype)
174  {
175  assert(canPromote(ptype));
176  Ptype ret=static_cast<Ptype>(static_cast<int>(ptype)-8);
177  assert(isPiece(ret));
178  return ret;
179  }
180 
181  inline bool isMajorBasic(Ptype ptype)
182  {
183  return ptype >= 14;
184  }
185  inline bool isMajor(Ptype ptype)
186  {
187  assert(isPiece(ptype));
188  return isMajorBasic(unpromote(ptype));
189  }
190  inline bool isMajorNonPieceOK(Ptype ptype)
191  {
192  return (static_cast<int>(ptype)|8)>=14;
193  }
194 
199  enum PtypeO {
202  };
203 
204 #define NEW_PTYPEO(player,ptype) static_cast<PtypeO>(static_cast<int>(ptype)-(16&static_cast<int>(player)))
205  inline unsigned int ptypeOIndex(PtypeO ptypeo)
206  {
207  const int result = ptypeo - PTYPEO_MIN;
208  assert(result >= 0);
209  return result;
210  }
211  inline PtypeO newPtypeO(Player player,Ptype ptype)
212  {
213  return static_cast<PtypeO>(static_cast<int>(ptype)-(16&static_cast<int>(player)));
214  }
215 
216 
217  inline Ptype getPtype(PtypeO ptypeO)
218  {
219  return static_cast<Ptype>(static_cast<int>(ptypeO)& 15);
220  }
221 
223  inline PtypeO promote(PtypeO ptypeO)
224  {
225  assert(canPromote(getPtype(ptypeO)));
226  PtypeO ret=static_cast<PtypeO>(static_cast<int>(ptypeO)-8);
227  assert(isPiece(getPtype(ret)));
228  return ret;
229  }
230 
232  inline PtypeO promoteWithMask(PtypeO ptypeO,int promoteMask)
233  {
234  assert(promoteMask==0 || promoteMask==0x800000);
235  PtypeO ret=static_cast<PtypeO>(static_cast<int>(ptypeO)-(promoteMask>>20));
236  return ret;
237  }
238 
240  inline PtypeO unpromote(PtypeO ptypeO)
241  {
242  return static_cast<PtypeO>(static_cast<int>(ptypeO)|8);
243  }
244 
245  bool isValidPtypeO(int ptypeO);
246 
250  inline bool isPiece(PtypeO ptypeO)
251  {
252  assert(isValidPtypeO(ptypeO));
253  return isPiece(getPtype(ptypeO));
254  }
255 
256  inline Player getOwner(PtypeO ptypeO)
257  {
258  assert(isPiece(ptypeO));
259  return static_cast<Player>(static_cast<int>(ptypeO)>>31);
260  }
261 
262 
264  inline PtypeO captured(PtypeO ptypeO)
265  {
266  assert(isPiece(ptypeO));
267  return static_cast<PtypeO>((static_cast<int>(ptypeO)|8)^(~15));
268  }
269 
271  inline PtypeO alt(PtypeO ptypeO)
272  {
273  assert(isPiece(ptypeO));
274  return static_cast<PtypeO>(static_cast<int>(ptypeO)^(~15));
275  }
276 
281  inline PtypeO altIfPiece(PtypeO ptypeO)
282  {
283  int v=static_cast<int>(ptypeO);
284  return static_cast<PtypeO>(v^((1-(v&15))&~15));
285  }
286 
287  inline bool canPromote(PtypeO ptypeO)
288  {
289  return canPromote(getPtype(ptypeO));
290  }
291 
292 
296  inline bool isPromoted(PtypeO ptypeO)
297  {
298  assert(isValidPtypeO(ptypeO));
299  return isPromoted(getPtype(ptypeO));
300  }
301 
302 
304  const PtypeO PTYPEO_EDGE __attribute__((unused)) = newPtypeO(WHITE,PTYPE_EDGE);
305 
306  std::ostream& operator<<(std::ostream& os,const PtypeO ptypeO);
307 
309 
310  enum Direction{
313  UL=0,
314  U=1,
315  UR=2,
316  L=3,
317  R=4,
318  DL=5,
319  D=6,
320  DR=7,
322  UUL=8,
323  UUR=9,
326  LONG_U=11,
328  LONG_L=13,
329  LONG_R=14,
331  LONG_D=16,
340  };
341 
342  constexpr bool isShort(Direction d){
343  return d<=SHORT_DIRECTION_MAX;
344  }
345 
346  constexpr bool isShort8(Direction d){
347  return d<=SHORT8_DIRECTION_MAX;
348  }
349 
350  constexpr bool isLong(Direction d){
351  return d>=LONG_DIRECTION_MIN;
352  }
353 
355  return static_cast<Direction>(7 - d);
356  }
357 
359  //assert(isShort8(d))
360  return inverseUnsafe(d);
361  }
362 
367  //assert(isShort8(d))
368  return (d<4) ? d : inverse(d);
369  }
375  return (d<4) ? d : inverseUnsafe(d);
376  }
377 
378  bool isValid(Direction d);
379 
381  //assert(isLong(d))
382  return static_cast<Direction>(static_cast<int>(d)-LONG_UL);
383  }
384 
389  //assert(isShort(d))
390  return static_cast<Direction>(static_cast<int>(d)+LONG_UL);
391  }
392 
393  constexpr int dirToMask(Direction dir){
394  return (1<<static_cast<int>(dir));
395  }
396 
397  std::ostream& operator<<(std::ostream& os,const Direction d);
398 
424  class Square;
425  bool operator==(Square l, Square r);
429  class Offset
430  {
431  public:
432  enum {
433  OFFSET_MIN=-0x100,
434  ONBOARD_OFFSET_MIN=-0x88,
435  OFFSET_ZERO=0,
436  ONBOARD_OFFSET_MAX=0x88,
437  OFFSET_MAX=0x100,
438  ONBOARD_OFFSET_SIZE=0x88*2+1
439  };
440  static const int BOARD_HEIGHT=16;
441  private:
442  int offset;
443  explicit Offset(int o) : offset(o)
444  {
445  }
446  public:
447  static const Offset makeDirect(int value) { return Offset(value); }
448  int intValue() const { return offset; }
449  public:
450  static int makeOffset(int dx,int dy) { return dx*BOARD_HEIGHT + dy; }
451  Offset(int dx,int dy) : offset(makeOffset(dx,dy))
452  {
453  }
455  Offset() : offset(OFFSET_ZERO)
456  {
457  }
458  template <Player, Direction>
459  static Offset make(); // defined in directionTraits.h
460  static const Offset ZERO() { return Offset(OFFSET_ZERO); }
461  int
462 #ifdef __GNUC__
463  __attribute__ ((pure))
464 #endif
465  dx() const;
466  int
467 #ifdef __GNUC__
468  __attribute__ ((pure))
469 #endif
470  dy() const;
471  unsigned int index() const { return offset - OFFSET_MIN; }
472 
474  {
475  offset += other.offset;
476  return *this;
477  }
479  offset -= other.offset;
480  return *this;
481  }
482  const Offset operator+(Offset other) const
483  {
484  Offset result(*this);
485  return result += other;
486  }
487  const Offset operator-(const Offset other) const
488  {
489  Offset result(*this);
490  return result -= other;
491  }
492  const Offset operator*(const int mult) const {
493  return static_cast<Offset>(static_cast<int>(offset)*mult);
494  }
495  const Offset operator-() const { return Offset(-offset); }
499  template <Player P>
500  const Offset blackOffset() const { return (P==BLACK) ? *this : -(*this); }
501 
502  bool zero() const { return offset == OFFSET_ZERO; }
503  };
504 
508  inline Offset newOffset(int dx,int dy){
509  return Offset(dx,dy);
510  }
511 
512  inline bool operator==(Offset l, Offset r)
513  {
514  return l.intValue() == r.intValue();
515  }
516  inline bool operator!=(Offset l, Offset r)
517  {
518  return ! (l == r);
519  }
520  inline bool operator<(Offset l, Offset r)
521  {
522  return l.intValue() < r.intValue();
523  }
524 
525 
526  std::ostream& operator<<(std::ostream&, Offset);
527 }
528 #include "bits/directionTraits.h"
529 namespace osl
530 {
531  class Square
532  {
533  unsigned int square;
534  explicit Square(int p) : square(p)
535  {
536  }
537  public:
538  static const Square makeDirect(int value) { return Square(value); }
539  unsigned int uintValue() const { return square; }
540  enum {
541  PIECE_STAND=0,
542  MIN=0,
543  SIZE=0x100
544  };
545  Square() : square(PIECE_STAND)
546  {
547  }
548  static const Square STAND() { return Square(PIECE_STAND); }
549  Square(int x, int y) : square((x*Offset::BOARD_HEIGHT)+y+1)
550  {
551  assert(square < SIZE);
552  }
556  static const Square makeNoCheck(int x, int y) {
557  return Square((x*Offset::BOARD_HEIGHT)+y+1);
558  }
559  static const Square nth(unsigned int i) { return Square(i+MIN); }
563  int x() const { return square >> 4; }
567  int y() const { return (square&0xf)-1; }
571  int y1() const { return square&0xf; }
572  unsigned int index() const { return square - MIN; }
573  static unsigned int indexMax() { return SIZE - MIN; }
574  int indexForOffset32() const { return square + (square&0xf0); }
575 
576  bool isPieceStand() const { return square == PIECE_STAND; }
577  bool isOnBoardSlow() const;
583  bool isOnBoard() const {
584  return (0xffffff88&(square-0x12)&
585  ((unsigned int)((square&0x77)^0x12)+0xffffff77))==0;
586  }
591  bool isEdge() const {
592  assert(!isPieceStand() && 0<=x() && x()<=10 && 0<=y() && y()<=10);
593  return (0x88&(square-0x12)&((square&0x11)+0xf7))!=0;
594  }
595  bool isValid() const;
596 
597 
598  const Square squareForBlack(Player player) const {
599  return (player == BLACK)
600  ? *this
601  : makeDirect(Square(9,9).uintValue()+Square(1,1).uintValue()-uintValue());
602  }
603 
608  template<Player P>
609  const Square squareForBlack() const{
610  return squareForBlack(P);
611  }
612 
613  const Square rotate180() const
614  {
615  return squareForBlack<WHITE>();
616  }
617  const Square rotate180EdgeOK() const
618  {
619  Square ret=makeDirect(Square(9,9).uintValue()+Square(1,1).uintValue()-uintValue());
620  return ret;
621  }
622  const Square rotate180Safe() const
623  {
624  if (isPieceStand())
625  return *this;
626  return squareForBlack<WHITE>();
627  }
628  const Square flipHorizontal() const
629  {
630  if (isPieceStand())
631  return *this;
632  return Square(10-x(), y());
633  }
634 
635  static const Square onBoardMax(){ return Square(9,9); }
636  static const Square onBoardMin(){ return Square(1,1); }
637 
641  bool isOnBoardRegion() const {
642  return static_cast<unsigned int>(index()-onBoardMin().index())
643  <= static_cast<unsigned int>(onBoardMax().index()-onBoardMin().index());
644  }
645 
647  square += 1;
648  return *this;
649  }
650 
651  static int reverseX(int x) { return 10-x; }
652  static int reverseY(int y) { return 10-y; }
653  public:
654  template <Player P>
655  static bool canPromoteY(int y) {
656  return P == BLACK ? y <= 3 : y >= 7;
657  }
658  template <Player P>
659  bool canPromote() const{
660  return canPromote(P);
661  }
662  bool canPromote(Player player) const
663  {
664  if (player==BLACK)
665  return (uintValue()&0xf)<=4;
666  else
667  return (uintValue()&0x8)!=0;
668  }
673  bool isULRD(Square sq) const{
674  assert(isOnBoard() && sq.isOnBoard());
675  unsigned int v=uintValue() ^ sq.uintValue();
676  return (((v+0xefull)^v)&0x110ull)!=0x110ull;
677  }
681  bool isUD(Square sq) const{
682  assert(isOnBoard() && sq.isOnBoard());
683  unsigned int v=uintValue() ^ sq.uintValue();
684  return (v&0xf0)==0;
685  }
689  template<Player P>
690  bool isU(Square sq) const{
691  assert(isOnBoard() && sq.isOnBoard());
692  unsigned int v=uintValue() ^ sq.uintValue();
693  if(P==BLACK)
694  return ((v|(uintValue()-sq.uintValue()))&0xf0)==0;
695  else
696  return ((v|(sq.uintValue()-uintValue()))&0xf0)==0;
697  }
701  bool isLR(Square sq) const{
702  assert(isOnBoard() && sq.isOnBoard());
703  unsigned int v=uintValue() ^ sq.uintValue();
704  return (v&0xf)==0;
705  }
707  square += offset.intValue();
708  return *this;
709  }
711  square -= offset.intValue();
712  return *this;
713  }
714  const Square operator+(Offset offset) const {
715  Square result(*this);
716  return result+=offset;
717  }
718  const Square operator-(Offset offset) const {
719  Square result(*this);
720  return result-=offset;
721  }
722  const Offset operator-(Square other) const {
723  return Offset::makeDirect(square - other.square);
724  }
725  template<int Y>
726  bool yEq() {
727  return (uintValue()&0xf)==(Y+1);
728  }
729  template<int Y>
730  typename std::enable_if<Y!=2,bool>::type yLe() {
731  return (uintValue()&0xf)<=(Y+1);
732  }
733  template<int Y>
734  typename std::enable_if<Y==2,bool>::type yLe() {
735  return (uintValue()&0xc)==0;
736  }
737  template<int Y>
738  typename std::enable_if<Y!=7,bool>::type yGe() {
739  return (uintValue()&0xf)>=(Y+1);
740  }
741  template<int Y>
742  typename std::enable_if<Y==7,bool>::type yGe() {
743  return (uintValue()&0x8)!=0;
744  }
745  template <Player P, Direction D>
746  const Square neighbor() const {
747  return *this + DirectionPlayerTraits<D,P>::offset();
748  }
749  template <Player P, Direction D>
750  const Square back() const {
751  return neighbor<alt(P),D>();
752  }
753  const Square neighbor(Player P, Direction D) const;
754  const Square back(Player P, Direction D) const;
755  bool isNeighboring8(Square to) const;
756  };
757 
758  inline bool operator==(Square l, Square r)
759  {
760  return l.uintValue() == r.uintValue();
761  }
762  inline bool operator!=(Square l, Square r)
763  {
764  return ! (l == r);
765  }
766  inline bool operator<(Square l, Square r)
767  {
768  return l.uintValue() < r.uintValue();
769  }
770  inline bool operator>(Square l, Square r)
771  {
772  return l.uintValue() > r.uintValue();
773  }
774  std::ostream& operator<<(std::ostream&, Square);
775 
776  class Piece;
777  inline bool operator==(Piece l, Piece r);
778  const int EMPTY_NUM=0x80;
779  const int EDGE_NUM=0x40;
787  class Piece
788  {
789  int piece;
790  Piece(int p) : piece(p)
791  {
792  }
793  public:
794  static const int SIZE=40;
795  static const Piece makeDirect(int value) { return Piece(value); }
796  int intValue() const { return piece; }
797  static const Piece EMPTY() { return Piece(BLACK,PTYPE_EMPTY,EMPTY_NUM,Square::STAND()); }
798  static const Piece EDGE() { return Piece(WHITE,PTYPE_EDGE,EDGE_NUM,Square::STAND()); }
799  static const int BitOffsetPtype=16;
800  static const int BitOffsetPromote=BitOffsetPtype+3;
801  static const int BitOffsetMovePromote=BitOffsetPromote+4;
802 
803  Piece(Player owner, Ptype ptype, int num, Square square)
804  : piece((static_cast<int>(owner)<<20)
805  +(static_cast<int>(ptype)<<BitOffsetPtype)
806  +((num)<<8)+ square.uintValue())
807  {
808  }
809  Piece() : piece(EMPTY().piece)
810  {
811  }
815  static const Piece
816 #ifdef __GNUC__
817  __attribute__ ((pure))
818 #endif
819  makeKing(Player owner, Square square);
820 
821  Ptype ptype() const {
822  return static_cast<Ptype>((piece>>BitOffsetPtype)&0xf);
823  }
824  PtypeO ptypeO() const {
825  return static_cast<PtypeO>(piece>>BitOffsetPtype);
826  }
827 
828  int number() const {
829  return ((piece&0xff00)>>8);
830  }
831 
832  const Square square() const {
833  return Square::makeDirect(piece&0xff);
834  }
835 
837  piece += offset.intValue();
838  return *this;
839  }
840 
841  void setSquare(Square square) {
842  piece = (piece&0xffffff00)+square.uintValue();
843  }
844  public:
851  template<Player P>
852  bool isOnBoardByOwner() const { return isOnBoardByOwner(P); }
856  bool isOnBoardByOwner(Player owner) const
857  {
858  if(owner==BLACK)
859  return static_cast<int>(static_cast<unsigned int>(piece)&0x800000ff)>0;
860  else
861  return static_cast<int>((-piece)&0x800000ff)>0;
862  }
863 
864  /* 成る. PROMOTE不可なpieceに適用不可 */
865  const Piece promote() const {
866  assert(canPromote(ptype()));
867  return Piece(piece-0x80000);
868  }
869 
870  /* 成りを戻す. PROMOTE不可なpieceに適用可 */
871  const Piece unpromote() const {
872  return Piece((int)piece|0x80000);
873  }
874 
879  const Piece captured() const {
880  // return (Piece)((((int)piece|0x80000)&0xffffff00)^0xfff00000);
881  // をoptimizeする
882  return Piece((piece&0xfff7ff00)^0xfff80000);
883  }
884 
885  const Piece promoteWithMask(int promote_mask) const {
886  assert(! (isPromoted() && promote_mask));
887  assert(promote_mask==0 || promote_mask==(1<<23));
888  return Piece(piece - (promote_mask>>(BitOffsetMovePromote-BitOffsetPromote)));
889  }
890 
891  const Piece checkPromote(bool promotep) const {
892  return Piece(piece - (promotep<<19));
893  }
894 
898  bool isPromoted() const { return (piece&(1<<19))==0; }
899 
904  bool isOnBoardNotPromoted() const{
905  int mask=piece&((1<<19)|0xff);
906  return mask>(1<<19);
907  }
908  bool isPromotedNotKingGold() const {
909  assert(ptype()!=KING && ptype()!=GOLD);
910  return isPromoted();
911  }
912 
913  bool isEmpty() const {
914  return (piece&0x8000)!=0;
915  }
916  static bool isEmptyNum(int num) {
917  return (num&0x80)!=0;
918  }
919  bool isEdge() const {
920  return (piece&0x4000)!=0;
921  }
922  static bool isEdgeNum(int num){
923  assert(!isEmptyNum(num));
924  return (num&0x40)!=0;
925  }
926  static bool isPieceNum(int num){
927  return (num&0xc0)==0;
928  }
929  template<Ptype T>
930  bool isPtype() const{
931  return (piece&0xf0000)==((T)<<BitOffsetPtype);
932  }
937  bool isPlayerPtype(Player pl,Ptype ptype) const{
938  assert(PTYPE_PIECE_MIN<=ptype && ptype<=PTYPE_MAX);
939  return (piece&0x1f0000)==(((ptype)<<BitOffsetPtype)|(pl&0x100000));
940  }
945  bool isPlayerBasicPtype(Player pl,Ptype ptype) const{
946  assert(PTYPE_PIECE_MIN<=ptype && ptype<=PTYPE_MAX);
947  assert(isBasic(ptype));
948  if(canPromote(ptype))
949  return (piece&0x170000)==(((osl::promote(ptype))<<BitOffsetPtype)|(pl&0x100000));
950  else
951  return isPlayerPtype(pl,ptype);
952  }
953  bool isPiece() const {
954  return (piece&0xc000)==0;
955  }
959  bool pieceIsBlack() const{
960  assert(isPiece());
961  return static_cast<int>(piece)>=0;
962  }
963  Player owner() const
964  {
965  assert(isPiece());
966  return static_cast<Player>(piece>>20);
967  }
968 
969  private:
970  public:
979  template<Player P>
980  bool canMoveOn() const { return canMoveOn(P); }
981  bool canMoveOn(Player pl) const{
982  return pl == BLACK ? ((piece+0xe0000)&0x104000)==0 : piece>=0;
983  }
984 
985  bool isOnBoard() const {
986  assert(square().isValid());
987  return ! square().isPieceStand();
988  }
989  };
990 
991  inline bool operator<(Piece l, Piece r)
992  {
993  return l.intValue() < r.intValue();
994  }
995  inline bool operator==(Piece l, Piece r)
996  {
997  return l.intValue() == r.intValue();
998  }
999  inline bool operator!=(Piece l, Piece r)
1000  {
1001  return ! (l == r);
1002  }
1003 
1004  std::ostream& operator<<(std::ostream& os,const Piece piece);
1005 }
1006 
1008 // #define MOVE_DEBUG
1009 #ifdef MOVE_DEBUG
1010 # include <cassert>
1011 # define move_assert(x) assert(x)
1012 #else
1013 # define move_assert(x)
1014 #endif
1015 // 2009/12/10 以前のfromが下位にあるパターンと
1016 // operator< を同じにしたい時に定義する.
1017 // #define PRESERVE_MOVE_ORDER
1018 
1019 namespace osl
1020 {
1021  class SimpleState;
1023  enum Move16 {
1025  };
1051  class Move
1052  {
1053  public:
1054  static const int BitOffsetPromote=Piece::BitOffsetMovePromote; // 23
1055  private:
1056  int move;
1057  explicit Move(int value) : move(value)
1058  {
1059  }
1060  enum {
1061  INVALID_VALUE = (1<<8), DECLARE_WIN = (2<<8),
1062  BLACK_PASS = 0, WHITE_PASS = ((unsigned) -1)<<28,
1063  };
1064  public:
1065  int intValue() const { return move; }
1067  unsigned int hash() const;
1071  static const unsigned int MaxUniqMoves=600;
1072  private:
1073  void init(Square from, Square to, Ptype ptype,
1074  Ptype capture_ptype, bool is_promote, Player player)
1075  {
1076  move = (to.uintValue()
1077  + (from.uintValue()<<8)
1078  + (static_cast<unsigned int>(capture_ptype)<<16)
1079  + (static_cast<unsigned int>(is_promote)<<BitOffsetPromote)
1080  + (static_cast<unsigned int>(ptype)<<24)
1081  + (static_cast<int>(player)<<28));
1082  }
1083  public:
1084  Move() : move(INVALID_VALUE)
1085  {
1086  }
1088  bool isNormal() const {
1089  // PASS や INVALID は to() が 00
1090  return move & 0x00ff;
1091  }
1092  bool isPass() const { return (move & 0xffff) == 0; }
1093  static const Move makeDirect(int value) { return Move(value); }
1094  static const Move PASS(Player P) { return Move(P<<28); }
1095  static const Move INVALID() { return Move(INVALID_VALUE); }
1096  static const Move DeclareWin() { return Move(DECLARE_WIN); }
1100  Move(Square from, Square to, Ptype ptype,
1101  Ptype capture_ptype, bool is_promote, Player player)
1102  {
1103  move_assert(from.isValid());
1104  move_assert(to.isOnBoard());
1105  move_assert(isValid(ptype));
1106  move_assert(isValid(capture_ptype));
1107  move_assert(isValid(player));
1108  init(from, to, ptype, capture_ptype, is_promote, player);
1109  move_assert(isValid());
1110  }
1114  Move(Square to, Ptype ptype, Player player)
1115  {
1116  move_assert(to.isOnBoard());
1117  move_assert(isValid(ptype));
1118  move_assert(isValid(player));
1119  init(Square::STAND(), to, ptype, PTYPE_EMPTY, false, player);
1120  move_assert(isValid());
1121  }
1122  static const Move fromMove16(Move16, const SimpleState&);
1123  Move16 toMove16() const;
1124 
1125  const Square from() const
1126  {
1127  assert(! isInvalid());
1128  move_assert(isValidOrPass());
1129  const Square result = Square::makeDirect((move>>8) & 0xff);
1130  return result;
1131  }
1132  const Square to() const {
1133  assert(! isInvalid());
1134  move_assert(isValidOrPass());
1135  const Square result = Square::makeDirect(move & 0xff);
1136  return result;
1137  }
1139  unsigned int fromTo() const { return move & 0xffff; }
1143  int promoteMask() const {
1144  assert(isNormal());
1145  return (static_cast<int>(move)&(1<<BitOffsetPromote));
1146  }
1147  bool isPromotion() const { assert(isNormal()); return (move & (1<<BitOffsetPromote))!=0; }
1148  bool isCapture() const { assert(isNormal()); return capturePtype() != PTYPE_EMPTY; }
1149  bool isCaptureOrPromotion() const { return isCapture() || isPromotion(); }
1150  bool isDrop() const { assert(isNormal()); return from().isPieceStand(); }
1151  bool isPawnDrop() const {
1152  return isDrop() && ptype() == PAWN;
1153  }
1154 
1155  Ptype ptype() const {
1156  assert(! isInvalid());
1157  move_assert(isValidOrPass());
1158  const Ptype result = static_cast<Ptype>((move >> 24) & 0xf);
1159  return result;
1160  }
1162  PtypeO ptypeO() const {
1163  assert(! isInvalid());
1164  const PtypeO result = static_cast<PtypeO>(move >> 24);
1165  return result;
1166  }
1168  PtypeO oldPtypeO() const {
1169  assert(! isInvalid());
1170  const PtypeO result = static_cast<PtypeO>((move>>24)+((move >> (BitOffsetPromote-3))&8));
1171  return result;
1172  }
1174  Ptype oldPtype() const {
1175  assert(! isInvalid());
1176  move_assert(isValidOrPass());
1177  const PtypeO old_ptypeo = static_cast<PtypeO>((move>>24)+((move >> (BitOffsetPromote-3))&8));
1178  return getPtype(old_ptypeo);
1179  }
1181  assert(isNormal());
1182  const Ptype result = static_cast<Ptype>((move>>16)&0xf);
1183  return result;
1184  }
1186  assert(isCapture());
1187  return newPtypeO(alt(player()), capturePtype());
1188  }
1190  if (! isCapture())
1191  return PTYPEO_EMPTY;
1192  return capturePtypeO();
1193  }
1194 
1195  Player player() const {
1196  assert(! isInvalid());
1197  const Player result = static_cast<Player>(move>>28);
1198  return result;
1199  }
1200  bool isValid() const;
1202  bool isInvalid() const {
1203  return static_cast<unsigned int>(move-1) < DECLARE_WIN;
1204  }
1205  bool isValidOrPass() const { return isPass() || isValid(); }
1206 
1207  Move newFrom(Square new_from) const
1208  {
1209  assert(isNormal());
1210  int result = static_cast<int>(intValue());
1211  result &= ~(0xff00);
1212  result += (new_from.uintValue()<<8);
1213  return makeDirect(result);
1214  }
1215  Move newAddFrom(Square new_from) const
1216  {
1217  assert(isNormal());
1218  assert(from().uintValue()==0);
1219  int result = static_cast<int>(intValue());
1220  result += (new_from.uintValue()<<8);
1221  return makeDirect(result);
1222  }
1226  const Move newAddCapture(Piece capture) const
1227  {
1228  assert(! isCapture());
1229  return makeDirect(intValue()+(capture.intValue()&0xf0000));
1230  }
1231  const Move newCapture(Piece capture) const
1232  {
1233  return makeDirect((intValue()&0xfff0ffff)+(capture.intValue()&0xf0000));
1234  }
1235  const Move newCapture(Ptype capture) const
1236  {
1237  return makeDirect((intValue()&0xfff0ffff)
1238  +(static_cast<int>(capture)<<Piece::BitOffsetPtype));
1239  }
1243  const Move unpromote() const {
1244  assert(isNormal());
1245  move_assert(isPromotion() && isPromoted(ptype()));
1246  return makeDirect(intValue()^((1<<BitOffsetPromote)^(1<<27)));
1247  }
1251  const Move promote() const {
1252  assert(isNormal());
1253  move_assert(!isPromotion() && canPromote(ptype()));
1254  return makeDirect(intValue()^((1<<BitOffsetPromote)^(1<<27)));
1255  }
1260  inline Move newAddTo(Offset o) const{
1261  return makeDirect(intValue()+o.intValue());
1262  }
1267  inline Move newAddTo(Square sq) const{
1268  assert((intValue()&0xff)==0);
1269  return Move::makeDirect(intValue()+sq.uintValue());
1270  }
1274  inline Move newAddPtype(Ptype newPtype) const{
1275  assert(ptype()==PTYPE_EMPTY);
1276  return Move::makeDirect(intValue()
1277  + (static_cast<unsigned int>(newPtype)<<24));
1278  }
1279  template<Player P>
1280  static bool ignoreUnpromote(Ptype ptype,Square from,Square to){
1281  switch(ptype){
1282  case PAWN:
1283  return to.canPromote<P>();
1284  case BISHOP: case ROOK:
1285  return to.canPromote<P>() || from.canPromote<P>();
1286  case LANCE:
1287  return (P==BLACK ? to.y()==2 : to.y()==8);
1288  default: return false;
1289  }
1290  }
1295  template<Player P>
1296  bool ignoreUnpromote() const{
1297  assert(player()==P);
1298  if(isDrop()) return false;
1299  return ignoreUnpromote<P>(ptype(),from(),to());
1300  }
1301  bool ignoreUnpromote() const{
1302  if(player()==BLACK) return ignoreUnpromote<BLACK>();
1303  else return ignoreUnpromote<WHITE>();
1304  }
1308  template<Player P>
1309  bool hasIgnoredUnpromote() const{
1310  assert(player()==P);
1311  if(!isPromotion()) return false;
1312  switch(ptype()){
1313  case PPAWN:
1314  return (P==BLACK ? to().y()!=1 : to().y()!=9);
1315  case PLANCE:
1316  return (P==BLACK ? to().y()==2 : to().y()==8);
1317  case PBISHOP: case PROOK:
1318  return true;
1319  default: return false;
1320  }
1321  }
1322  bool hasIgnoredUnpromote() const{
1323  if(player()==BLACK) return hasIgnoredUnpromote<BLACK>();
1324  else return hasIgnoredUnpromote<WHITE>();
1325  }
1326  const Move rotate180() const;
1327  };
1328  inline bool operator<(Move lhs, Move rhs)
1329  {
1330 #ifdef PRESERVE_MOVE_ORDER
1331  int l=lhs.intValue();
1332  l=(l&0xffff0000)+((l>>8)&0xff)+((l<<8)&0xff00);
1333  int r=rhs.intValue();
1334  r=(r&0xffff0000)+((r>>8)&0xff)+((r<<8)&0xff00);
1335  return l<r;
1336 #else
1337  return lhs.intValue() < rhs.intValue();
1338 #endif
1339  }
1340  inline bool operator==(Move lhs, Move rhs)
1341  {
1342  return lhs.intValue() == rhs.intValue();
1343  }
1344  inline bool operator!=(Move lhs, Move rhs)
1345  {
1346  return ! (lhs == rhs);
1347  }
1348 
1349  std::ostream& operator<<(std::ostream& os, Move move);
1350 }
1351 
1352 namespace std
1353 {
1354  template <typename T> struct hash;
1355  template <> struct hash<osl::Move>
1356  {
1357  unsigned long operator()(osl::Move m) const { return m.intValue(); }
1358  };
1359 } // namespace stl
1360 #endif /* OSL_BASIC_TYPE_H */
1361 // ;;; Local Variables:
1362 // ;;; mode:c++
1363 // ;;; c-basic-offset:2
1364 // ;;; coding:utf-8
1365 // ;;; End:
static bool ignoreUnpromote(Ptype ptype, Square from, Square to)
Definition: basic_type.h:1280
Square & operator+=(Offset offset)
Definition: basic_type.h:706
constexpr Direction primDirUnsafe(Direction d)
8方向について,primitiveな4方向を求める dとしてknight, INVALIDなども来る
Definition: basic_type.h:374
static const int BitOffsetMovePromote
Definition: basic_type.h:801
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す ...
Definition: basic_type.h:157
Piece(int p)
Definition: basic_type.h:790
bool isOnBoardByOwner() const
piece がプレイヤーPの持ち物でかつボード上にある駒の場合は true.
Definition: basic_type.h:852
constexpr Direction inverseUnsafe(Direction d)
Definition: basic_type.h:354
bool isOnBoard() const
Definition: basic_type.h:985
static const Piece makeDirect(int value)
Definition: basic_type.h:795
std::enable_if< Y==2, bool >::type yLe()
Definition: basic_type.h:734
Square(int x, int y)
Definition: basic_type.h:549
bool canMoveOn() const
Player Pの駒が,thisの上に移動できるか? PIECE_EMPTY 0x00008000 BLACK_PIECE 0x000XxxYY X>=2...
Definition: basic_type.h:980
bool isMajor(Ptype ptype)
Definition: basic_type.h:185
int operator+(Player, int)
int number() const
Definition: basic_type.h:828
constexpr int dirToMask(Direction dir)
Definition: basic_type.h:393
void init(Square from, Square to, Ptype ptype, Ptype capture_ptype, bool is_promote, Player player)
Definition: basic_type.h:1073
constexpr Direction inverse(Direction d)
Definition: basic_type.h:358
constexpr bool isShort(Direction d)
Definition: basic_type.h:342
PtypeO altIfPiece(PtypeO ptypeO)
Pieceの時にはowner を反転する
Definition: basic_type.h:281
static const Move makeDirect(int value)
Definition: basic_type.h:1093
constexpr Player alt(Player player)
Definition: basic_type.h:13
bool zero() const
Definition: basic_type.h:502
const Offset operator-(Square other) const
Definition: basic_type.h:722
const PtypeO PTYPEO_EDGE __attribute__((unused))
const Square operator+(Offset offset) const
Definition: basic_type.h:714
Ptype ptype() const
Definition: basic_type.h:821
Square(int p)
Definition: basic_type.h:534
Move(int value)
Definition: basic_type.h:1057
bool canMoveOn(Player pl) const
Definition: basic_type.h:981
int intValue() const
Definition: basic_type.h:796
bool isValidOrPass() const
Definition: basic_type.h:1205
static const Square makeDirect(int value)
Definition: basic_type.h:538
PtypeO capturePtypeOSafe() const
Definition: basic_type.h:1189
bool hasIgnoredUnpromote() const
MoveをunpromoteするとcutUnpromoteなMoveになる
Definition: basic_type.h:1309
const Move promote() const
unpromote moveからpromote moveを作る
Definition: basic_type.h:1251
Piece & operator+=(Offset offset)
Definition: basic_type.h:836
static const Piece EDGE()
Definition: basic_type.h:798
座標の差分
Definition: basic_type.h:429
PtypeO capturePtypeO() const
Definition: basic_type.h:1185
Ptype getPtype(PtypeO ptypeO)
Definition: basic_type.h:217
Move(Square to, Ptype ptype, Player player)
drop
Definition: basic_type.h:1114
void setSquare(Square square)
Definition: basic_type.h:841
const Move unpromote() const
promote moveからunpromote moveを作る
Definition: basic_type.h:1243
const Offset operator*(const int mult) const
Definition: basic_type.h:492
static const Move PASS(Player P)
Definition: basic_type.h:1094
const int EMPTY_NUM
Definition: basic_type.h:778
bool isPiece() const
Definition: basic_type.h:953
PtypeO ptypeO() const
Definition: basic_type.h:824
bool isNormal() const
INVALID でも PASS でもない.
Definition: basic_type.h:1088
Offset(int o)
Definition: basic_type.h:443
bool isMajorNonPieceOK(Ptype ptype)
Definition: basic_type.h:190
int y() const
将棋としてのY座標を返す.
Definition: basic_type.h:567
const Piece checkPromote(bool promotep) const
Definition: basic_type.h:891
bool isULRD(Square sq) const
2つのSquare(onBoardであることが前提)が, xが等しいかyが等しい
Definition: basic_type.h:673
const Square squareForBlack() const
後手の場合は盤面を引っくり返す.
Definition: basic_type.h:609
std::ostream & operator<<(std::ostream &os, Player player)
Definition: basic_type.cc:14
static const Piece EMPTY()
Definition: basic_type.h:797
const Offset operator+(Offset other) const
Definition: basic_type.h:482
PtypeO ptypeO() const
移動後のPtype, i.e., 成る手だった場合成った後
Definition: basic_type.h:1162
static const int BOARD_HEIGHT
Definition: basic_type.h:440
Move16
16bit 表現
Definition: basic_type.h:1023
const int PTYPE_SIZE
Definition: basic_type.h:107
Move newAddPtype(Ptype newPtype) const
作ってあったPTYPE_EMPTYのひな形のPTYPEをsetする
Definition: basic_type.h:1274
const int PTYPEO_SIZE
Definition: basic_type.h:308
int x() const
将棋としてのX座標を返す.
Definition: basic_type.h:563
const Move newCapture(Ptype capture) const
Definition: basic_type.h:1235
Square & operator-=(Offset offset)
Definition: basic_type.h:710
Ptype promote(Ptype ptype)
promote可能なptypeに対して,promote後の型を返す promote不可のptypeを与えてはいけない. ...
Definition: basic_type.h:173
bool ignoreUnpromote() const
Definition: basic_type.h:1301
PtypeO newPtypeO(Player player, Ptype ptype)
Definition: basic_type.h:211
bool isValidPtypeO(int ptypeO)
Definition: basic_type.cc:30
bool isPtype() const
Definition: basic_type.h:930
std::enable_if< Y==7, bool >::type yGe()
Definition: basic_type.h:742
static const Square makeNoCheck(int x, int y)
assertなしに作る
Definition: basic_type.h:556
Ptype
駒の種類を4ビットでコード化する
Definition: basic_type.h:83
int operator/(Player, int)
unsigned long operator()(osl::Move m) const
Definition: basic_type.h:1357
Piece(Player owner, Ptype ptype, int num, Square square)
Definition: basic_type.h:803
Ptype ptype() const
Definition: basic_type.h:1155
static bool isEdgeNum(int num)
Definition: basic_type.h:922
constexpr bool isShort8(Direction d)
Definition: basic_type.h:346
static int reverseY(int y)
Definition: basic_type.h:652
const int EDGE_NUM
Definition: basic_type.h:779
unsigned int index() const
Definition: basic_type.h:471
bool ignoreUnpromote() const
合法手ではあるが,打歩詰め絡み以外では有利にはならない手.
Definition: basic_type.h:1296
bool isOnBoard() const
盤面上を表すかどうかの判定. 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する. ...
Definition: basic_type.h:583
int intValue() const
Definition: basic_type.h:1065
static const Offset makeDirect(int value)
Definition: basic_type.h:447
const Square from() const
Definition: basic_type.h:1125
Player getOwner(PtypeO ptypeO)
Definition: basic_type.h:256
Ptype oldPtype() const
移動前のPtype, i.e., 成る手だった場合成る前
Definition: basic_type.h:1174
Move(Square from, Square to, Ptype ptype, Ptype capture_ptype, bool is_promote, Player player)
移動
Definition: basic_type.h:1100
static int reverseX(int x)
Definition: basic_type.h:651
bool yEq()
Definition: basic_type.h:726
圧縮していない moveの表現 .
Definition: basic_type.h:1051
static unsigned int indexMax()
Definition: basic_type.h:573
const Square rotate180() const
Definition: basic_type.h:613
static const Move INVALID()
Definition: basic_type.h:1095
bool isPass() const
Definition: basic_type.h:1092
bool isValid(Player player)
cast等で作られたplayerが正しいかどうかを返す
Definition: basic_type.cc:9
Move newAddTo(Square sq) const
つくってあったmoveの雛形のsquareをsetする. mのtoは0
Definition: basic_type.h:1267
bool isPromoted() const
promoteした駒かどうかをチェックする
Definition: basic_type.h:898
const Piece promoteWithMask(int promote_mask) const
Definition: basic_type.h:885
bool isBasic(Ptype ptype)
ptypeが基本型(promoteしていない)かのチェック
Definition: basic_type.h:128
constexpr Direction shortToLong(Direction d)
引数に longDirを与えてはいけない
Definition: basic_type.h:388
bool canPromote(Player player) const
Definition: basic_type.h:662
constexpr int playerToIndex(Player player)
Definition: basic_type.h:16
static bool isEmptyNum(int num)
Definition: basic_type.h:916
unsigned int index() const
Definition: basic_type.h:572
Player player() const
Definition: basic_type.h:1195
const Square neighbor() const
Definition: basic_type.h:746
int y1() const
y+1を返す
Definition: basic_type.h:571
int promoteMask() const
pieceに使うためのmaskなので
Definition: basic_type.h:1143
bool operator<(Offset l, Offset r)
Definition: basic_type.h:520
constexpr Direction primDir(Direction d)
8方向について,primitiveな4方向を求める
Definition: basic_type.h:366
Offset & operator+=(Offset other)
Definition: basic_type.h:473
constexpr int sign(Player player)
Definition: basic_type.h:23
bool isCaptureOrPromotion() const
Definition: basic_type.h:1149
const Piece promote() const
Definition: basic_type.h:865
Offset(int dx, int dy)
Definition: basic_type.h:451
constexpr Direction longToShort(Direction d)
Definition: basic_type.h:380
const Square rotate180EdgeOK() const
Definition: basic_type.h:617
unsigned int square
Definition: basic_type.h:533
static const Square nth(unsigned int i)
Definition: basic_type.h:559
bool isEdge() const
Definition: basic_type.h:919
Move newAddTo(Offset o) const
moveのtoをoffsetだけ変える. 元のtoが0以外でも使える
Definition: basic_type.h:1260
const Square flipHorizontal() const
Definition: basic_type.h:628
bool isOnBoardByOwner(Player owner) const
isOnBoardByOwner の通常関数のバージョン.
Definition: basic_type.h:856
bool canPromote(Ptype ptype)
ptypeがpromote可能な型かどうかのチェック promote済みの場合はfalseを返す
Definition: basic_type.h:147
const Offset operator-() const
Definition: basic_type.h:495
bool hasIgnoredUnpromote() const
Definition: basic_type.h:1322
const Move newCapture(Piece capture) const
Definition: basic_type.h:1231
const Square square() const
Definition: basic_type.h:832
Ptype capturePtype() const
Definition: basic_type.h:1180
constexpr Player indexToPlayer(int n)
Definition: basic_type.h:19
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
int intValue() const
Definition: basic_type.h:448
Offset newOffset(int dx, int dy)
Definition: basic_type.h:508
Direction
Definition: basic_type.h:310
PtypeO oldPtypeO() const
移動前のPtypeO, i.e., 成る手だった場合成る前
Definition: basic_type.h:1168
int indexForOffset32() const
Definition: basic_type.h:574
static const Move DeclareWin()
Definition: basic_type.h:1096
static const int BitOffsetPtype
Definition: basic_type.h:799
bool isUD(Square sq) const
2つのSquare(onBoardであることが前提)のxが等しい
Definition: basic_type.h:681
static const Square onBoardMax()
Definition: basic_type.h:635
constexpr bool isPiece(Ptype ptype)
ptypeが空白やEDGEでないかのチェック
Definition: basic_type.h:120
static bool canPromoteY(int y)
Definition: basic_type.h:655
std::enable_if< Y!=2, bool >::type yLe()
Definition: basic_type.h:730
const Square back() const
Definition: basic_type.h:750
const PtypeO PTYPEO_EMPTY
Definition: basic_type.h:303
Move newFrom(Square new_from) const
Definition: basic_type.h:1207
constexpr bool isLong(Direction d)
Definition: basic_type.h:350
bool isPromoted(Ptype ptype)
ptypeがpromote後の型かどうかのチェック
Definition: basic_type.h:137
const Offset operator-(const Offset other) const
Definition: basic_type.h:487
static const Square onBoardMin()
Definition: basic_type.h:636
bool isPlayerPtype(Player pl, Ptype ptype) const
あるpieceがPlayer pの持ち物でPtype ptypeであるかどうかをチェックする. TはEMPTY, EDGEではない. ...
Definition: basic_type.h:937
bool isPromotion() const
Definition: basic_type.h:1147
std::enable_if< Y!=7, bool >::type yGe()
Definition: basic_type.h:738
bool isEmpty() const
Definition: basic_type.h:913
bool isOnBoardNotPromoted() const
promoteしていないOnBoardの駒であることのチェック Lance位しか使い道がない?
Definition: basic_type.h:904
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に,ownerを反転する.
Definition: basic_type.h:264
static bool isPieceNum(int num)
Definition: basic_type.h:926
static int makeOffset(int dx, int dy)
Definition: basic_type.h:450
constexpr int playerToMask(Player player)
Definition: basic_type.h:28
Player
Definition: basic_type.h:8
bool isLR(Square sq) const
2つのSquare(onBoardであることが前提)のyが等しい
Definition: basic_type.h:701
bool isU(Square sq) const
sqがPlayer Pにとって上
Definition: basic_type.h:690
bool isPromotedNotKingGold() const
Definition: basic_type.h:908
const Offset blackOffset() const
Player P からみた offset を黒番のものに変更する
Definition: basic_type.h:500
constexpr Ptype unpromoteSafe(Ptype ptype)
Definition: basic_type.h:164
bool isPawnDrop() const
Definition: basic_type.h:1151
const Piece unpromote() const
Definition: basic_type.h:871
bool operator==(Square l, Square r)
Definition: basic_type.h:758
const Square squareForBlack(Player player) const
Definition: basic_type.h:598
bool operator>(Square l, Square r)
Definition: basic_type.h:770
int operator*(Player, int)
Square & operator++()
Definition: basic_type.h:646
#define move_assert(x)
move 関係でつかまえ所のないエラーがでるときに定義する
Definition: basic_type.h:1013
bool isPieceStand() const
Definition: basic_type.h:576
int operator-(Player, int)
unsigned int ptypeOIndex(PtypeO ptypeo)
Definition: basic_type.h:205
bool isEdge() const
onBoardから8近傍のオフセットを足した点がedgeかどうかの判定 そこそこ速くなった.
Definition: basic_type.h:591
bool isPlayerBasicPtype(Player pl, Ptype ptype) const
あるpieceがPlayer pの持ち物でBASIC typeがptypeであるかどうかをチェックする. TはEMPTY, EDGEではない.
Definition: basic_type.h:945
bool operator!=(Offset l, Offset r)
Definition: basic_type.h:516
const Square rotate180Safe() const
Definition: basic_type.h:622
const Square operator-(Offset offset) const
Definition: basic_type.h:718
std::istream & operator>>(std::istream &is, Ptype &ptype)
Definition: basic_type.cc:35
static const Offset ZERO()
Definition: basic_type.h:460
Offset & operator-=(Offset other)
Definition: basic_type.h:478
bool canPromote() const
Definition: basic_type.h:659
unsigned int uintValue() const
Definition: basic_type.h:539
static const Square STAND()
Definition: basic_type.h:548
bool isOnBoardRegion() const
squareがONBOARD_MINとONBOARD_MAXの間にある
Definition: basic_type.h:641
const Move newAddCapture(Piece capture) const
no capture moveからcapture moveを作る
Definition: basic_type.h:1226
Move newAddFrom(Square new_from) const
Definition: basic_type.h:1215
bool isMajorBasic(Ptype ptype)
Definition: basic_type.h:181
const Piece captured() const
取られたpieceを作成.
Definition: basic_type.h:879
bool isCapture() const
Definition: basic_type.h:1148
unsigned int fromTo() const
fromとtoをまとめて同一性の判定など
Definition: basic_type.h:1139
bool isInvalid() const
state に apply 可能でない場合にtrue
Definition: basic_type.h:1202
bool pieceIsBlack() const
pieceであることが分かっている時に,更にBlackかどうかをチェックする.
Definition: basic_type.h:959
PtypeO promoteWithMask(PtypeO ptypeO, int promoteMask)
pieceを引数次第でpromoteさせる
Definition: basic_type.h:232
Player owner() const
Definition: basic_type.h:963
bool isValid() const
Definition: basic_type.cc:184