Go to the documentation of this file. 1 #ifndef OSL_BASIC_TYPE_H
2 #define OSL_BASIC_TYPE_H
14 return static_cast<Player>(-1-
static_cast<int>(player));
17 return -
static_cast<int>(player);
21 return static_cast<Player>(-n);
26 return 1+(
static_cast<int>(player)<<1);
29 return static_cast<int>(player);
48 struct PlayerTraits<
BLACK>{
49 static const int offsetMul=1;
50 static const int index=0;
51 static const int mask=0;
56 struct PlayerTraits<
WHITE>{
57 static const int offsetMul=-1;
58 static const int index=1;
59 static const int mask= -1;
131 return static_cast<int>(ptype)>
PROOK;
140 return static_cast<int>(ptype)<
KING;
150 return static_cast<int>(ptype)>
GOLD;
160 Ptype ret=
static_cast<Ptype>(
static_cast<int>(ptype)|8);
176 Ptype ret=
static_cast<Ptype>(
static_cast<int>(ptype)-8);
192 return (
static_cast<int>(ptype)|8)>=14;
204 #define NEW_PTYPEO(player,ptype) static_cast<PtypeO>(static_cast<int>(ptype)-(16&static_cast<int>(player)))
213 return static_cast<PtypeO>(
static_cast<int>(ptype)-(16&
static_cast<int>(player)));
219 return static_cast<Ptype>(
static_cast<int>(ptypeO)& 15);
226 PtypeO ret=
static_cast<PtypeO>(
static_cast<int>(ptypeO)-8);
234 assert(promoteMask==0 || promoteMask==0x800000);
235 PtypeO ret=
static_cast<PtypeO>(
static_cast<int>(ptypeO)-(promoteMask>>20));
242 return static_cast<PtypeO>(
static_cast<int>(ptypeO)|8);
259 return static_cast<Player>(
static_cast<int>(ptypeO)>>31);
267 return static_cast<PtypeO>((
static_cast<int>(ptypeO)|8)^(~15));
274 return static_cast<PtypeO>(
static_cast<int>(ptypeO)^(~15));
283 int v=
static_cast<int>(ptypeO);
284 return static_cast<PtypeO>(v^((1-(v&15))&~15));
394 return (1<<
static_cast<int>(dir));
458 template <Player, Direction>
485 return result += other;
490 return result -= other;
493 return static_cast<Offset>(
static_cast<int>(
offset)*mult);
526 std::ostream&
operator<<(std::ostream&, Offset);
584 return (0xffffff88&(
square-0x12)&
585 ((
unsigned int)((
square&0x77)^0x12)+0xffffff77))==0;
599 return (player ==
BLACK)
615 return squareForBlack<WHITE>();
626 return squareForBlack<WHITE>();
656 return P ==
BLACK ? y <= 3 : y >= 7;
676 return (((v+0xefull)^v)&0x110ull)!=0x110ull;
716 return result+=offset;
720 return result-=offset;
730 typename std::enable_if<Y!=2,bool>::type
yLe() {
734 typename std::enable_if<Y==2,bool>::type
yLe() {
738 typename std::enable_if<Y!=7,bool>::type
yGe() {
742 typename std::enable_if<Y==7,bool>::type
yGe() {
745 template <Player P, Direction D>
749 template <Player P, Direction D>
751 return neighbor<alt(P),D>();
774 std::ostream&
operator<<(std::ostream&, Square);
806 +((num)<<8)+
square.uintValue())
829 return ((
piece&0xff00)>>8);
859 return static_cast<int>(
static_cast<unsigned int>(
piece)&0x800000ff)>0;
861 return static_cast<int>((-
piece)&0x800000ff)>0;
887 assert(promote_mask==0 || promote_mask==(1<<23));
905 int mask=
piece&((1<<19)|0xff);
914 return (
piece&0x8000)!=0;
917 return (num&0x80)!=0;
920 return (
piece&0x4000)!=0;
924 return (num&0x40)!=0;
927 return (num&0xc0)==0;
954 return (
piece&0xc000)==0;
961 return static_cast<int>(
piece)>=0;
1004 std::ostream&
operator<<(std::ostream& os,
const Piece piece);
1011 # define move_assert(x) assert(x)
1013 # define move_assert(x)
1067 unsigned int hash()
const;
1078 + (
static_cast<unsigned int>(capture_ptype)<<16)
1080 + (
static_cast<unsigned int>(
ptype)<<24)
1081 + (
static_cast<int>(
player)<<28));
1090 return move & 0x00ff;
1210 int result =
static_cast<int>(
intValue());
1211 result &= ~(0xff00);
1218 assert(
from().uintValue()==0);
1219 int result =
static_cast<int>(
intValue());
1277 + (
static_cast<unsigned int>(newPtype)<<24));
1288 default:
return false;
1298 if(
isDrop())
return false;
1302 if(
player()==
BLACK)
return ignoreUnpromote<BLACK>();
1303 else return ignoreUnpromote<WHITE>();
1314 return (P==
BLACK ?
to().y()!=1 :
to().y()!=9);
1316 return (P==
BLACK ?
to().y()==2 :
to().y()==8);
1319 default:
return false;
1323 if(
player()==
BLACK)
return hasIgnoredUnpromote<BLACK>();
1324 else return hasIgnoredUnpromote<WHITE>();
1330 #ifdef PRESERVE_MOVE_ORDER
1332 l=(l&0xffff0000)+((l>>8)&0xff)+((l<<8)&0xff00);
1334 r=(r&0xffff0000)+((r>>8)&0xff)+((r<<8)&0xff00);
1346 return ! (lhs == rhs);
1349 std::ostream&
operator<<(std::ostream& os, Move move);
bool isMajor(Ptype ptype)
constexpr Direction primDirUnsafe(Direction d)
8方向について,primitiveな4方向を求める dとしてknight, INVALIDなども来る
PtypeO capturePtypeOSafe() const
bool isInvalid() const
state に apply 可能でない場合にtrue
static int reverseY(int y)
static const Offset ZERO()
bool hasIgnoredUnpromote() const
MoveをunpromoteするとcutUnpromoteなMoveになる
bool isOnBoard() const
盤面上を表すかどうかの判定. 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する.
bool canMoveOn() const
Player Pの駒が,thisの上に移動できるか? PIECE_EMPTY 0x00008000 BLACK_PIECE 0x000XxxYY X>=2, YY>0 PIECE_EDGE 0xfff1...
int operator+(Player, int)
constexpr Direction inverse(Direction d)
static const Offset makeDirect(int value)
constexpr Player alt(Player player)
const Piece promote() const
static const Square nth(unsigned int i)
bool canMoveOn(Player pl) const
const Offset operator-(Square other) const
int dx() const
Offsetから一般に dxは求まらないので, ここでの入力は12近傍のみとする
Ptype promote(Ptype ptype)
promote可能なptypeに対して,promote後の型を返す promote不可のptypeを与えてはいけない.
bool canPromote(Player player) const
bool isMajorNonPieceOK(Ptype ptype)
bool isValidPtypeO(int ptypeO)
const Move rotate180() const
const Move promote() const
unpromote moveからpromote moveを作る
Move(Square to, Ptype ptype, Player player)
drop
static const Square makeNoCheck(int x, int y)
assertなしに作る
static const unsigned int MaxUniqMoves
一局面辺りの合法手の最大値 重複して手を生成することがある場合は,600では不足かもしれない
Ptype getPtype(PtypeO ptypeO)
std::enable_if< Y==2, bool >::type yLe()
bool isCaptureOrPromotion() const
Move newAddPtype(Ptype newPtype) const
作ってあったPTYPE_EMPTYのひな形のPTYPEをsetする
constexpr bool isShort(Direction d)
PtypeO altIfPiece(PtypeO ptypeO)
Pieceの時にはowner を反転する
static const Piece makeKing(Player owner, Square square)
玉を作る
static const int BitOffsetPtype
static const Piece EMPTY()
static const int BOARD_HEIGHT
bool isOnBoardByOwner(Player owner) const
isOnBoardByOwner の通常関数のバージョン.
bool isOnBoardRegion() const
squareがONBOARD_MINとONBOARD_MAXの間にある
static const int BitOffsetPromote
static const Move INVALID()
PtypeO newPtypeO(Player player, Ptype ptype)
Player getOwner(PtypeO ptypeO)
void setSquare(Square square)
bool isPromotedNotKingGold() const
static bool ignoreUnpromote(Ptype ptype, Square from, Square to)
Square & operator+=(Offset offset)
const Piece checkPromote(bool promotep) const
bool hasIgnoredUnpromote() const
int promoteMask() const
pieceに使うためのmaskなので
const Offset operator-() const
int operator/(Player, int)
void init(Square from, Square to, Ptype ptype, Ptype capture_ptype, bool is_promote, Player player)
std::ostream & operator<<(std::ostream &os, Player player)
static const Square onBoardMax()
static const Move fromMove16(Move16, const SimpleState &)
Ptype oldPtype() const
移動前のPtype, i.e., 成る手だった場合成る前
bool isUD(Square sq) const
2つのSquare(onBoardであることが前提)のxが等しい
unsigned int uintValue() const
constexpr bool isShort8(Direction d)
static bool canPromoteY(int y)
bool isPieceStand() const
static const Piece makeDirect(int value)
Move newAddFrom(Square new_from) const
PtypeO oldPtypeO() const
移動前のPtypeO, i.e., 成る手だった場合成る前
unsigned int index() const
@ DIRECTION_INVALID_VALUE
const Move newAddCapture(Piece capture) const
no capture moveからcapture moveを作る
bool isOnBoardSlow() const
const Move unpromote() const
promote moveからunpromote moveを作る
bool ignoreUnpromote() const
Ptype capturePtype() const
Offset & operator-=(Offset other)
const Offset blackOffset() const
Player P からみた offset を黒番のものに変更する
static const Move DeclareWin()
static bool isEmptyNum(int num)
bool isU(Square sq) const
sqがPlayer Pにとって上
const Offset operator*(const int mult) const
PtypeO ptypeO() const
移動後のPtype, i.e., 成る手だった場合成った後
bool isULRD(Square sq) const
2つのSquare(onBoardであることが前提)が, xが等しいかyが等しい
unsigned int index() const
bool isValidOrPass() const
constexpr Player indexToPlayer(int n)
bool isBasic(Ptype ptype)
ptypeが基本型(promoteしていない)かのチェック
constexpr Direction shortToLong(Direction d)
引数に longDirを与えてはいけない
bool isOnBoardByOwner() const
piece がプレイヤーPの持ち物でかつボード上にある駒の場合は true.
const Move newCapture(Ptype capture) const
bool isPromoted() const
promoteした駒かどうかをチェックする
const Square squareForBlack() const
後手の場合は盤面を引っくり返す.
const Square flipHorizontal() const
static unsigned int indexMax()
Move newFrom(Square new_from) const
bool isNormal() const
INVALID でも PASS でもない.
Square & operator-=(Offset offset)
const Piece promoteWithMask(int promote_mask) const
const Square rotate180Safe() const
const Square from() const
std::enable_if< Y==7, bool >::type yGe()
bool isValid(Player player)
cast等で作られたplayerが正しいかどうかを返す
int x() const
将棋としてのX座標を返す.
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に,ownerを反転する.
std::enable_if< Y!=7, bool >::type yGe()
const Square back() const
const Offset operator-(const Offset other) const
bool isEdge() const
onBoardから8近傍のオフセットを足した点がedgeかどうかの判定 そこそこ速くなった.
static int makeOffset(int dx, int dy)
constexpr int playerToIndex(Player player)
Move newAddTo(Offset o) const
moveのtoをoffsetだけ変える. 元のtoが0以外でも使える
constexpr bool isPiece(Ptype ptype)
ptypeが空白やEDGEでないかのチェック
const Square neighbor() const
constexpr Ptype unpromoteSafe(Ptype ptype)
unsigned long operator()(osl::Move m) const
int y() const
将棋としてのY座標を返す.
Move newAddTo(Square sq) const
つくってあったmoveの雛形のsquareをsetする. mのtoは0
bool operator<(Offset l, Offset r)
constexpr Direction primDir(Direction d)
8方向について,primitiveな4方向を求める
constexpr int sign(Player player)
constexpr bool isLong(Direction d)
static const Move PASS(Player P)
bool isPromoted(Ptype ptype)
ptypeがpromote後の型かどうかのチェック
bool operator==(Square l, Square r)
#define move_assert(x)
move 関係でつかまえ所のないエラーがでるときに定義する
bool isNeighboring8(Square to) const
const Square square() const
constexpr Direction longToShort(Direction d)
bool operator>(Square l, Square r)
static const Piece EDGE()
PtypeO capturePtypeO() const
Offset newOffset(int dx, int dy)
@obsolete
unsigned int ptypeOIndex(PtypeO ptypeo)
bool canPromote(Ptype ptype)
ptypeがpromote可能な型かどうかのチェック promote済みの場合はfalseを返す
Piece & operator+=(Offset offset)
bool isPlayerPtype(Player pl, Ptype ptype) const
あるpieceがPlayer pの持ち物でPtype ptypeであるかどうかをチェックする. TはEMPTY, EDGEではない.
const PtypeO PTYPEO_EMPTY
bool ignoreUnpromote() const
合法手ではあるが,打歩詰め絡み以外では有利にはならない手.
const Square operator-(Offset offset) const
bool isOnBoardNotPromoted() const
promoteしていないOnBoardの駒であることのチェック Lance位しか使い道がない?
const Square rotate180() const
static bool isPieceNum(int num)
int indexForOffset32() const
static const Square makeDirect(int value)
Piece(Player owner, Ptype ptype, int num, Square square)
const Square rotate180EdgeOK() const
const Offset operator+(Offset other) const
std::enable_if< Y!=2, bool >::type yLe()
const Piece captured() const
取られたpieceを作成.
int dy() const
Offsetから一般に dyは求まらないので, ここでの入力は12近傍のみとする
const Move newCapture(Piece capture) const
int operator-(Player, int)
unsigned int hash() const
駒を取らない手を [0, 16305] にmap
bool operator!=(Offset l, Offset r)
Move(Square from, Square to, Ptype ptype, Ptype capture_ptype, bool is_promote, Player player)
移動
const Piece unpromote() const
unsigned int fromTo() const
fromとtoをまとめて同一性の判定など
static const Square STAND()
static const Square onBoardMin()
std::istream & operator>>(std::istream &is, Ptype &ptype)
bool isLR(Square sq) const
2つのSquare(onBoardであることが前提)のyが等しい
static bool isEdgeNum(int num)
bool pieceIsBlack() const
pieceであることが分かっている時に,更にBlackかどうかをチェックする.
bool isMajorBasic(Ptype ptype)
int operator*(Player, int)
Offset & operator+=(Offset other)
const Square squareForBlack(Player player) const
constexpr int dirToMask(Direction dir)
PtypeO promoteWithMask(PtypeO ptypeO, int promoteMask)
pieceを引数次第でpromoteさせる
constexpr int playerToMask(Player player)
static int reverseX(int x)
static const int BitOffsetMovePromote
const PtypeO PTYPEO_EDGE __attribute__((unused))
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す
bool isPlayerBasicPtype(Player pl, Ptype ptype) const
あるpieceがPlayer pの持ち物でBASIC typeがptypeであるかどうかをチェックする. TはEMPTY, EDGEではない.
static const Move makeDirect(int value)
static const int BitOffsetPromote
const Square operator+(Offset offset) const
constexpr Direction inverseUnsafe(Direction d)