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