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;
60 static const Player opponent=BLACK;
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);
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);
#define move_assert(x)
move 関係でつかまえ所のないエラーがでるときに定義する
const Move promote() const
unpromote moveからpromote moveを作る
PtypeO ptypeO() const
移動後のPtype, i.e., 成る手だった場合成った後
static const Move PASS(Player P)
static const Move makeDirect(int value)
Move newAddTo(Offset o) const
moveのtoをoffsetだけ変える. 元のtoが0以外でも使える
static const Move INVALID()
bool ignoreUnpromote() const
合法手ではあるが,打歩詰め絡み以外では有利にはならない手.
bool isInvalid() const
state に apply 可能でない場合にtrue
Move newAddPtype(Ptype newPtype) const
作ってあったPTYPE_EMPTYのひな形のPTYPEをsetする
PtypeO oldPtypeO() const
移動前のPtypeO, i.e., 成る手だった場合成る前
static const int BitOffsetPromote
Move newAddFrom(Square new_from) const
static const Move DeclareWin()
const Move unpromote() const
promote moveからunpromote moveを作る
Ptype capturePtype() const
PtypeO capturePtypeO() const
PtypeO capturePtypeOSafe() const
Move(Square from, Square to, Ptype ptype, Ptype capture_ptype, bool is_promote, Player player)
移動
static bool ignoreUnpromote(Ptype ptype, Square from, Square to)
const Move newCapture(Piece capture) const
bool isValidOrPass() const
static const Move fromMove16(Move16, const SimpleState &)
Move newAddTo(Square sq) const
つくってあったmoveの雛形のsquareをsetする. mのtoは0
Move(Square to, Ptype ptype, Player player)
drop
bool hasIgnoredUnpromote() const
bool isNormal() const
INVALID でも PASS でもない.
void init(Square from, Square to, Ptype ptype, Ptype capture_ptype, bool is_promote, Player player)
bool isCaptureOrPromotion() const
int promoteMask() const
pieceに使うためのmaskなので
const Move rotate180() const
Move newFrom(Square new_from) const
bool ignoreUnpromote() const
Ptype oldPtype() const
移動前のPtype, i.e., 成る手だった場合成る前
bool hasIgnoredUnpromote() const
MoveをunpromoteするとcutUnpromoteなMoveになる
static const unsigned int MaxUniqMoves
一局面辺りの合法手の最大値 重複して手を生成することがある場合は,600では不足かもしれない
unsigned int fromTo() const
fromとtoをまとめて同一性の判定など
unsigned int hash() const
駒を取らない手を [0, 16305] にmap
const Move newCapture(Ptype capture) const
const Square from() const
const Move newAddCapture(Piece capture) const
no capture moveからcapture moveを作る
static int makeOffset(int dx, int dy)
const Offset operator-() const
unsigned int index() const
const Offset operator+(Offset other) const
const Offset operator-(const Offset other) const
Offset & operator-=(Offset other)
const Offset blackOffset() const
Player P からみた offset を黒番のものに変更する
Offset & operator+=(Offset other)
int dx() const
Offsetから一般に dxは求まらないので, ここでの入力は12近傍のみとする
int dy() const
Offsetから一般に dyは求まらないので, ここでの入力は12近傍のみとする
const Offset operator*(const int mult) const
static const Offset makeDirect(int value)
static const int BOARD_HEIGHT
static const Offset ZERO()
static const int BitOffsetPtype
void setSquare(Square square)
static const Piece makeDirect(int value)
bool isPromoted() const
promoteした駒かどうかをチェックする
const Square square() const
bool pieceIsBlack() const
pieceであることが分かっている時に,更にBlackかどうかをチェックする.
const Piece unpromote() const
static bool isPieceNum(int num)
static bool isEmptyNum(int num)
bool isPlayerPtype(Player pl, Ptype ptype) const
あるpieceがPlayer pの持ち物でPtype ptypeであるかどうかをチェックする. TはEMPTY, EDGEではない.
bool canMoveOn() const
Player Pの駒が,thisの上に移動できるか? PIECE_EMPTY 0x00008000 BLACK_PIECE 0x000XxxYY X>=2, YY>0 PIECE_EDGE 0xfff1...
static const int BitOffsetPromote
const Piece promote() const
bool canMoveOn(Player pl) const
const Piece promoteWithMask(int promote_mask) const
bool isOnBoardByOwner() const
piece がプレイヤーPの持ち物でかつボード上にある駒の場合は true.
static bool isEdgeNum(int num)
bool isPromotedNotKingGold() const
const Piece checkPromote(bool promotep) const
static const Piece EMPTY()
Piece(Player owner, Ptype ptype, int num, Square square)
bool isOnBoardNotPromoted() const
promoteしていないOnBoardの駒であることのチェック Lance位しか使い道がない?
static const Piece makeKing(Player owner, Square square)
玉を作る
const Piece captured() const
取られたpieceを作成.
bool isOnBoardByOwner(Player owner) const
isOnBoardByOwner の通常関数のバージョン.
bool isPlayerBasicPtype(Player pl, Ptype ptype) const
あるpieceがPlayer pの持ち物でBASIC typeがptypeであるかどうかをチェックする. TはEMPTY, EDGEではない.
Piece & operator+=(Offset offset)
static const Piece EDGE()
static const int BitOffsetMovePromote
const Offset operator-(Square other) const
static const Square onBoardMax()
std::enable_if< Y!=7, bool >::type yGe()
unsigned int index() const
bool isPieceStand() const
const Square rotate180EdgeOK() const
int y() const
将棋としてのY座標を返す.
const Square squareForBlack() const
後手の場合は盤面を引っくり返す.
bool isLR(Square sq) const
2つのSquare(onBoardであることが前提)のyが等しい
int indexForOffset32() const
bool isNeighboring8(Square to) const
bool isOnBoardSlow() const
const Square neighbor() const
bool isUD(Square sq) const
2つのSquare(onBoardであることが前提)のxが等しい
unsigned int uintValue() const
const Square rotate180() const
static const Square onBoardMin()
const Square squareForBlack(Player player) const
const Square back() const
static int reverseX(int x)
static int reverseY(int y)
static const Square STAND()
bool canPromote(Player player) const
bool isOnBoard() const
盤面上を表すかどうかの判定. 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する.
std::enable_if< Y!=2, bool >::type yLe()
static const Square makeNoCheck(int x, int y)
assertなしに作る
std::enable_if< Y==7, bool >::type yGe()
bool isEdge() const
onBoardから8近傍のオフセットを足した点がedgeかどうかの判定 そこそこ速くなった.
std::enable_if< Y==2, bool >::type yLe()
bool isOnBoardRegion() const
squareがONBOARD_MINとONBOARD_MAXの間にある
Square & operator+=(Offset offset)
int x() const
将棋としてのX座標を返す.
Square & operator-=(Offset offset)
const Square rotate180Safe() const
static unsigned int indexMax()
const Square operator+(Offset offset) const
bool isULRD(Square sq) const
2つのSquare(onBoardであることが前提)が, xが等しいかyが等しい
bool isU(Square sq) const
sqがPlayer Pにとって上
const Square operator-(Offset offset) const
static const Square makeDirect(int value)
const Square flipHorizontal() const
static const Square nth(unsigned int i)
static bool canPromoteY(int y)
constexpr bool isShort8(Direction d)
const PtypeO PTYPEO_EMPTY
Ptype getPtype(PtypeO ptypeO)
bool isValidPtypeO(int ptypeO)
constexpr int dirToMask(Direction dir)
bool isMajorBasic(Ptype ptype)
bool operator>(Square l, Square r)
int operator+(Player, int)
constexpr Player indexToPlayer(int n)
constexpr Ptype unpromoteSafe(Ptype ptype)
bool canPromote(Ptype ptype)
ptypeがpromote可能な型かどうかのチェック promote済みの場合はfalseを返す
constexpr Direction longToShort(Direction d)
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す
constexpr int playerToIndex(Player player)
Player getOwner(PtypeO ptypeO)
constexpr Direction primDirUnsafe(Direction d)
8方向について,primitiveな4方向を求める dとしてknight, INVALIDなども来る
bool isValid(Player player)
cast等で作られたplayerが正しいかどうかを返す
int operator*(Player, int)
bool operator<(Offset l, Offset r)
constexpr Direction inverseUnsafe(Direction d)
@ DIRECTION_INVALID_VALUE
unsigned int ptypeOIndex(PtypeO ptypeo)
bool isPromoted(Ptype ptype)
ptypeがpromote後の型かどうかのチェック
constexpr bool isShort(Direction d)
bool operator!=(Offset l, Offset r)
constexpr int sign(Player player)
constexpr bool isPiece(Ptype ptype)
ptypeが空白やEDGEでないかのチェック
int operator/(Player, int)
const PtypeO PTYPEO_EDGE __attribute__((unused))
bool isMajor(Ptype ptype)
constexpr int playerToMask(Player player)
Offset newOffset(int dx, int dy)
@obsolete
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
constexpr Direction primDir(Direction d)
8方向について,primitiveな4方向を求める
PtypeO promoteWithMask(PtypeO ptypeO, int promoteMask)
pieceを引数次第でpromoteさせる
bool isBasic(Ptype ptype)
ptypeが基本型(promoteしていない)かのチェック
constexpr bool isLong(Direction d)
bool isMajorNonPieceOK(Ptype ptype)
int operator-(Player, int)
std::istream & operator>>(std::istream &is, Ptype &ptype)
constexpr Direction shortToLong(Direction d)
引数に longDirを与えてはいけない
constexpr Player alt(Player player)
PtypeO newPtypeO(Player player, Ptype ptype)
Ptype promote(Ptype ptype)
promote可能なptypeに対して,promote後の型を返す promote不可のptypeを与えてはいけない.
PtypeO altIfPiece(PtypeO ptypeO)
Pieceの時にはowner を反転する
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に,ownerを反転する.
std::ostream & operator<<(std::ostream &os, Player player)
constexpr Direction inverse(Direction d)
bool operator==(Square l, Square r)
unsigned long operator()(osl::Move m) const