My Project
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,
339  DIRECTION_SIZE=18
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,
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; }
452  {
453  }
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 {
542  MIN=0,
543  SIZE=0x100
544  };
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
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  {
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;
802 
804  : piece((static_cast<int>(owner)<<20)
805  +(static_cast<int>(ptype)<<BitOffsetPtype)
806  +((num)<<8)+ square.uintValue())
807  {
808  }
810  {
811  }
815  static const Piece
816 #ifdef __GNUC__
817  __attribute__ ((pure))
818 #endif
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 
842  piece = (piece&0xffffff00)+square.uintValue();
843  }
844  public:
851  template<Player P>
852  bool isOnBoardByOwner() const { return isOnBoardByOwner(P); }
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  }
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:
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:
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:
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); }
1101  Ptype capture_ptype, bool is_promote, Player player)
1102  {
1106  move_assert(isValid(capture_ptype));
1108  init(from, to, ptype, capture_ptype, is_promote, player);
1109  move_assert(isValid());
1110  }
1115  {
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());
1129  const Square result = Square::makeDirect((move>>8) & 0xff);
1130  return result;
1131  }
1132  const Square to() const {
1133  assert(! isInvalid());
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());
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());
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());
1246  return makeDirect(intValue()^((1<<BitOffsetPromote)^(1<<27)));
1247  }
1251  const Move promote() const {
1252  assert(isNormal());
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>
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:
osl::Offset::ONBOARD_OFFSET_SIZE
@ ONBOARD_OFFSET_SIZE
Definition: basic_type.h:438
osl::Piece::number
int number() const
Definition: basic_type.h:828
osl::UR
@ UR
Definition: basic_type.h:315
osl::PTYPE_PIECE_MIN
@ PTYPE_PIECE_MIN
Definition: basic_type.h:104
osl::Square
Definition: basic_type.h:532
osl::LONG_L
@ LONG_L
Definition: basic_type.h:328
osl::isMajor
bool isMajor(Ptype ptype)
Definition: basic_type.h:185
osl::primDirUnsafe
constexpr Direction primDirUnsafe(Direction d)
8方向について,primitiveな4方向を求める dとしてknight, INVALIDなども来る
Definition: basic_type.h:374
osl::Move::capturePtypeOSafe
PtypeO capturePtypeOSafe() const
Definition: basic_type.h:1189
osl::Move::isInvalid
bool isInvalid() const
state に apply 可能でない場合にtrue
Definition: basic_type.h:1202
osl::Square::reverseY
static int reverseY(int y)
Definition: basic_type.h:652
osl::Square::SIZE
@ SIZE
Definition: basic_type.h:543
osl::Move::Move
Move()
Definition: basic_type.h:1084
osl::Offset::ZERO
static const Offset ZERO()
Definition: basic_type.h:460
osl::Move::toMove16
Move16 toMove16() const
Definition: basic_type.cc:336
osl::WHITE
@ WHITE
Definition: basic_type.h:10
osl::Move::hasIgnoredUnpromote
bool hasIgnoredUnpromote() const
MoveをunpromoteするとcutUnpromoteなMoveになる
Definition: basic_type.h:1309
osl::Square::isOnBoard
bool isOnBoard() const
盤面上を表すかどうかの判定. 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する.
Definition: basic_type.h:583
osl::Piece::canMoveOn
bool canMoveOn() const
Player Pの駒が,thisの上に移動できるか? PIECE_EMPTY 0x00008000 BLACK_PIECE 0x000XxxYY X>=2, YY>0 PIECE_EDGE 0xfff1...
Definition: basic_type.h:980
osl::Piece::SIZE
static const int SIZE
Definition: basic_type.h:794
osl::operator+
int operator+(Player, int)
osl::R
@ R
Definition: basic_type.h:317
std::hash
Definition: basic_type.h:1354
osl::inverse
constexpr Direction inverse(Direction d)
Definition: basic_type.h:358
osl::LONG_DR
@ LONG_DR
Definition: basic_type.h:332
osl::LONG_DL
@ LONG_DL
Definition: basic_type.h:330
osl::Offset::makeDirect
static const Offset makeDirect(int value)
Definition: basic_type.h:447
osl::alt
constexpr Player alt(Player player)
Definition: basic_type.h:13
osl::Piece::promote
const Piece promote() const
Definition: basic_type.h:865
osl::Square::nth
static const Square nth(unsigned int i)
Definition: basic_type.h:559
osl::PTYPE_SIZE
const int PTYPE_SIZE
Definition: basic_type.h:107
osl::Piece::canMoveOn
bool canMoveOn(Player pl) const
Definition: basic_type.h:981
osl::misc::Player2Type::value
@ value
Definition: basic_type.h:75
osl::misc::Int2Type::value
@ value
Definition: basic_type.h:69
osl::Piece::piece
int piece
Definition: basic_type.h:789
osl::Piece::intValue
int intValue() const
Definition: basic_type.h:796
osl::PLANCE
@ PLANCE
Definition: basic_type.h:88
osl::Square::operator-
const Offset operator-(Square other) const
Definition: basic_type.h:722
directionTraits.h
osl::Offset::dx
int dx() const
Offsetから一般に dxは求まらないので, ここでの入力は12近傍のみとする
Definition: basic_type.cc:119
osl::Offset::offset
int offset
Definition: basic_type.h:442
osl::promote
Ptype promote(Ptype ptype)
promote可能なptypeに対して,promote後の型を返す promote不可のptypeを与えてはいけない.
Definition: basic_type.h:173
osl::Square::canPromote
bool canPromote(Player player) const
Definition: basic_type.h:662
osl::isMajorNonPieceOK
bool isMajorNonPieceOK(Ptype ptype)
Definition: basic_type.h:190
osl::isValidPtypeO
bool isValidPtypeO(int ptypeO)
Definition: basic_type.cc:30
osl::Move::rotate180
const Move rotate180() const
Definition: basic_type.cc:262
osl::Move::promote
const Move promote() const
unpromote moveからpromote moveを作る
Definition: basic_type.h:1251
osl::Move::isValid
bool isValid() const
Definition: basic_type.cc:246
osl::Move::Move
Move(Square to, Ptype ptype, Player player)
drop
Definition: basic_type.h:1114
osl::Square::makeNoCheck
static const Square makeNoCheck(int x, int y)
assertなしに作る
Definition: basic_type.h:556
osl::Move::MaxUniqMoves
static const unsigned int MaxUniqMoves
一局面辺りの合法手の最大値 重複して手を生成することがある場合は,600では不足かもしれない
Definition: basic_type.h:1071
osl::getPtype
Ptype getPtype(PtypeO ptypeO)
Definition: basic_type.h:217
osl::PSILVER
@ PSILVER
Definition: basic_type.h:90
osl::Move
圧縮していない moveの表現 .
Definition: basic_type.h:1052
osl::Square::yLe
std::enable_if< Y==2, bool >::type yLe()
Definition: basic_type.h:734
osl::Move::isCaptureOrPromotion
bool isCaptureOrPromotion() const
Definition: basic_type.h:1149
osl::Move::DECLARE_WIN
@ DECLARE_WIN
Definition: basic_type.h:1061
osl::Move::newAddPtype
Move newAddPtype(Ptype newPtype) const
作ってあったPTYPE_EMPTYのひな形のPTYPEをsetする
Definition: basic_type.h:1274
osl::isShort
constexpr bool isShort(Direction d)
Definition: basic_type.h:342
osl::LONG_DIRECTION_MAX
@ LONG_DIRECTION_MAX
Definition: basic_type.h:333
osl::altIfPiece
PtypeO altIfPiece(PtypeO ptypeO)
Pieceの時にはowner を反転する
Definition: basic_type.h:281
osl::Piece::makeKing
static const Piece makeKing(Player owner, Square square)
玉を作る
Definition: basic_type.cc:231
osl::Piece::BitOffsetPtype
static const int BitOffsetPtype
Definition: basic_type.h:799
osl::Piece::EMPTY
static const Piece EMPTY()
Definition: basic_type.h:797
osl::Piece::ptypeO
PtypeO ptypeO() const
Definition: basic_type.h:824
osl::UUL
@ UUL
Definition: basic_type.h:322
osl::Offset::BOARD_HEIGHT
static const int BOARD_HEIGHT
Definition: basic_type.h:440
osl::Piece::isOnBoardByOwner
bool isOnBoardByOwner(Player owner) const
isOnBoardByOwner の通常関数のバージョン.
Definition: basic_type.h:856
osl::Square::isOnBoardRegion
bool isOnBoardRegion() const
squareがONBOARD_MINとONBOARD_MAXの間にある
Definition: basic_type.h:641
osl::Move::BLACK_PASS
@ BLACK_PASS
Definition: basic_type.h:1062
osl::SimpleState
Definition: simpleState.h:35
osl::Piece::BitOffsetPromote
static const int BitOffsetPromote
Definition: basic_type.h:800
osl::DIRECTION_SIZE
@ DIRECTION_SIZE
Definition: basic_type.h:339
osl::Move::INVALID
static const Move INVALID()
Definition: basic_type.h:1095
osl::newPtypeO
PtypeO newPtypeO(Player player, Ptype ptype)
Definition: basic_type.h:211
osl::Square::isValid
bool isValid() const
Definition: basic_type.cc:184
osl::getOwner
Player getOwner(PtypeO ptypeO)
Definition: basic_type.h:256
osl::Offset
座標の差分
Definition: basic_type.h:430
osl::LONG_D
@ LONG_D
Definition: basic_type.h:331
osl::Piece::setSquare
void setSquare(Square square)
Definition: basic_type.h:841
osl::PTYPEO_MAX
@ PTYPEO_MAX
Definition: basic_type.h:201
osl::Ptype
Ptype
駒の種類を4ビットでコード化する
Definition: basic_type.h:84
osl::DIRECTION_MAX
@ DIRECTION_MAX
Definition: basic_type.h:337
osl::LANCE
@ LANCE
Definition: basic_type.h:96
osl::misc::Player2Type
Definition: basic_type.h:75
osl::UUR
@ UUR
Definition: basic_type.h:323
osl::DIRECTION_MIN
@ DIRECTION_MIN
Definition: basic_type.h:334
osl::PTYPEO_SIZE
const int PTYPEO_SIZE
Definition: basic_type.h:308
osl::Piece::isPromotedNotKingGold
bool isPromotedNotKingGold() const
Definition: basic_type.h:908
osl::Move::ignoreUnpromote
static bool ignoreUnpromote(Ptype ptype, Square from, Square to)
Definition: basic_type.h:1280
osl::Square::operator+=
Square & operator+=(Offset offset)
Definition: basic_type.h:706
osl::D
@ D
Definition: basic_type.h:319
osl::EMPTY_NUM
const int EMPTY_NUM
Definition: basic_type.h:778
osl::DirectionPlayerTraits
Definition: directionTraits.h:242
osl::EDGE_NUM
const int EDGE_NUM
Definition: basic_type.h:779
osl::Piece::checkPromote
const Piece checkPromote(bool promotep) const
Definition: basic_type.h:891
osl::Move::hasIgnoredUnpromote
bool hasIgnoredUnpromote() const
Definition: basic_type.h:1322
osl::Move::promoteMask
int promoteMask() const
pieceに使うためのmaskなので
Definition: basic_type.h:1143
osl::Piece::isPtype
bool isPtype() const
Definition: basic_type.h:930
osl::Piece
駒.
Definition: basic_type.h:788
osl::Offset::zero
bool zero() const
Definition: basic_type.h:502
osl::SHORT8_DIRECTION_MAX
@ SHORT8_DIRECTION_MAX
Definition: basic_type.h:321
osl::Offset::operator-
const Offset operator-() const
Definition: basic_type.h:495
osl::GOLD
@ GOLD
Definition: basic_type.h:94
osl::operator/
int operator/(Player, int)
osl::Move::isCapture
bool isCapture() const
Definition: basic_type.h:1148
osl::Move::init
void init(Square from, Square to, Ptype ptype, Ptype capture_ptype, bool is_promote, Player player)
Definition: basic_type.h:1073
osl::operator<<
std::ostream & operator<<(std::ostream &os, Player player)
Definition: basic_type.cc:14
osl::Square::yEq
bool yEq()
Definition: basic_type.h:726
osl::DR
@ DR
Definition: basic_type.h:320
osl::Piece::Piece
Piece(int p)
Definition: basic_type.h:790
osl::LONG_R
@ LONG_R
Definition: basic_type.h:329
osl::Square::onBoardMax
static const Square onBoardMax()
Definition: basic_type.h:635
osl::Move::fromMove16
static const Move fromMove16(Move16, const SimpleState &)
Definition: basic_type.cc:317
osl::Move::oldPtype
Ptype oldPtype() const
移動前のPtype, i.e., 成る手だった場合成る前
Definition: basic_type.h:1174
osl::Square::isUD
bool isUD(Square sq) const
2つのSquare(onBoardであることが前提)のxが等しい
Definition: basic_type.h:681
osl::PTYPE_MAX
@ PTYPE_MAX
Definition: basic_type.h:105
osl::Move16
Move16
16bit 表現
Definition: basic_type.h:1023
osl::Square::uintValue
unsigned int uintValue() const
Definition: basic_type.h:539
osl::isShort8
constexpr bool isShort8(Direction d)
Definition: basic_type.h:346
osl::Square::canPromoteY
static bool canPromoteY(int y)
Definition: basic_type.h:655
osl::Square::isPieceStand
bool isPieceStand() const
Definition: basic_type.h:576
osl::Piece::makeDirect
static const Piece makeDirect(int value)
Definition: basic_type.h:795
osl::Move::newAddFrom
Move newAddFrom(Square new_from) const
Definition: basic_type.h:1215
osl::KING
@ KING
Definition: basic_type.h:93
osl::LONG_U
@ LONG_U
Definition: basic_type.h:326
osl::Move::oldPtypeO
PtypeO oldPtypeO() const
移動前のPtypeO, i.e., 成る手だった場合成る前
Definition: basic_type.h:1168
osl::Square::index
unsigned int index() const
Definition: basic_type.h:572
osl::DIRECTION_INVALID_VALUE
@ DIRECTION_INVALID_VALUE
Definition: basic_type.h:338
osl::Move::newAddCapture
const Move newAddCapture(Piece capture) const
no capture moveからcapture moveを作る
Definition: basic_type.h:1226
osl::BISHOP
@ BISHOP
Definition: basic_type.h:99
osl::Square::isOnBoardSlow
bool isOnBoardSlow() const
Definition: basic_type.cc:178
osl::Move::unpromote
const Move unpromote() const
promote moveからunpromote moveを作る
Definition: basic_type.h:1243
osl::Move::ignoreUnpromote
bool ignoreUnpromote() const
Definition: basic_type.h:1301
osl::Move::capturePtype
Ptype capturePtype() const
Definition: basic_type.h:1180
osl::Offset::operator-=
Offset & operator-=(Offset other)
Definition: basic_type.h:478
osl::Offset::blackOffset
const Offset blackOffset() const
Player P からみた offset を黒番のものに変更する
Definition: basic_type.h:500
osl::Offset::Offset
Offset(int o)
Definition: basic_type.h:443
osl::Move::DeclareWin
static const Move DeclareWin()
Definition: basic_type.h:1096
osl::Piece::isEmptyNum
static bool isEmptyNum(int num)
Definition: basic_type.h:916
osl::Square::isU
bool isU(Square sq) const
sqがPlayer Pにとって上
Definition: basic_type.h:690
osl::Move::isDrop
bool isDrop() const
Definition: basic_type.h:1150
osl::Offset::operator*
const Offset operator*(const int mult) const
Definition: basic_type.h:492
osl::Move::ptypeO
PtypeO ptypeO() const
移動後のPtype, i.e., 成る手だった場合成った後
Definition: basic_type.h:1162
osl::Offset::OFFSET_ZERO
@ OFFSET_ZERO
Definition: basic_type.h:435
osl::PAWN
@ PAWN
Definition: basic_type.h:95
osl::Square::isULRD
bool isULRD(Square sq) const
2つのSquare(onBoardであることが前提)が, xが等しいかyが等しい
Definition: basic_type.h:673
osl::Offset::index
unsigned int index() const
Definition: basic_type.h:471
osl::PPAWN
@ PPAWN
Definition: basic_type.h:87
osl::Square::square
unsigned int square
Definition: basic_type.h:533
osl::Move::isValidOrPass
bool isValidOrPass() const
Definition: basic_type.h:1205
osl::indexToPlayer
constexpr Player indexToPlayer(int n)
Definition: basic_type.h:19
osl::PKNIGHT
@ PKNIGHT
Definition: basic_type.h:89
osl::isBasic
bool isBasic(Ptype ptype)
ptypeが基本型(promoteしていない)かのチェック
Definition: basic_type.h:128
osl::shortToLong
constexpr Direction shortToLong(Direction d)
引数に longDirを与えてはいけない
Definition: basic_type.h:388
osl::Piece::isOnBoardByOwner
bool isOnBoardByOwner() const
piece がプレイヤーPの持ち物でかつボード上にある駒の場合は true.
Definition: basic_type.h:852
osl::L
@ L
Definition: basic_type.h:316
osl::Square::Square
Square(int x, int y)
Definition: basic_type.h:549
osl::Move::newCapture
const Move newCapture(Ptype capture) const
Definition: basic_type.h:1235
osl::Offset::OFFSET_MAX
@ OFFSET_MAX
Definition: basic_type.h:437
osl::PTYPE_MIN
@ PTYPE_MIN
Definition: basic_type.h:102
osl::Piece::isPromoted
bool isPromoted() const
promoteした駒かどうかをチェックする
Definition: basic_type.h:898
osl::Square::squareForBlack
const Square squareForBlack() const
後手の場合は盤面を引っくり返す.
Definition: basic_type.h:609
osl::Square::flipHorizontal
const Square flipHorizontal() const
Definition: basic_type.h:628
osl::Square::indexMax
static unsigned int indexMax()
Definition: basic_type.h:573
osl::Move::newFrom
Move newFrom(Square new_from) const
Definition: basic_type.h:1207
osl::Square::operator++
Square & operator++()
Definition: basic_type.h:646
osl::Offset::ONBOARD_OFFSET_MIN
@ ONBOARD_OFFSET_MIN
Definition: basic_type.h:434
osl::misc::Int2Type
Definition: basic_type.h:69
osl::Move::isNormal
bool isNormal() const
INVALID でも PASS でもない.
Definition: basic_type.h:1088
osl::Piece::owner
Player owner() const
Definition: basic_type.h:963
osl::Square::operator-=
Square & operator-=(Offset offset)
Definition: basic_type.h:710
osl::Move::move
int move
Definition: basic_type.h:1056
osl::Square::Square
Square(int p)
Definition: basic_type.h:534
osl::PBISHOP
@ PBISHOP
Definition: basic_type.h:91
osl::Piece::promoteWithMask
const Piece promoteWithMask(int promote_mask) const
Definition: basic_type.h:885
osl::Square::rotate180Safe
const Square rotate180Safe() const
Definition: basic_type.h:622
osl::Move::from
const Square from() const
Definition: basic_type.h:1125
osl::Offset::OFFSET_MIN
@ OFFSET_MIN
Definition: basic_type.h:433
osl::Square::yGe
std::enable_if< Y==7, bool >::type yGe()
Definition: basic_type.h:742
osl::isValid
bool isValid(Player player)
cast等で作られたplayerが正しいかどうかを返す
Definition: basic_type.cc:9
osl::Square::x
int x() const
将棋としてのX座標を返す.
Definition: basic_type.h:563
osl::PtypeO
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
Definition: basic_type.h:199
osl::Piece::isPiece
bool isPiece() const
Definition: basic_type.h:953
osl::Move::INVALID_VALUE
@ INVALID_VALUE
Definition: basic_type.h:1061
osl::captured
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に,ownerを反転する.
Definition: basic_type.h:264
osl::Square::yGe
std::enable_if< Y!=7, bool >::type yGe()
Definition: basic_type.h:738
osl::Square::back
const Square back() const
Definition: basic_type.h:750
osl::Direction
Direction
Definition: basic_type.h:310
osl::Offset::operator-
const Offset operator-(const Offset other) const
Definition: basic_type.h:487
osl::Square::isEdge
bool isEdge() const
onBoardから8近傍のオフセットを足した点がedgeかどうかの判定 そこそこ速くなった.
Definition: basic_type.h:591
osl::Offset::makeOffset
static int makeOffset(int dx, int dy)
Definition: basic_type.h:450
osl::playerToIndex
constexpr int playerToIndex(Player player)
Definition: basic_type.h:16
osl::ROOK
@ ROOK
Definition: basic_type.h:100
osl::Square::canPromote
bool canPromote() const
Definition: basic_type.h:659
osl::Move::newAddTo
Move newAddTo(Offset o) const
moveのtoをoffsetだけ変える. 元のtoが0以外でも使える
Definition: basic_type.h:1260
osl::isPiece
constexpr bool isPiece(Ptype ptype)
ptypeが空白やEDGEでないかのチェック
Definition: basic_type.h:120
osl::Square::neighbor
const Square neighbor() const
Definition: basic_type.h:746
osl::unpromoteSafe
constexpr Ptype unpromoteSafe(Ptype ptype)
Definition: basic_type.h:164
std::hash< osl::Move >::operator()
unsigned long operator()(osl::Move m) const
Definition: basic_type.h:1357
osl::Move::WHITE_PASS
@ WHITE_PASS
Definition: basic_type.h:1062
osl::Square::y
int y() const
将棋としてのY座標を返す.
Definition: basic_type.h:567
osl::Move::newAddTo
Move newAddTo(Square sq) const
つくってあったmoveの雛形のsquareをsetする. mのtoは0
Definition: basic_type.h:1267
osl::operator<
bool operator<(Offset l, Offset r)
Definition: basic_type.h:520
osl::primDir
constexpr Direction primDir(Direction d)
8方向について,primitiveな4方向を求める
Definition: basic_type.h:366
osl::sign
constexpr int sign(Player player)
Definition: basic_type.h:23
osl::isLong
constexpr bool isLong(Direction d)
Definition: basic_type.h:350
osl::Move::PASS
static const Move PASS(Player P)
Definition: basic_type.h:1094
osl::misc::EmptyType
Definition: basic_type.h:77
osl::isPromoted
bool isPromoted(Ptype ptype)
ptypeがpromote後の型かどうかのチェック
Definition: basic_type.h:137
osl::operator==
bool operator==(Square l, Square r)
Definition: basic_type.h:758
move_assert
#define move_assert(x)
move 関係でつかまえ所のないエラーがでるときに定義する
Definition: basic_type.h:1013
osl::PTYPEO_MIN
@ PTYPEO_MIN
Definition: basic_type.h:200
osl::Square::isNeighboring8
bool isNeighboring8(Square to) const
Definition: basic_type.cc:202
osl::Piece::square
const Square square() const
Definition: basic_type.h:832
osl::longToShort
constexpr Direction longToShort(Direction d)
Definition: basic_type.h:380
osl::operator>
bool operator>(Square l, Square r)
Definition: basic_type.h:770
osl::Piece::EDGE
static const Piece EDGE()
Definition: basic_type.h:798
osl::Piece::ptype
Ptype ptype() const
Definition: basic_type.h:821
osl::Move::capturePtypeO
PtypeO capturePtypeO() const
Definition: basic_type.h:1185
osl::newOffset
Offset newOffset(int dx, int dy)
@obsolete
Definition: basic_type.h:508
std
Definition: basic_type.h:1353
osl::Piece::isEmpty
bool isEmpty() const
Definition: basic_type.h:913
osl::Move::isPass
bool isPass() const
Definition: basic_type.h:1092
osl::Square::MIN
@ MIN
Definition: basic_type.h:542
osl::SHORT_DIRECTION_SIZE
@ SHORT_DIRECTION_SIZE
Definition: basic_type.h:336
osl::Move::ptype
Ptype ptype() const
Definition: basic_type.h:1155
osl::BLACK
@ BLACK
Definition: basic_type.h:9
osl::ptypeOIndex
unsigned int ptypeOIndex(PtypeO ptypeo)
Definition: basic_type.h:205
osl::Offset::make
static Offset make()
Definition: directionTraits.h:265
osl::canPromote
bool canPromote(Ptype ptype)
ptypeがpromote可能な型かどうかのチェック promote済みの場合はfalseを返す
Definition: basic_type.h:147
osl::PTYPE_BASIC_MIN
@ PTYPE_BASIC_MIN
Definition: basic_type.h:103
osl::PTYPE_EDGE
@ PTYPE_EDGE
Definition: basic_type.h:86
osl::Piece::operator+=
Piece & operator+=(Offset offset)
Definition: basic_type.h:836
osl::Piece::isPlayerPtype
bool isPlayerPtype(Player pl, Ptype ptype) const
あるpieceがPlayer pの持ち物でPtype ptypeであるかどうかをチェックする. TはEMPTY, EDGEではない.
Definition: basic_type.h:937
osl::PTYPEO_EMPTY
const PtypeO PTYPEO_EMPTY
Definition: basic_type.h:303
osl::Move::ignoreUnpromote
bool ignoreUnpromote() const
合法手ではあるが,打歩詰め絡み以外では有利にはならない手.
Definition: basic_type.h:1296
misc
osl::DL
@ DL
Definition: basic_type.h:318
osl::Square::operator-
const Square operator-(Offset offset) const
Definition: basic_type.h:718
osl::Piece::isOnBoardNotPromoted
bool isOnBoardNotPromoted() const
promoteしていないOnBoardの駒であることのチェック Lance位しか使い道がない?
Definition: basic_type.h:904
osl::Offset::ONBOARD_OFFSET_MAX
@ ONBOARD_OFFSET_MAX
Definition: basic_type.h:436
osl::SILVER
@ SILVER
Definition: basic_type.h:98
osl::LONG_UL
@ LONG_UL
Definition: basic_type.h:325
osl::Square::rotate180
const Square rotate180() const
Definition: basic_type.h:613
osl::Offset::Offset
Offset()
Definition: basic_type.h:455
config.h
osl::Piece::isPieceNum
static bool isPieceNum(int num)
Definition: basic_type.h:926
osl::Square::indexForOffset32
int indexForOffset32() const
Definition: basic_type.h:574
osl::Square::makeDirect
static const Square makeDirect(int value)
Definition: basic_type.h:538
osl::Piece::Piece
Piece(Player owner, Ptype ptype, int num, Square square)
Definition: basic_type.h:803
osl::PTYPE_EMPTY
@ PTYPE_EMPTY
Definition: basic_type.h:85
osl::Square::PIECE_STAND
@ PIECE_STAND
Definition: basic_type.h:541
osl::PROOK
@ PROOK
Definition: basic_type.h:92
osl::Square::rotate180EdgeOK
const Square rotate180EdgeOK() const
Definition: basic_type.h:617
osl::Offset::operator+
const Offset operator+(Offset other) const
Definition: basic_type.h:482
osl::Square::yLe
std::enable_if< Y!=2, bool >::type yLe()
Definition: basic_type.h:730
osl::Offset::intValue
int intValue() const
Definition: basic_type.h:448
osl::Square::y1
int y1() const
y+1を返す
Definition: basic_type.h:571
osl::Offset::Offset
Offset(int dx, int dy)
Definition: basic_type.h:451
osl::Piece::captured
const Piece captured() const
取られたpieceを作成.
Definition: basic_type.h:879
osl::Offset::dy
int dy() const
Offsetから一般に dyは求まらないので, ここでの入力は12近傍のみとする
Definition: basic_type.cc:146
osl::Move::newCapture
const Move newCapture(Piece capture) const
Definition: basic_type.h:1231
osl::Player
Player
Definition: basic_type.h:8
osl::operator-
int operator-(Player, int)
osl::Move::hash
unsigned int hash() const
駒を取らない手を [0, 16305] にmap
Definition: basic_type.cc:309
osl::SHORT_DIRECTION_MAX
@ SHORT_DIRECTION_MAX
Definition: basic_type.h:335
osl::misc::Type2Type
Definition: basic_type.h:72
osl::operator!=
bool operator!=(Offset l, Offset r)
Definition: basic_type.h:516
osl::Move::Move
Move(Square from, Square to, Ptype ptype, Ptype capture_ptype, bool is_promote, Player player)
移動
Definition: basic_type.h:1100
osl::SHORT_DIRECTION_MIN
@ SHORT_DIRECTION_MIN
Definition: basic_type.h:311
osl::Piece::unpromote
const Piece unpromote() const
Definition: basic_type.h:871
osl::Move::fromTo
unsigned int fromTo() const
fromとtoをまとめて同一性の判定など
Definition: basic_type.h:1139
osl::UL
@ UL
Definition: basic_type.h:313
osl::LONG_DIRECTION_MIN
@ LONG_DIRECTION_MIN
Definition: basic_type.h:324
osl::Square::Square
Square()
Definition: basic_type.h:545
osl::Square::STAND
static const Square STAND()
Definition: basic_type.h:548
osl::SHORT8_DIRECTION_MIN
@ SHORT8_DIRECTION_MIN
Definition: basic_type.h:312
osl::Square::onBoardMin
static const Square onBoardMin()
Definition: basic_type.h:636
osl::Move::to
const Square to() const
Definition: basic_type.h:1132
osl::operator>>
std::istream & operator>>(std::istream &is, Ptype &ptype)
Definition: basic_type.cc:35
osl::Move::Move
Move(int value)
Definition: basic_type.h:1057
osl::Square::isLR
bool isLR(Square sq) const
2つのSquare(onBoardであることが前提)のyが等しい
Definition: basic_type.h:701
osl::Piece::isEdgeNum
static bool isEdgeNum(int num)
Definition: basic_type.h:922
osl::Move::isPawnDrop
bool isPawnDrop() const
Definition: basic_type.h:1151
osl::Piece::Piece
Piece()
Definition: basic_type.h:809
osl::Piece::pieceIsBlack
bool pieceIsBlack() const
pieceであることが分かっている時に,更にBlackかどうかをチェックする.
Definition: basic_type.h:959
osl::LONG_UR
@ LONG_UR
Definition: basic_type.h:327
osl::isMajorBasic
bool isMajorBasic(Ptype ptype)
Definition: basic_type.h:181
osl::U
@ U
Definition: basic_type.h:314
osl::operator*
int operator*(Player, int)
osl::Move::intValue
int intValue() const
Definition: basic_type.h:1065
osl::Move::isPromotion
bool isPromotion() const
Definition: basic_type.h:1147
osl::Offset::operator+=
Offset & operator+=(Offset other)
Definition: basic_type.h:473
osl::Piece::isOnBoard
bool isOnBoard() const
Definition: basic_type.h:985
osl::Square::squareForBlack
const Square squareForBlack(Player player) const
Definition: basic_type.h:598
osl::dirToMask
constexpr int dirToMask(Direction dir)
Definition: basic_type.h:393
osl::promoteWithMask
PtypeO promoteWithMask(PtypeO ptypeO, int promoteMask)
pieceを引数次第でpromoteさせる
Definition: basic_type.h:232
osl::playerToMask
constexpr int playerToMask(Player player)
Definition: basic_type.h:28
osl::Square::reverseX
static int reverseX(int x)
Definition: basic_type.h:651
osl::Piece::BitOffsetMovePromote
static const int BitOffsetMovePromote
Definition: basic_type.h:801
osl::Move::player
Player player() const
Definition: basic_type.h:1195
osl::__attribute__
const PtypeO PTYPEO_EDGE __attribute__((unused))
osl::unpromote
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す
Definition: basic_type.h:157
osl
Definition: additionalEffect.h:6
osl::Piece::isPlayerBasicPtype
bool isPlayerBasicPtype(Player pl, Ptype ptype) const
あるpieceがPlayer pの持ち物でBASIC typeがptypeであるかどうかをチェックする. TはEMPTY, EDGEではない.
Definition: basic_type.h:945
osl::Move::makeDirect
static const Move makeDirect(int value)
Definition: basic_type.h:1093
osl::Move::BitOffsetPromote
static const int BitOffsetPromote
Definition: basic_type.h:1054
osl::Square::operator+
const Square operator+(Offset offset) const
Definition: basic_type.h:714
osl::KNIGHT
@ KNIGHT
Definition: basic_type.h:97
osl::MOVE16_NONE
@ MOVE16_NONE
Definition: basic_type.h:1024
osl::Piece::isEdge
bool isEdge() const
Definition: basic_type.h:919
osl::inverseUnsafe
constexpr Direction inverseUnsafe(Direction d)
Definition: basic_type.h:354