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