numEffectState.h
Go to the documentation of this file.
/* numEffectState.h
*/
#ifndef OSL_NUM_EFFECT_STATE_H
#define OSL_NUM_EFFECT_STATE_H
#include "osl/bits/numSimpleEffect.h"
#include "osl/mobility/kingMobility.h"
#include "osl/bits/align16New.h"
namespace osl
{
namespace checkmate
{
class King8Info;
}
class MoveVector;
class NumEffectState;
bool operator==(const NumEffectState& st1, const NumEffectState& st2);
class NumEffectState : public SimpleState
#if OSL_WORDSIZE == 32
, public misc::Align16New
#endif
{
effect::NumSimpleEffectTable effects;
CArray<PieceMask,2> pieces_onboard;
PieceMask promoted;
CArray<PieceMask,2> pin_or_open;
KingMobility king_mobility;
CArray<uint64_t,2> king8infos;
friend bool operator==(const NumEffectState& st1,const NumEffectState& st2);
typedef NumEffectState state_t;
public:
// ----------------------------------------------------------------------
// 0. 将棋以外の操作
// ----------------------------------------------------------------------
explicit NumEffectState(const SimpleState& st=SimpleState(HIRATE));
~NumEffectState();
void copyFrom(const NumEffectState& src);
void copyFrom(const SimpleState& src);
bool isConsistent(bool showError=true) const;
bool isConsistent(const NumEffectState& prev, Move moved, bool show_error=true) const;
void showEffect(std::ostream& os) const;
// ----------------------------------------------------------------------
// 1. 盤面全体の情報
// ----------------------------------------------------------------------
const PieceMask& piecesOnBoard(Player p) const { return pieces_onboard[p]; }
const PieceMask promotedPieces() const { return promoted; }
const PieceMask pin(Player king) const
{
return pin_or_open[king]&piecesOnBoard(king);
}
const PieceMask checkShadow(Player attack) const
{
return pin_or_open[alt(attack)]&piecesOnBoard(attack);
}
PieceMask pinOrOpen(Player king) const
{
return pin_or_open[king];
}
uint64_t Iking8Info(Player king) const
{
return king8infos[king];
}
const checkmate::King8Info
#ifdef __GNUC__
__attribute__ ((pure))
#endif
king8Info(Player king) const;
bool inCheck(Player P) const
{
const Square king = kingSquare(P);
#ifdef ALLOW_KING_ABSENCE
if (king.isPieceStand())
return false;
#endif
return hasEffectAt(alt(P), king);
}
bool inCheck() const { return inCheck(turn()); }
bool inUnblockableCheck(Player target) const {
const Square king_position = kingSquare(target);
Piece attacker_piece;
if (hasEffectAt(alt(target), king_position, attacker_piece)) {
if (attacker_piece == Piece::EMPTY())
return true; // multiple pieces
// sigle check
const Square from = attacker_piece.square();
const EffectContent effect
= Ptype_Table.getEffect(attacker_piece.ptypeO(),
from, king_position);
return effect.hasUnblockableEffect();
}
// no check
return false;
}
const EffectedNumTable& longEffectNumTable() const
{
return effects.effectedNumTable;
}
const PieceMask effectedMask(Player pl) const
{
return effects.effected_mask[pl];
}
const PieceMask effectedChanged(Player pl) const
{
return effects.effected_changed_mask[pl];
}
bool hasChangedEffects() const {
return ! effects.changedEffects(BLACK).isInvalid();
}
const BoardMask changedEffects(Player pl) const{
assert(hasChangedEffects());
return effects.changedEffects(pl);
}
const BoardMask changedEffects() const{
BoardMask ret = changedEffects(BLACK);
return ret |= changedEffects(WHITE);
}
const NumBitmapEffect changedPieces() const{
return effects.changedPieces();
}
template <Ptype PTYPE> bool longEffectChanged() const
{
return changedPieces().template hasLong<PTYPE>();
}
template <Ptype PTYPE> bool anyEffectChanged() const
{
return changedPieces().template hasAny<PTYPE>();
}
const Piece findThreatenedPiece(Player P) const;
// ----------------------------------------------------------------------
// 2. 駒に関する情報
// ----------------------------------------------------------------------
bool isOnBoardNum(int num) const
{
return piecesOnBoard(BLACK).test(num) || piecesOnBoard(WHITE).test(num);
}
Square mobilityOf(Direction d,int num) const
{
return effects.mobilityTable.get(d,num);
}
Square mobilityOf(Direction d, Piece p) const
{
return mobilityOf(d, p.number());
}
Square kingMobilityAbs(Player p, Direction d) const
{
return Square::makeDirect(king_mobility[p][d]);
}
Square kingMobilityOfPlayer(Player p, Direction d) const
{
if (p == BLACK)
d = inverse(d);
return kingMobilityAbs(p, d);
}
template<Player P>
Direction pinnedDir(Piece p) const
{
assert(p.owner() == P);
assert(pinOrOpen(P).test(p.number()));
Square king=kingSquare<P>();
return Board_Table.getShort8<P>(p.square(),king);
}
Direction pinnedDir(Piece p) const
{
if (p.owner() == BLACK)
return pinnedDir<BLACK>(p);
else
return pinnedDir<WHITE>(p);
}
template<Player P>
bool pinnedCanMoveTo(Piece p,Square to) const
{
assert(p.owner() == P);
Direction d=pinnedDir<P>(p);
Square from=p.square();
return primDir(d)==primDirUnsafe(Board_Table.getShort8Unsafe<P>(from,to));
}
bool pinnedCanMoveTo(Piece p,Square to) const
{
if (p.owner() == BLACK)
return pinnedCanMoveTo<BLACK>(p, to);
else
return pinnedCanMoveTo<WHITE>(p, to);
}
template<Player P>
Piece pinAttacker(Piece pinned) const
{
assert(pinned.owner() == P);
assert(pinOrOpen(P).test(pinned.number()));
Direction d=pinnedDir<P>(pinned);
int attacker_num=longEffectNumTable()[pinned.number()][(P==BLACK ? d : inverseUnsafe(d))];
return pieceOf(attacker_num);
}
Piece pinAttacker(Piece pinned) const
{
if (pinned.owner() == BLACK)
return pinAttacker<BLACK>(pinned);
else
return pinAttacker<WHITE>(pinned);
}
// ----------------------------------------------------------------------
// 3. あるSquareへの利き
// ----------------------------------------------------------------------
const NumBitmapEffect effectSetAt(Square sq) const
{
return effects.effectSetAt(sq);
}
int countEffect(Player player,Square target) const
{
assert(target.isOnBoard());
return effectSetAt(target).countEffect(player);
}
int
#ifdef __GNUC__
__attribute__ ((pure))
#endif
countEffect(Player player,Square target, PieceMask pins) const
{
assert(target.isOnBoard());
const NumBitmapEffect effect = effectSetAt(target);
const int all = effect.countEffect(player);
pins &= effect;
return all - pins.countBit();
}
// ----------------------------------------------------------------------
// 3.1 集合を返す
// ----------------------------------------------------------------------
template <Ptype PTYPE>
const mask_t allEffectAt(Player P, Square target) const
{
return effectSetAt(target).template selectBit<PTYPE>() & piecesOnBoard(P).template getMask<PTYPE>();
}
const mask_t allEffectAt(Player P, Ptype ptype, Square target) const;
template <Ptype PTYPE> const mask_t longEffectAt(Square target) const
{
return effectSetAt(target).selectLong<PTYPE>() >> 8;
}
template <Ptype PTYPE> const mask_t longEffectAt(Square target, Player owner) const
{
return longEffectAt<PTYPE>(target) & piecesOnBoard(owner).getMask(1);
}
const mask_t longEffectAt(Square target) const
{
return effectSetAt(target).selectLong() >> 8;
}
const mask_t longEffectAt(Square target, Player owner) const
{
return longEffectAt(target) & piecesOnBoard(owner).getMask(1);
}
// ----------------------------------------------------------------------
// 3.2 bool を返す
// ----------------------------------------------------------------------
template<Player P>
bool hasEffectAt(Square target) const {
assert(target.isOnBoard());
mask_t mask=effectSetAt(target).getMask(1);
mask&=NumBitmapEffect::playerEffectMask<P>();
return !mask.none();
}
bool hasEffectAt(Player player,Square target) const {
assert(target.isOnBoard());
mask_t mask=effectSetAt(target).getMask(1);
mask&=NumBitmapEffect::playerEffectMask(player);
return !mask.none();
}
template <Ptype PTYPE>
bool hasLongEffectAt(Player P, Square to) const {
static_assert((PTYPE == LANCE || PTYPE == BISHOP || PTYPE == ROOK), "ptype");
return longEffectAt<PTYPE>(to, P).any();
}
template <Ptype PTYPE>
bool hasEffectByPtype(Player attack, Square target) const
{
return allEffectAt<PTYPE>(attack, target).any();
}
template <Ptype PTYPE>
bool hasEffectByPtypeStrict(Player attack, Square target) const
{
mask_t mask=allEffectAt<PTYPE>(attack, target);
if (isPromoted(PTYPE))
mask &= promoted.getMask<PTYPE>();
else
mask &= ~(promoted.getMask<PTYPE>());
return mask.any();
}
template<Direction Dir,Player P>
bool hasEffectInDirection(Square to) const {
static_assert((DirectionTraits<Dir>::isLong), "Dir");
const PieceMask& pieces_onboard=piecesOnBoard(P);
mask_t mask1=pieces_onboard.getMask(1);
mask1 &= ((PtypeDirectionTraits<LANCE,Dir>::canMove
? mask_t::makeDirect(PtypeFuns<LANCE>::indexMask)
: mask_t::makeDirect(0))
| (PtypeDirectionTraits<BISHOP,Dir>::canMove
? mask_t::makeDirect(PtypeFuns<BISHOP>::indexMask)
: mask_t::makeDirect(0))
| (PtypeDirectionTraits<ROOK,Dir>::canMove
? mask_t::makeDirect(PtypeFuns<ROOK>::indexMask)
: mask_t::makeDirect(0)));
mask1 <<= 8;
// 短い利きを排除
mask1&=effectSetAt(to).getMask(1)& NumBitmapEffect::longEffectMask();
while (mask1.any())
{
int num=mask1.takeOneBit()+NumBitmapEffect::longToNumOffset;
Square from = pieceOf(num).square();
Direction dir=Board_Table.getLongDirection<BLACK>(Offset32(to,from));
if (dir==DirectionPlayerTraits<Dir,P>::directionByBlack)
return true;
}
return false;
}
bool hasEffectNotBy(Player player,Piece piece,Square target) const {
assert(piece.owner()==player);
PieceMask pieces_onboard=piecesOnBoard(player);
int num=piece.number();
pieces_onboard.reset(num);
return (pieces_onboard&effectSetAt(target)).any();
}
bool hasEffectByNotPinnedAndKing(Player pl,Square target) const{
assert(target.isOnBoard());
PieceMask m=piecesOnBoard(pl)& ~pinOrOpen(pl) & effectSetAt(target);
m.clearBit<KING>();
return m.any();
}
bool hasEffectByNotPinned(Player pl,Square target) const{
assert(target.isOnBoard());
PieceMask m=piecesOnBoard(pl)& ~pinOrOpen(pl) & effectSetAt(target);
return m.any();
}
bool hasMultipleEffectAt(Player player,Square target) const
{
mask_t mask=effectSetAt(target).getMask(1);
mask&=NumBitmapEffect::playerEffectMask(player);
return NumBitmapEffect::playerEffect(player).getMask(1) < mask;
}
bool hasEffectByPiece(Piece attack, Square target) const
{
assert(attack.isPiece());
assert(target.isOnBoard());
return effectSetAt(target).test(attack.number());
}
bool hasEffectIf(PtypeO ptypeo,Square attacker,
Square target) const
#ifdef __GNUC__
__attribute__ ((pure))
#endif
{
Offset32 offset32=Offset32(target,attacker);
EffectContent effect=Ptype_Table.getEffect(ptypeo,offset32);
if (! effect.hasEffect())
return false;
if (effect.hasUnblockableEffect())
return true;
assert(Board_Table.getShortOffset(offset32) == effect.offset());
return this->isEmptyBetween(attacker,target,effect.offset());
}
template<Player P>
bool
#ifdef __GNUC__
__attribute__ ((pure))
#endif
hasEffectByWithRemove(Square target,Square removed) const;
bool hasEffectByWithRemove(Player player, Square target,Square removed) const{
if (player==BLACK)
return hasEffectByWithRemove<BLACK>(target,removed);
else
return hasEffectByWithRemove<WHITE>(target,removed);
}
// ----------------------------------------------------------------------
// 3.3 pieceを探す
// ----------------------------------------------------------------------
template <Ptype PTYPE>
const Piece findAttackAt(Player attack, Square target) const
{
mask_t mask=allEffectAt<PTYPE>(attack, target);
if (mask.none())
return Piece::EMPTY();
return pieceOf(mask.takeOneBit()+PtypeFuns<PTYPE>::indexNum*32);
}
template <Ptype PTYPE>
const Piece findAttackAtStrict(Player attack, Square target) const
{
mask_t mask=allEffectAt<PTYPE>(attack, target);
if (isPromoted(PTYPE))
mask &= promoted.getMask<PTYPE>();
else
mask &= ~(promoted.getMask<PTYPE>());
if (mask.none())
return Piece::EMPTY();
return pieceOf(mask.takeOneBit()+PtypeFuns<PTYPE>::indexNum*32);
}
const Piece findLongAttackAt(Player owner, int piece, Direction d) const
{
assert(pieceOf(piece).isOnBoardByOwner(owner));
if (owner == BLACK)
d = inverse(d);
const int num = effects.effectedNumTable[piece][d];
if (num == EMPTY_NUM)
return Piece::EMPTY();
return pieceOf(num);
}
const Piece findLongAttackAt(Player owner, Piece piece, Direction d) const
{
assert(piece.isPiece());
assert(piece.owner() == owner);
return findLongAttackAt(owner, piece.number(), d);
}
const Piece findLongAttackAt(Piece piece, Direction d) const
{
assert(piece.isPiece());
return findLongAttackAt(piece.owner(), piece, d);
}
const Piece findLongAttackAt(Square square, Direction d) const
{
return findLongAttackAt(pieceOnBoard(square), d);
}
const Piece selectCheapPiece(PieceMask effect) const;
const Piece findCheapAttack(Player P, Square square) const
{
return selectCheapPiece(piecesOnBoard(P) & effectSetAt(square));
}
const Piece findCheapAttackNotBy(Player P, Square square, const PieceMask& ignore) const
{
PieceMask pieces = piecesOnBoard(P);
pieces &= ~ignore;
return selectCheapPiece(pieces & effectSetAt(square));
}
const Piece findAttackNotBy(Player P, Square square, const PieceMask& ignore) const
{
PieceMask pieces = piecesOnBoard(P);
pieces &= ~ignore;
pieces &= effectSetAt(square);
if (pieces.none())
return Piece::EMPTY();
return pieceOf(pieces.takeOneBit());
}
template<Player P>
bool findCheckPiece(Piece& attack_piece) const
{
return hasEffectAt<alt(P)>(kingSquare(P),attack_piece);
}
bool hasEffectAt(Player P, Square target,Piece& attackerPiece) const
{
if (P == BLACK)
return hasEffectAt<BLACK>(target, attackerPiece);
else
return hasEffectAt<WHITE>(target, attackerPiece);
}
template<Player P>
bool hasEffectAt(Square target,Piece& attackerPiece) const {
attackerPiece=Piece::EMPTY();
const PieceMask& pieceMask=piecesOnBoard(P)&effectSetAt(target);
mask_t mask=pieceMask.getMask(0);
if (mask.none()) return false;
if (mask.hasMultipleBit())
return true;
int num=mask.bsf();
attackerPiece=pieceOf(num);
return true;
}
// ----------------------------------------------------------------------
// 4. 指手の検査・生成・適用
// ----------------------------------------------------------------------
// --- 2014/03
bool isSafeMove(Move move) const;
bool isCheck(Move move) const;
bool isPawnDropCheckmate(Move move) const;
bool isDirectCheck(Move move) const;
bool isOpenCheck(Move move) const;
// ---
template <bool show_error>
bool isAlmostValidMove(Move move) const;
bool isAlmostValidMove(Move move,bool show_error=true) const;
void generateLegal(MoveVector&) const;
void generateWithFullUnpromotions(MoveVector&) const;
void generateAllUnsafe(MoveVector&) const;
void makeMove(Move move);
void makeMovePass()
{
changeTurn();
effects.clearChangedEffects();
effects.clearEffectedChanged();
}
template <class Function>
void makeUnmakePass(Function &f)
{
changeTurn();
f(Square::STAND());
changeTurn();
}
template <class Function>
void makeUnmakeMove(Move move, Function &f)
{
if (move.player() == BLACK)
makeUnmakeMove(Player2Type<BLACK>(), move, f);
else
makeUnmakeMove(Player2Type<WHITE>(), move, f);
}
template <Player P, class Function>
void makeUnmakeMove(Player2Type<P> player, Move move, Function &f)
{
if (move.isPass())
return makeUnmakePass(f);
assert(move.isValid());
assert(isAlmostValidMove(move));
assert(P == move.player());
assert(P == turn());
Square from=move.from();
Square to=move.to();
if (from.isPieceStand())
{
assert(pieceAt(to) == Piece::EMPTY());
doUndoDropMove(player,to,move.ptype(),f);
}
else
{
assert(pieceAt(from) != Piece::EMPTY());
Piece captured=pieceAt(to);
if (captured != Piece::EMPTY())
{
doUndoCaptureMove(player,from,to,captured,move.promoteMask(),f);
}
else
{
doUndoSimpleMove(player,from,to,move.promoteMask(),f);
}
}
}
bool wasCheckEvasion(Move last_move) const;
// ----------------------------------------------------------------------
// 5. forEachXXX
// ----------------------------------------------------------------------
template<Player P,Ptype T,typename F>
void forEachOnBoard(F& func) const {
mask_t onMask=piecesOnBoard(P).template selectBit<T>() ;
while (onMask.any())
{
int num=onMask.takeOneBit()+((PtypeFuns<T>::indexNum)<<5);
Piece p = pieceOf(num);
func(p);
}
}
template<Player P,Ptype T,typename F>
void forEachOnBoardPtypeStrict(F& func) const
{
mask_t mask=piecesOnBoard(P).template selectBit<T>() ;
if (isPromoted(T))
mask &= promoted.getMask<T>();
else
mask &= ~(promoted.getMask<T>());
while (mask.any())
{
int num=mask.takeOneBit()+((PtypeFuns<T>::indexNum)<<5);
func(pieceOf(num));
}
}
private:
template<Player P,class Action>
void forEachEffect(const PieceMask& pieces, Square sq,Action & action) const
{
#if OSL_WORDSIZE == 64
mask_t mask=pieces.getMask(0);
while (mask.any())
{
const int num=mask.takeOneBit();
action.template doAction<P>(pieceOf(num),sq);
}
#elif OSL_WORDSIZE == 32
mask_t mask0=pieces.getMask(0);
while (mask0.any())
{
const int num=mask0.takeOneBit();
action.template doAction<P>(pieceOf(num),sq);
}
mask_t mask1=pieces.getMask(1);
while (mask1.any())
{
const int num=mask1.takeOneBit()+32;
action.template doAction<P>(pieceOf(num),sq);
}
#endif
}
public:
template<Player P,class Action>
void forEachEffect(Square sq,Action & action) const
{
const PieceMask pieceMask=piecesOnBoard(P)&effectSetAt(sq);
forEachEffect<P,Action>(pieceMask, sq, action);
}
template<Player P,class Action>
void forEachEffect(Square sq,Action & action,const PieceMask& pin) const
{
PieceMask pieceMask=piecesOnBoard(P)&effectSetAt(sq);
pieceMask &= ~pin;
forEachEffect<P,Action>(pieceMask, sq, action);
}
template<Player P,class Action>
void forEachEffectNotBy(Square sq,Piece piece,Action & action) const {
PieceMask pieces=piecesOnBoard(P)&effectSetAt(sq);
pieces.reset(piece.number());
forEachEffect<P,Action>(pieces, sq, action);
}
private:
template<Player P,Ptype Type,class Action,Direction Dir>
void forEachEffectOfPieceDir(Square, Action&, Int2Type<false>) const {}
template<Player P,Ptype Type,class Action,Direction Dir>
void forEachEffectOfPieceDir(Square pieceSquare,Action & action,Int2Type<true>) const {
const Offset offset=DirectionPlayerTraits<Dir,P>::offset();
action.template doAction<P>(this->pieceAt(pieceSquare),pieceSquare+offset);
}
template<Player P,Ptype Type,class Action,Direction Dir>
void forEachEffectOfPieceDir(Square pieceSquare,Action & action) const {
forEachEffectOfPieceDir<P,Type,Action,Dir>(pieceSquare,action,Int2Type<(PtypeTraits<Type>::moveMask & DirectionTraits<Dir>::mask)!=0>());
}
template<Player P,Ptype Type,class Action,Direction Dir>
void forEachEffectOfPieceLongDir(Square, Action&, Int2Type<false>) const {}
template<Player P,Ptype Type,class Action,Direction Dir>
void forEachEffectOfPieceLongDir(Square pieceSquare,Action & action,Int2Type<true>) const {
Piece piece=this->pieceAt(pieceSquare);
const Offset offset=DirectionPlayerTraits<Dir,P>::offset();
assert(offset.intValue() != 35);
Square sq=pieceSquare+offset;
for (;this->pieceAt(sq).isEmpty();sq+=offset)
action.template doAction<P>(piece,sq);
action.template doAction<P>(piece,sq);
}
template<Player P,Ptype Type,class Action,Direction Dir>
void forEachEffectOfPieceLongDir(Square pieceSquare,Action & action) const {
forEachEffectOfPieceLongDir<P,Type,Action,Dir>(pieceSquare,action,Int2Type<(PtypeTraits<Type>::moveMask & DirectionTraits<Dir>::mask)!=0>());
}
public:
template<Player P,Ptype Type,class Action>
void forEachEffectOfPiece(Square pieceSquare,Action & action) const;
template<class Action>
void forEachEffectOfPiece(Piece piece,Action & action) const;
template <class Function, bool InterestEmpty>
void forEachEffectOfPtypeO(Square, PtypeO, Function& f) const;
template <Player P, class Function, bool InterestEmpty>
void forEachEffectOfPtypeO(Square, Ptype, Function& f) const;
template <Player P>
Piece safeCaptureNotByKing(Square target, Piece king) const;
Piece safeCaptureNotByKing(Player P, Square target) const {
const Piece king = kingPiece(P);
if (P == BLACK)
return this->safeCaptureNotByKing<BLACK>(target, king);
else
return this->safeCaptureNotByKing<WHITE>(target, king);
}
template <class Action>
void forEachEffect(Player P, Square pos, Action& a) const {
if (P == BLACK)
this->template forEachEffect<BLACK>(pos,a);
else
this->template forEachEffect<WHITE>(pos,a);
}
void findEffect(Player P, Square target, PieceVector& out) const;
private:
void doSimpleMove(Square from, Square to, int promoteMask);
void doDropMove(Square to,Ptype ptype);
void doCaptureMove(Square from, Square to, Piece target,int promoteMask);
template <Player P, class Function>
void doUndoSimpleMove(Player2Type<P> player,
Square from, Square to, int promoteMask,Function& func);
template <Player P>
void prologueSimple(Player2Type<P>, Square from, Square to, int promoteMask,
Piece& oldPiece, int& num,
PtypeO& oldPtypeO, PtypeO& new_ptypeo,
CArray<PieceMask,2>& pin_or_open_backup,
KingMobility& king_mobility_backup,
PieceMask& promoted_backup,
CArray<PieceMask,2>& effected_mask_backup,
CArray<PieceMask,2>& effected_changed_mask_backup,
CArray<uint64_t,2>& king8infos_backup,
MobilityTable &mobility_backup
);
void epilogueSimple(Square from, Square to, Piece oldPiece,
int num, PtypeO oldPtypeO, PtypeO newPtypeO,
const CArray<PieceMask,2>& pin_or_open_backup,
const KingMobility& king_mobility_backup,
const PieceMask& promoted_backup,
const CArray<PieceMask,2>& effected_mask_backup,
const CArray<PieceMask,2>& effected_changed_mask_backup,
const CArray<uint64_t,2>& king8infos_backup,
const MobilityTable &mobility_backup
);
template <Player P, class Function>
void doUndoDropMove(Player2Type<P> player,
Square to, Ptype ptype, Function& func);
template <Player P>
void prologueDrop(Player2Type<P>, Square to, Ptype ptype,
Piece& oldPiece, int& num, PtypeO& ptypeO,
int& numIndex, mask_t& numMask,
CArray<PieceMask,2>& pin_or_open_backup,
KingMobility& king_mobility_backup,
CArray<PieceMask,2>& effected_mask_backup,
CArray<PieceMask,2>& effected_changed_mask_backup,
CArray<uint64_t,2>& king8infos_backup,
MobilityTable &mobility_backup);
template<Player P>
void epilogueDrop(Player2Type<P>, Square to, Ptype ptype, Piece oldPiece,
int num, PtypeO ptypeO, int numIndex, mask_t numMask,
const CArray<PieceMask,2>& pin_or_open_backup,
const KingMobility& king_mobility_backup,
const CArray<PieceMask,2>& effected_mask_backup,
const CArray<PieceMask,2>& effected_changed_mask_backup,
const CArray<uint64_t,2>& king8infos_backup,
const MobilityTable &mobility_backup);
template <Player P, class Function>
void doUndoCaptureMove(Player2Type<P> player, Square from,Square to,
Piece target, int promoteMask,Function& func);
template<Player P>
void prologueCapture(Player2Type<P>, Square from, Square to, Piece target,
int promoteMask,
Piece& oldPiece, PtypeO& oldPtypeO, PtypeO& capturePtypeO,
PtypeO& new_ptypeo, int& num0, int& num1,
int& num1Index, mask_t& num1Mask,
CArray<PieceMask,2>& pin_or_open_backup,
KingMobility& king_mobility_backup,
PieceMask& promoted_backup,
CArray<PieceMask,2>& effected_mask_backup,
CArray<PieceMask,2>& effected_changed_mask_backup,
CArray<uint64_t,2>& king8infos_backup,
MobilityTable &mobility_backup);
template<Player P>
void epilogueCapture(Player2Type<P>, Square from, Square to, Piece target,
Piece oldPiece, PtypeO oldPtypeO, PtypeO capturePtypeO,
PtypeO newPtypeO, int num0, int num1,
int num1Index, mask_t num1Mask,
const CArray<PieceMask,2>& pin_or_open_backup,
const KingMobility& king_mobility_backup,
const PieceMask& promoted_backup,
const CArray<PieceMask,2>& effected_mask_backup,
const CArray<PieceMask,2>& effected_changed_mask_backup,
const CArray<uint64_t,2>& king8infos_backup,
const MobilityTable &mobility_backup);
//
template<Direction DIR>
void makePinOpenDir(Square target,
PieceMask& pins, PieceMask const& onBoard,Player defense)
{
const Offset offset = DirectionTraits<DIR>::blackOffset();
Square sq=target-offset;
int num;
while(Piece::isEmptyNum(num=pieceAt(sq).number()))
sq-=offset;
king_mobility[defense][DIR]=static_cast<unsigned char>(sq.uintValue());
if(Piece::isEdgeNum(num)) return;
int num1=longEffectNumTable()[num][DIR];
if(Piece::isPieceNum(num1) && onBoard.test(num1)){
pins.set(num);
}
}
void recalcPinOpen(Square changed, Direction &lastDir, Player defense)
{
Square target=kingSquare(defense);
#ifdef ALLOW_KING_ABSENCE
if (target.isPieceStand())
return;
#endif
const Direction longD=Board_Table.getLongDirection<BLACK>(changed,target);
if(!isLong(longD) || (lastDir!=UL && longD==lastDir)) return;
lastDir=longD;
Direction shortD=longToShort(longD);
{
// reset old pins
Square oldPos=Square::makeDirect(king_mobility[defense][shortD]);
int oldNum=pieceAt(oldPos).number();
if(Piece::isPieceNum(oldNum))
pin_or_open[defense].reset(oldNum);
}
const Offset offset = Board_Table.getOffsetForBlack(longD);
Square sq=target-offset;
int num;
while(Piece::isEmptyNum(num=pieceAt(sq).number()))
sq-=offset;
king_mobility[defense][shortD]=static_cast<unsigned char>(sq.uintValue());
if(Piece::isEdgeNum(num)) return;
int num1=longEffectNumTable()[num][shortD];
if(Piece::isPieceNum(num1) && piecesOnBoard(alt(defense)).test(num1)){
pin_or_open[defense].set(num);
}
}
PieceMask makePinOpen(Square target,Player defense);
void makePinOpen(Player defense);
template<Player P>
void makeKing8Info();
};
inline bool operator!=(const NumEffectState& s1, const NumEffectState& s2)
{
return !(s1==s2);
}
} // namespace osl
template <osl::Player P, typename Function>
void osl::NumEffectState::
doUndoSimpleMove(Player2Type<P> player,
Square from, Square to, int promoteMask, Function& func)
{
Piece oldPiece;
int num;
PtypeO oldPtypeO, newPtypeO;
CArray<PieceMask,2> pin_or_open_backup;
KingMobility king_mobility_backup;
PieceMask promoted_backup;
CArray<PieceMask,2> effected_mask_backup;
CArray<PieceMask,2> effected_changed_mask_backup;
CArray<uint64_t,2> king8infos_backup;
MobilityTable mobility_backup;
prologueSimple(player, from, to, promoteMask, oldPiece, num, oldPtypeO, newPtypeO,
pin_or_open_backup,
king_mobility_backup,
promoted_backup,
effected_mask_backup, effected_changed_mask_backup,
king8infos_backup,
mobility_backup);
if (promoteMask!=0 && num < PtypeTraits<PAWN>::indexLimit)
{
clearPawn(P,from);
changeTurn();
func(to);
changeTurn();
setPawn(P,from);
}
else
{
changeTurn();
func(to);
changeTurn();
}
epilogueSimple(from, to, oldPiece, num, oldPtypeO, newPtypeO,
pin_or_open_backup,
king_mobility_backup,
promoted_backup, effected_mask_backup, effected_changed_mask_backup,
king8infos_backup,
mobility_backup);
}
template <osl::Player P, typename Function>
void osl::NumEffectState::doUndoDropMove(Player2Type<P> player,
Square to, Ptype ptype, Function& func)
{
Piece oldPiece;
PtypeO ptypeO;
int num, numIndex;
mask_t numMask;
CArray<PieceMask,2> pin_or_open_backup;
KingMobility king_mobility_backup;
CArray<PieceMask,2> effected_mask_backup;
CArray<PieceMask,2> effected_changed_mask_backup;
CArray<uint64_t,2> king8infos_backup;
MobilityTable mobility_backup;
prologueDrop(player, to, ptype, oldPiece, num, ptypeO, numIndex, numMask,
pin_or_open_backup, king_mobility_backup,
effected_mask_backup,effected_changed_mask_backup,
king8infos_backup,
mobility_backup);
if (ptype==PAWN)
{
setPawn(P,to);
changeTurn();
func(to);
changeTurn();
clearPawn(P,to);
}
else
{
changeTurn();
func(to);
changeTurn();
}
epilogueDrop(player, to, ptype, oldPiece, num, ptypeO, numIndex, numMask,
pin_or_open_backup, king_mobility_backup,
effected_mask_backup,effected_changed_mask_backup,
king8infos_backup,
mobility_backup);
}
template <osl::Player P, typename Function>
void osl::NumEffectState::doUndoCaptureMove(Player2Type<P> player,
Square from,Square to, Piece target,
int promoteMask,Function& func)
{
Piece oldPiece;
PtypeO oldPtypeO, capturePtypeO, newPtypeO;
int num0, num1, num1Index;
mask_t num1Mask;
CArray<PieceMask,2> pin_or_open_backup;
KingMobility king_mobility_backup;
PieceMask promoted_backup;
CArray<PieceMask,2> effected_mask_backup;
CArray<PieceMask,2> effected_changed_mask_backup;
CArray<uint64_t,2> king8infos_backup;
MobilityTable mobility_backup;
prologueCapture(player, from, to, target, promoteMask, oldPiece, oldPtypeO,
capturePtypeO, newPtypeO, num0, num1, num1Index,num1Mask,
pin_or_open_backup, king_mobility_backup,
promoted_backup,
effected_mask_backup, effected_changed_mask_backup,
king8infos_backup,
mobility_backup);
changeTurn();
const Ptype capturePtype=target.ptype();
if (capturePtype==PAWN)
{
clearPawn(alt(P),to);
if (promoteMask!=0 && num0<PtypeTraits<PAWN>::indexLimit)
{
clearPawn(P,from);
func(to);
setPawn(P,from);
}
else
{
func(to);
}
setPawn(alt(P),to);
}
else if (promoteMask!=0 && num0<PtypeTraits<PAWN>::indexLimit)
{
clearPawn(P,from);
func(to);
setPawn(P,from);
}
else
{
func(to);
}
changeTurn();
epilogueCapture(player, from, to, target, oldPiece, oldPtypeO, capturePtypeO, newPtypeO,
num0, num1, num1Index,num1Mask,
pin_or_open_backup, king_mobility_backup,
promoted_backup,effected_mask_backup, effected_changed_mask_backup,
king8infos_backup,
mobility_backup);
}
template <class Action>
void osl::NumEffectState::
forEachEffectOfPiece(Piece piece,Action & action) const
{
Square pieceSquare = piece.square();
switch ((int)piece.ptypeO()) {
case NEW_PTYPEO(WHITE,PAWN): forEachEffectOfPiece<WHITE,PAWN,Action>(pieceSquare,action); break;
case NEW_PTYPEO(WHITE,LANCE): forEachEffectOfPiece<WHITE,LANCE,Action>(pieceSquare,action); break;
case NEW_PTYPEO(WHITE,KNIGHT): forEachEffectOfPiece<WHITE,KNIGHT,Action>(pieceSquare,action); break;
case NEW_PTYPEO(WHITE,SILVER): forEachEffectOfPiece<WHITE,SILVER,Action>(pieceSquare,action); break;
case NEW_PTYPEO(WHITE,PPAWN): forEachEffectOfPiece<WHITE,PPAWN,Action>(pieceSquare,action); break;
case NEW_PTYPEO(WHITE,PLANCE): forEachEffectOfPiece<WHITE,PLANCE,Action>(pieceSquare,action); break;
case NEW_PTYPEO(WHITE,PKNIGHT): forEachEffectOfPiece<WHITE,PKNIGHT,Action>(pieceSquare,action); break;
case NEW_PTYPEO(WHITE,PSILVER): forEachEffectOfPiece<WHITE,PSILVER,Action>(pieceSquare,action); break;
case NEW_PTYPEO(WHITE,GOLD): forEachEffectOfPiece<WHITE,GOLD,Action>(pieceSquare,action); break;
case NEW_PTYPEO(WHITE,BISHOP): forEachEffectOfPiece<WHITE,BISHOP,Action>(pieceSquare,action); break;
case NEW_PTYPEO(WHITE,PBISHOP): forEachEffectOfPiece<WHITE,PBISHOP,Action>(pieceSquare,action); break;
case NEW_PTYPEO(WHITE,ROOK): forEachEffectOfPiece<WHITE,ROOK,Action>(pieceSquare,action); break;
case NEW_PTYPEO(WHITE,PROOK): forEachEffectOfPiece<WHITE,PROOK,Action>(pieceSquare,action); break;
case NEW_PTYPEO(WHITE,KING): forEachEffectOfPiece<WHITE,KING,Action>(pieceSquare,action); break;
case NEW_PTYPEO(BLACK,PAWN): forEachEffectOfPiece<BLACK,PAWN,Action>(pieceSquare,action); break;
case NEW_PTYPEO(BLACK,LANCE): forEachEffectOfPiece<BLACK,LANCE,Action>(pieceSquare,action); break;
case NEW_PTYPEO(BLACK,KNIGHT): forEachEffectOfPiece<BLACK,KNIGHT,Action>(pieceSquare,action); break;
case NEW_PTYPEO(BLACK,SILVER): forEachEffectOfPiece<BLACK,SILVER,Action>(pieceSquare,action); break;
case NEW_PTYPEO(BLACK,PPAWN): forEachEffectOfPiece<BLACK,PPAWN,Action>(pieceSquare,action); break;
case NEW_PTYPEO(BLACK,PLANCE): forEachEffectOfPiece<BLACK,PLANCE,Action>(pieceSquare,action); break;
case NEW_PTYPEO(BLACK,PKNIGHT): forEachEffectOfPiece<BLACK,PKNIGHT,Action>(pieceSquare,action); break;
case NEW_PTYPEO(BLACK,PSILVER): forEachEffectOfPiece<BLACK,PSILVER,Action>(pieceSquare,action); break;
case NEW_PTYPEO(BLACK,GOLD): forEachEffectOfPiece<BLACK,GOLD,Action>(pieceSquare,action); break;
case NEW_PTYPEO(BLACK,BISHOP): forEachEffectOfPiece<BLACK,BISHOP,Action>(pieceSquare,action); break;
case NEW_PTYPEO(BLACK,PBISHOP): forEachEffectOfPiece<BLACK,PBISHOP,Action>(pieceSquare,action); break;
case NEW_PTYPEO(BLACK,ROOK): forEachEffectOfPiece<BLACK,ROOK,Action>(pieceSquare,action); break;
case NEW_PTYPEO(BLACK,PROOK): forEachEffectOfPiece<BLACK,PROOK,Action>(pieceSquare,action); break;
case NEW_PTYPEO(BLACK,KING): forEachEffectOfPiece<BLACK,KING,Action>(pieceSquare,action); break;
default: assert(0);
}
}
template <osl::Player P, osl::Ptype Type, class Action>
void osl::NumEffectState::
forEachEffectOfPiece(Square pieceSquare,Action & action) const
{
forEachEffectOfPieceDir<P,Type,Action,UL>(pieceSquare,action);
forEachEffectOfPieceDir<P,Type,Action,U>(pieceSquare,action);
forEachEffectOfPieceDir<P,Type,Action,UR>(pieceSquare,action);
forEachEffectOfPieceDir<P,Type,Action,L>(pieceSquare,action);
forEachEffectOfPieceDir<P,Type,Action,R>(pieceSquare,action);
forEachEffectOfPieceDir<P,Type,Action,DL>(pieceSquare,action);
forEachEffectOfPieceDir<P,Type,Action,D>(pieceSquare,action);
forEachEffectOfPieceDir<P,Type,Action,DR>(pieceSquare,action);
forEachEffectOfPieceDir<P,Type,Action,UUL>(pieceSquare,action);
forEachEffectOfPieceDir<P,Type,Action,UUR>(pieceSquare,action);
forEachEffectOfPieceLongDir<P,Type,Action,LONG_UL>(pieceSquare,action);
forEachEffectOfPieceLongDir<P,Type,Action,LONG_U>(pieceSquare,action);
forEachEffectOfPieceLongDir<P,Type,Action,LONG_UR>(pieceSquare,action);
forEachEffectOfPieceLongDir<P,Type,Action,LONG_L>(pieceSquare,action);
forEachEffectOfPieceLongDir<P,Type,Action,LONG_R>(pieceSquare,action);
forEachEffectOfPieceLongDir<P,Type,Action,LONG_DL>(pieceSquare,action);
forEachEffectOfPieceLongDir<P,Type,Action,LONG_D>(pieceSquare,action);
forEachEffectOfPieceLongDir<P,Type,Action,LONG_DR>(pieceSquare,action);
}
#include "osl/bits/pieceStand.h"
#endif /* OSL_NUM_EFFECT_STATE_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
align16New.h
NEW_PTYPEO
#define NEW_PTYPEO(player, ptype)
Definition basic_type.h:204
pieceStand.h
osl::CArray
Definition container.h:20
osl::EffectContent
Definition effectContent.h:11
osl::MoveVector
Definition container.h:293
osl::Move
圧縮していない moveの表現 .
Definition basic_type.h:1052
osl::Move::isValid
bool isValid() const
Definition basic_type.cc:246
osl::Move::ptype
Ptype ptype() const
Definition basic_type.h:1155
osl::Move::player
Player player() const
Definition basic_type.h:1195
osl::Move::isPass
bool isPass() const
Definition basic_type.h:1092
osl::Move::promoteMask
int promoteMask() const
pieceに使うためのmaskなので
Definition basic_type.h:1143
osl::Move::to
const Square to() const
Definition basic_type.h:1132
osl::Move::from
const Square from() const
Definition basic_type.h:1125
osl::NumBitmapEffect::playerEffect
static NumBitmapEffect playerEffect()
Definition numBitmapEffect.h:35
osl::NumBitmapEffect::longEffectMask
static const mask_t longEffectMask()
Definition numBitmapEffect.h:107
osl::NumBitmapEffect::playerEffectMask
static mask_t playerEffectMask()
Definition numBitmapEffect.h:53
osl::NumEffectState
利きを持つ局面
Definition numEffectState.h:34
osl::NumEffectState::hasEffectByNotPinned
bool hasEffectByNotPinned(Player pl, Square target) const
pinされている駒以外からの利きがある.
Definition numEffectState.h:428
osl::NumEffectState::pinnedDir
Direction pinnedDir(Piece p) const
pinされた駒がPのKingから見てどの方向か?
Definition numEffectState.h:203
osl::NumEffectState::pinnedCanMoveTo
bool pinnedCanMoveTo(Piece p, Square to) const
pinされた駒pがtoに動けるか?
Definition numEffectState.h:222
osl::NumEffectState::doUndoSimpleMove
void doUndoSimpleMove(Player2Type< P > player, Square from, Square to, int promoteMask, Function &func)
Definition numEffectState.h:1042
osl::NumEffectState::generateLegal
void generateLegal(MoveVector &) const
全ての合法手を生成する.
Definition numEffectState.cc:1086
osl::NumEffectState::effectSetAt
const NumBitmapEffect effectSetAt(Square sq) const
Definition numEffectState.h:258
osl::NumEffectState::findLongAttackAt
const Piece findLongAttackAt(Player owner, Piece piece, Direction d) const
Definition numEffectState.h:536
osl::NumEffectState::findCheapAttackNotBy
const Piece findCheapAttackNotBy(Player P, Square square, const PieceMask &ignore) const
Definition numEffectState.h:569
osl::NumEffectState::hasEffectByWithRemove
bool hasEffectByWithRemove(Square target, Square removed) const
osl::NumEffectState::hasEffectInDirection
bool hasEffectInDirection(Square to) const
あるマスにあるDirectionでの長い利きがあるかどうか.
Definition numEffectState.h:377
osl::NumEffectState::hasChangedEffects
bool hasChangedEffects() const
Definition numEffectState.h:141
osl::NumEffectState::recalcPinOpen
void recalcPinOpen(Square changed, Direction &lastDir, Player defense)
Definition numEffectState.h:998
osl::NumEffectState::doCaptureMove
void doCaptureMove(Square from, Square to, Piece target, int promoteMask)
Definition numEffectState.cc:260
osl::NumEffectState::forEachEffectOfPieceLongDir
void forEachEffectOfPieceLongDir(Square, Action &, Int2Type< false >) const
Definition numEffectState.h:828
osl::NumEffectState::king8Info
const checkmate::King8Info king8Info(Player king) const
Definition numEffectState.cc:44
osl::NumEffectState::epilogueCapture
void epilogueCapture(Player2Type< P >, Square from, Square to, Piece target, Piece oldPiece, PtypeO oldPtypeO, PtypeO capturePtypeO, PtypeO newPtypeO, int num0, int num1, int num1Index, mask_t num1Mask, const CArray< PieceMask, 2 > &pin_or_open_backup, const KingMobility &king_mobility_backup, const PieceMask &promoted_backup, const CArray< PieceMask, 2 > &effected_mask_backup, const CArray< PieceMask, 2 > &effected_changed_mask_backup, const CArray< uint64_t, 2 > &king8infos_backup, const MobilityTable &mobility_backup)
Definition numEffectState.cc:626
osl::NumEffectState::forEachEffectOfPieceDir
void forEachEffectOfPieceDir(Square, Action &, Int2Type< false >) const
Definition numEffectState.h:816
osl::NumEffectState::hasEffectByNotPinnedAndKing
bool hasEffectByNotPinnedAndKing(Player pl, Square target) const
{pinされている駒, 玉以外}からの利きがある.
Definition numEffectState.h:419
osl::NumEffectState::isOpenCheck
bool isOpenCheck(Move move) const
Definition numEffectState.cc:1074
osl::NumEffectState::findAttackAtStrict
const Piece findAttackAtStrict(Player attack, Square target) const
Definition numEffectState.h:511
osl::NumEffectState::changedEffects
const BoardMask changedEffects(Player pl) const
Definition numEffectState.h:144
osl::NumEffectState::longEffectNumTable
const EffectedNumTable & longEffectNumTable() const
Definition numEffectState.h:124
osl::NumEffectState::pieces_onboard
CArray< PieceMask, 2 > pieces_onboard
Definition numEffectState.h:36
osl::NumEffectState::selectCheapPiece
const Piece selectCheapPiece(PieceMask effect) const
利きの中から安そうな駒を選ぶ
Definition numEffectState.cc:100
osl::NumEffectState::findCheckPiece
bool findCheckPiece(Piece &attack_piece) const
王手駒を探す
Definition numEffectState.h:593
osl::NumEffectState::isPawnDropCheckmate
bool isPawnDropCheckmate(Move move) const
Definition numEffectState.cc:1063
osl::NumEffectState::longEffectChanged
bool longEffectChanged() const
Definition numEffectState.h:155
osl::NumEffectState::effectedMask
const PieceMask effectedMask(Player pl) const
pl からの利きが(1つ以上)ある駒一覧
Definition numEffectState.h:130
osl::NumEffectState::findAttackNotBy
const Piece findAttackNotBy(Player P, Square square, const PieceMask &ignore) const
Definition numEffectState.h:575
osl::NumEffectState::checkShadow
const PieceMask checkShadow(Player attack) const
attack の駒で動くと開き王手になる可能性がある集合
Definition numEffectState.h:70
osl::NumEffectState::doSimpleMove
void doSimpleMove(Square from, Square to, int promoteMask)
Definition numEffectState.cc:232
osl::NumEffectState::changedEffects
const BoardMask changedEffects() const
Definition numEffectState.h:148
osl::NumEffectState::hasEffectNotBy
bool hasEffectNotBy(Player player, Piece piece, Square target) const
対象とするマスにあるプレイヤーの(ただしある駒以外)利きがあるかどうか.
Definition numEffectState.h:409
osl::NumEffectState::makePinOpenDir
void makePinOpenDir(Square target, PieceMask &pins, PieceMask const &onBoard, Player defense)
Definition numEffectState.h:983
osl::NumEffectState::forEachEffect
void forEachEffect(const PieceMask &pieces, Square sq, Action &action) const
Definition numEffectState.h:754
osl::NumEffectState::forEachEffect
void forEachEffect(Square sq, Action &action, const PieceMask &pin) const
sq にある駒を取る move を生成して action の member を呼び出す.
Definition numEffectState.h:795
osl::NumEffectState::prologueCapture
void prologueCapture(Player2Type< P >, Square from, Square to, Piece target, int promoteMask, Piece &oldPiece, PtypeO &oldPtypeO, PtypeO &capturePtypeO, PtypeO &new_ptypeo, int &num0, int &num1, int &num1Index, mask_t &num1Mask, CArray< PieceMask, 2 > &pin_or_open_backup, KingMobility &king_mobility_backup, PieceMask &promoted_backup, CArray< PieceMask, 2 > &effected_mask_backup, CArray< PieceMask, 2 > &effected_changed_mask_backup, CArray< uint64_t, 2 > &king8infos_backup, MobilityTable &mobility_backup)
Definition numEffectState.cc:531
osl::NumEffectState::longEffectAt
const mask_t longEffectAt(Square target, Player owner) const
Definition numEffectState.h:302
osl::NumEffectState::wasCheckEvasion
bool wasCheckEvasion(Move last_move) const
Definition numEffectState.cc:175
osl::NumEffectState::makeMove
void makeMove(Move move)
Definition numEffectState.cc:201
osl::NumEffectState::countEffect
int countEffect(Player player, Square target) const
利きの数を数える.
Definition numEffectState.h:266
osl::NumEffectState::isAlmostValidMove
bool isAlmostValidMove(Move move) const
合法手かどうかを簡単に検査する．局面に依存するチェックのみ． ルール上指せない手である可能性がある場合は，isValidMove を用いる．
Definition numEffectState.cc:823
osl::NumEffectState::hasEffectByPiece
bool hasEffectByPiece(Piece attack, Square target) const
駒attack が target に利きを持つか (旧hasEffectToと統合)
Definition numEffectState.h:450
osl::NumEffectState::effectedChanged
const PieceMask effectedChanged(Player pl) const
前の指手でeffectedMask(pl)が変化したか.
Definition numEffectState.h:137
osl::NumEffectState::copyFrom
void copyFrom(const NumEffectState &src)
主要部分を高速にコピーする.
Definition numEffectState.cc:932
osl::NumEffectState::generateAllUnsafe
void generateAllUnsafe(MoveVector &) const
自殺を含めてすべての手を生成
Definition numEffectState.cc:1081
osl::NumEffectState::makePinOpen
PieceMask makePinOpen(Square target, Player defense)
Definition numEffectState.cc:884
osl::NumEffectState::isDirectCheck
bool isDirectCheck(Move move) const
Definition numEffectState.cc:1068
osl::NumEffectState::forEachEffectNotBy
void forEachEffectNotBy(Square sq, Piece piece, Action &action) const
sq に移動する move を生成して action の member を呼び出す
Definition numEffectState.h:808
osl::NumEffectState::forEachEffect
void forEachEffect(Square sq, Action &action) const
sq への利きを持つ各駒に関して処理を行う.
Definition numEffectState.h:784
osl::NumEffectState::findLongAttackAt
const Piece findLongAttackAt(Player owner, int piece, Direction d) const
pieceのd方向から長い利きがある場合にその駒を返す。
Definition numEffectState.h:526
osl::NumEffectState::hasEffectAt
bool hasEffectAt(Square target) const
対象とするマスにあるプレイヤーの利きがあるかどうか.
Definition numEffectState.h:324
osl::NumEffectState::prologueSimple
void prologueSimple(Player2Type< P >, Square from, Square to, int promoteMask, Piece &oldPiece, int &num, PtypeO &oldPtypeO, PtypeO &new_ptypeo, CArray< PieceMask, 2 > &pin_or_open_backup, KingMobility &king_mobility_backup, PieceMask &promoted_backup, CArray< PieceMask, 2 > &effected_mask_backup, CArray< PieceMask, 2 > &effected_changed_mask_backup, CArray< uint64_t, 2 > &king8infos_backup, MobilityTable &mobility_backup)
Definition numEffectState.cc:321
osl::NumEffectState::findLongAttackAt
const Piece findLongAttackAt(Piece piece, Direction d) const
Definition numEffectState.h:542
osl::NumEffectState::pin
const PieceMask pin(Player king) const
Definition numEffectState.h:65
osl::NumEffectState::makeMovePass
void makeMovePass()
Definition numEffectState.h:668
osl::NumEffectState::hasMultipleEffectAt
bool hasMultipleEffectAt(Player player, Square target) const
二つ以上の駒から利きがある.
Definition numEffectState.h:439
osl::NumEffectState::pinAttacker
Piece pinAttacker(Piece pinned) const
Pのpinされた駒から，そのpinの原因となっている長い利きを持つ駒を得る．
Definition numEffectState.h:240
osl::NumEffectState::inUnblockableCheck
bool inUnblockableCheck(Player target) const
target の王に合駒可能でない王手がかかっているかどうか.
Definition numEffectState.h:107
osl::NumEffectState::hasLongEffectAt
bool hasLongEffectAt(Player P, Square to) const
あるマスにPTYPEの長い利きがあるかどうか.
Definition numEffectState.h:346
osl::NumEffectState::longEffectAt
const mask_t longEffectAt(Square target, Player owner) const
Definition numEffectState.h:310
osl::NumEffectState::NumEffectState
NumEffectState(const SimpleState &st=SimpleState(HIRATE))
Definition numEffectState.cc:61
osl::NumEffectState::findCheapAttack
const Piece findCheapAttack(Player P, Square square) const
Definition numEffectState.h:560
osl::NumEffectState::state_t
NumEffectState state_t
Definition numEffectState.h:44
osl::NumEffectState::forEachEffectOfPieceDir
void forEachEffectOfPieceDir(Square pieceSquare, Action &action, Int2Type< true >) const
Definition numEffectState.h:818
osl::NumEffectState::makeUnmakePass
void makeUnmakePass(Function &f)
Definition numEffectState.h:676
osl::NumEffectState::changedPieces
const NumBitmapEffect changedPieces() const
Definition numEffectState.h:152
osl::NumEffectState::kingMobilityAbs
Square kingMobilityAbs(Player p, Direction d) const
Definition numEffectState.h:183
osl::NumEffectState::findThreatenedPiece
const Piece findThreatenedPiece(Player P) const
取られそうなPの駒で価値が最大のもの
Definition numEffectState.cc:139
osl::NumEffectState::effects
effect::NumSimpleEffectTable effects
Definition numEffectState.h:35
osl::NumEffectState::safeCaptureNotByKing
Piece safeCaptureNotByKing(Square target, Piece king) const
玉の素抜きなしに合法手でtargetに移動可能かを判定
osl::NumEffectState::mobilityOf
Square mobilityOf(Direction d, int num) const
Definition numEffectState.h:175
osl::NumEffectState::promotedPieces
const PieceMask promotedPieces() const
Definition numEffectState.h:64
osl::NumEffectState::findEffect
void findEffect(Player P, Square target, PieceVector &out) const
target に利きのあるPieceをoutに格納する
Definition numEffectState.cc:1119
osl::NumEffectState::promoted
PieceMask promoted
成駒一覧
Definition numEffectState.h:38
osl::NumEffectState::operator==
friend bool operator==(const NumEffectState &st1, const NumEffectState &st2)
駒番に依存した局面（インスタンス）比較をする.
osl::NumEffectState::forEachEffectOfPieceDir
void forEachEffectOfPieceDir(Square pieceSquare, Action &action) const
Definition numEffectState.h:824
osl::NumEffectState::isOnBoardNum
bool isOnBoardNum(int num) const
Definition numEffectState.h:170
osl::NumEffectState::hasEffectIf
bool hasEffectIf(PtypeO ptypeo, Square attacker, Square target) const
attackerにptypeoの駒がいると仮定した場合にtargetに利きがあるかどうか を stateをupdateしないで確かめる.
Definition numEffectState.h:465
osl::NumEffectState::doDropMove
void doDropMove(Square to, Ptype ptype)
Definition numEffectState.cc:293
osl::NumEffectState::findAttackAt
const Piece findAttackAt(Player attack, Square target) const
return a piece s.t.
Definition numEffectState.h:503
osl::NumEffectState::inCheck
bool inCheck(Player P) const
Pの玉が王手状態
Definition numEffectState.h:88
osl::NumEffectState::pinAttacker
Piece pinAttacker(Piece pinned) const
Definition numEffectState.h:248
osl::NumEffectState::epilogueSimple
void epilogueSimple(Square from, Square to, Piece oldPiece, int num, PtypeO oldPtypeO, PtypeO newPtypeO, const CArray< PieceMask, 2 > &pin_or_open_backup, const KingMobility &king_mobility_backup, const PieceMask &promoted_backup, const CArray< PieceMask, 2 > &effected_mask_backup, const CArray< PieceMask, 2 > &effected_changed_mask_backup, const CArray< uint64_t, 2 > &king8infos_backup, const MobilityTable &mobility_backup)
Definition numEffectState.cc:401
osl::NumEffectState::forEachEffectOfPieceLongDir
void forEachEffectOfPieceLongDir(Square pieceSquare, Action &action) const
Definition numEffectState.h:841
osl::NumEffectState::longEffectAt
const mask_t longEffectAt(Square target) const
Definition numEffectState.h:298
osl::NumEffectState::king_mobility
KingMobility king_mobility
Definition numEffectState.h:40
osl::NumEffectState::kingMobilityOfPlayer
Square kingMobilityOfPlayer(Player p, Direction d) const
玉がd方向にどこまで動けるかを返す
Definition numEffectState.h:192
osl::NumEffectState::makeUnmakeMove
void makeUnmakeMove(Move move, Function &f)
Definition numEffectState.h:683
osl::NumEffectState::makeKing8Info
void makeKing8Info()
Definition numEffectState.cc:50
osl::NumEffectState::forEachEffectOfPtypeO
void forEachEffectOfPtypeO(Square, Ptype, Function &f) const
osl::NumEffectState::forEachEffectOfPiece
void forEachEffectOfPiece(Square pieceSquare, Action &action) const
pieceSquareにある駒によって利きを受けるすべてのsquare (空白含む)について actionを実行する
Definition numEffectState.h:1225
osl::NumEffectState::pinnedDir
Direction pinnedDir(Piece p) const
Definition numEffectState.h:210
osl::NumEffectState::showEffect
void showEffect(std::ostream &os) const
Definition numEffectState.cc:858
osl::NumEffectState::~NumEffectState
~NumEffectState()
Definition numEffectState.cc:95
osl::NumEffectState::makeUnmakeMove
void makeUnmakeMove(Player2Type< P > player, Move move, Function &f)
Definition numEffectState.h:691
osl::NumEffectState::king8infos
CArray< uint64_t, 2 > king8infos
Definition numEffectState.h:41
osl::NumEffectState::inCheck
bool inCheck() const
手番の玉が王手状態
Definition numEffectState.h:98
osl::NumEffectState::pin_or_open
CArray< PieceMask, 2 > pin_or_open
Definition numEffectState.h:39
osl::NumEffectState::anyEffectChanged
bool anyEffectChanged() const
Definition numEffectState.h:159
osl::NumEffectState::doUndoDropMove
void doUndoDropMove(Player2Type< P > player, Square to, Ptype ptype, Function &func)
Definition numEffectState.h:1085
osl::NumEffectState::findLongAttackAt
const Piece findLongAttackAt(Square square, Direction d) const
Definition numEffectState.h:547
osl::NumEffectState::pinnedCanMoveTo
bool pinnedCanMoveTo(Piece p, Square to) const
Definition numEffectState.h:229
osl::NumEffectState::safeCaptureNotByKing
Piece safeCaptureNotByKing(Player P, Square target) const
Definition numEffectState.h:875
osl::NumEffectState::isSafeMove
bool isSafeMove(Move move) const
Definition numEffectState.cc:1053
osl::NumEffectState::pinOrOpen
PieceMask pinOrOpen(Player king) const
Definition numEffectState.h:74
osl::NumEffectState::hasEffectAt
bool hasEffectAt(Player player, Square target) const
対象とするマスにあるプレイヤーの利きがあるかどうか.
Definition numEffectState.h:335
osl::NumEffectState::piecesOnBoard
const PieceMask & piecesOnBoard(Player p) const
Definition numEffectState.h:63
osl::NumEffectState::forEachEffectOfPieceLongDir
void forEachEffectOfPieceLongDir(Square pieceSquare, Action &action, Int2Type< true >) const
Definition numEffectState.h:830
osl::NumEffectState::doUndoCaptureMove
void doUndoCaptureMove(Player2Type< P > player, Square from, Square to, Piece target, int promoteMask, Function &func)
Definition numEffectState.h:1125
osl::NumEffectState::hasEffectAt
bool hasEffectAt(Square target, Piece &attackerPiece) const
Definition numEffectState.h:611
osl::NumEffectState::Iking8Info
uint64_t Iking8Info(Player king) const
Definition numEffectState.h:78
osl::NumEffectState::epilogueDrop
void epilogueDrop(Player2Type< P >, Square to, Ptype ptype, Piece oldPiece, int num, PtypeO ptypeO, int numIndex, mask_t numMask, const CArray< PieceMask, 2 > &pin_or_open_backup, const KingMobility &king_mobility_backup, const CArray< PieceMask, 2 > &effected_mask_backup, const CArray< PieceMask, 2 > &effected_changed_mask_backup, const CArray< uint64_t, 2 > &king8infos_backup, const MobilityTable &mobility_backup)
Definition numEffectState.cc:503
osl::NumEffectState::hasEffectByPtypeStrict
bool hasEffectByPtypeStrict(Player attack, Square target) const
target に ptype の利きがあるか?
Definition numEffectState.h:363
osl::NumEffectState::forEachEffectOfPtypeO
void forEachEffectOfPtypeO(Square, PtypeO, Function &f) const
PtypeO が Square にいると仮定した時にの利きを列挙.
osl::NumEffectState::longEffectAt
const mask_t longEffectAt(Square target) const
Definition numEffectState.h:306
osl::NumEffectState::forEachEffect
void forEachEffect(Player P, Square pos, Action &a) const
forEachEffect の Player のtemplate 引数を通常の引数にしたバージョン
Definition numEffectState.h:888
osl::NumEffectState::forEachOnBoard
void forEachOnBoard(F &func) const
T は isBasic でなくても動くが unpromote(T) の結果と同じ.
Definition numEffectState.h:727
osl::NumEffectState::hasEffectByPtype
bool hasEffectByPtype(Player attack, Square target) const
target に ptype の利きがあるか?
Definition numEffectState.h:355
osl::NumEffectState::isConsistent
bool isConsistent(bool showError=true) const
Definition numEffectState.cc:663
osl::NumEffectState::prologueDrop
void prologueDrop(Player2Type< P >, Square to, Ptype ptype, Piece &oldPiece, int &num, PtypeO &ptypeO, int &numIndex, mask_t &numMask, CArray< PieceMask, 2 > &pin_or_open_backup, KingMobility &king_mobility_backup, CArray< PieceMask, 2 > &effected_mask_backup, CArray< PieceMask, 2 > &effected_changed_mask_backup, CArray< uint64_t, 2 > &king8infos_backup, MobilityTable &mobility_backup)
Definition numEffectState.cc:431
osl::NumEffectState::isCheck
bool isCheck(Move move) const
Definition numEffectState.cc:1058
osl::NumEffectState::forEachOnBoardPtypeStrict
void forEachOnBoardPtypeStrict(F &func) const
T の成不成を区別
Definition numEffectState.h:739
osl::NumEffectState::hasEffectAt
bool hasEffectAt(Player P, Square target, Piece &attackerPiece) const
Definition numEffectState.h:597
osl::NumEffectState::allEffectAt
const mask_t allEffectAt(Player P, Square target) const
Definition numEffectState.h:293
osl::NumEffectState::mobilityOf
Square mobilityOf(Direction d, Piece p) const
Definition numEffectState.h:179
osl::NumEffectState::hasEffectByWithRemove
bool hasEffectByWithRemove(Player player, Square target, Square removed) const
Definition numEffectState.h:490
osl::NumEffectState::countEffect
int countEffect(Player player, Square target, PieceMask pins) const
利きの数を数える.
Definition numEffectState.h:280
osl::NumEffectState::generateWithFullUnpromotions
void generateWithFullUnpromotions(MoveVector &) const
打歩詰め絡み以外では有利にはならない手も含め, 全ての合法手を生成す る（Move::ignoredUnpromoteも生成する）.
Definition numEffectState.cc:1105
osl::Offset
座標の差分
Definition basic_type.h:430
osl::Offset::intValue
int intValue() const
Definition basic_type.h:448
osl::PieceMask
駒番号のビットセット.
Definition pieceMask.h:21
osl::PieceMask::getMask
const mask_t getMask(int num) const
Definition pieceMask.h:59
osl::PieceMask::set
void set(int num)
Definition pieceMask.h:48
osl::PieceMask::clearBit
void clearBit()
unpromote(PTYPE) の駒のbit を消す
Definition pieceMask.h:74
osl::PieceMask::test
bool test(int num) const
Definition pieceMask.h:45
osl::PieceMask::any
bool any() const
Definition pieceMask.h:57
osl::PieceVector
Definition container.h:305
osl::Piece
駒.
Definition basic_type.h:788
osl::Piece::ptypeO
PtypeO ptypeO() const
Definition basic_type.h:824
osl::Piece::ptype
Ptype ptype() const
Definition basic_type.h:821
osl::Piece::square
const Square square() const
Definition basic_type.h:832
osl::Piece::isEmpty
bool isEmpty() const
Definition basic_type.h:913
osl::Piece::owner
Player owner() const
Definition basic_type.h:963
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::number
int number() const
Definition basic_type.h:828
osl::Piece::isEdgeNum
static bool isEdgeNum(int num)
Definition basic_type.h:922
osl::Piece::EMPTY
static const Piece EMPTY()
Definition basic_type.h:797
osl::SimpleState::pieceOnBoard
const Piece pieceOnBoard(Square sq) const
Definition simpleState.h:170
osl::SimpleState::clearPawn
void clearPawn(Player pl, Square sq)
(internal)
Definition simpleState.h:138
osl::SimpleState::SimpleState
SimpleState()
Definition simpleState.cc:12
osl::SimpleState::kingPiece
const Piece kingPiece() const
Definition simpleState.h:83
osl::SimpleState::turn
Player turn() const
Definition simpleState.h:220
osl::SimpleState::changeTurn
void changeTurn()
手番を変更する
Definition simpleState.h:226
osl::SimpleState::pieces
CArray< Piece, Piece::SIZE > pieces
全てのpieceが登録されている
Definition simpleState.h:55
osl::SimpleState::pieceOf
const Piece pieceOf(int num) const
Definition simpleState.h:76
osl::SimpleState::setPawn
void setPawn(Player pl, Square sq)
(internal)
Definition simpleState.h:142
osl::SimpleState::isEmptyBetween
bool isEmptyBetween(Square from, Square to, Offset offset, bool pieceExistsAtTo=false) const
Definition simpleState.h:267
osl::SimpleState::kingSquare
Square kingSquare() const
Definition simpleState.h:94
osl::SimpleState::pieceAt
const Piece pieceAt(Square sq) const
Definition simpleState.h:167
osl::Square
Definition basic_type.h:532
osl::Square::isPieceStand
bool isPieceStand() const
Definition basic_type.h:576
osl::Square::uintValue
unsigned int uintValue() const
Definition basic_type.h:539
osl::Square::STAND
static const Square STAND()
Definition basic_type.h:548
osl::Square::isOnBoard
bool isOnBoard() const
盤面上を表すかどうかの判定． 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する．
Definition basic_type.h:583
osl::Square::makeDirect
static const Square makeDirect(int value)
Definition basic_type.h:538
osl::checkmate::King8Info
敵玉の8近傍の状態を表す.
Definition king8Info.h:29
osl::container::BoardMask
11 x 12
Definition boardMask.h:21
osl::container::PieceMask64::countBit
int countBit() const
Definition pieceMask64.h:78
osl::effect::EffectedNumTable
Definition effectedNumTable.h:44
osl::effect::NumBitmapEffect
現在の定義 (2005/3/4以降)
Definition numBitmapEffect.h:29
osl::effect::NumBitmapEffect::countEffect
int countEffect(Player pl) const
Definition numBitmapEffect.h:81
osl::effect::NumBitmapEffect::selectLong
const mask_t selectLong() const
Definition numBitmapEffect.h:138
osl::effect::NumSimpleEffectTable
局面全体の利きデータ.
Definition numSimpleEffect.h:27
osl::misc::GeneralMask::none
bool none() const
Definition mask.h:297
osl::misc::GeneralMask< mask_int_t >::makeDirect
static const GeneralMask makeDirect(mask_int_t value)
Definition mask.h:219
osl::misc::GeneralMask::hasMultipleBit
bool hasMultipleBit() const
non-zeroのmaskが複数ビットセットされているかどうかを返す.
Definition mask.h:272
osl::misc::GeneralMask::any
bool any() const
Definition mask.h:298
osl::misc::GeneralMask::bsf
int bsf() const
Definition mask.h:257
osl::misc::GeneralMask::takeOneBit
int takeOneBit()
non-zeroのmaskのsetされているビットをLSBから探し，その番号を返す 副作用としてmaskの対応するビットをクリアする
Definition mask.h:265
osl::mobility::KingMobility
Definition kingMobility.h:24
osl::mobility::MobilityTable
駒番号からMobilityContentを得る
Definition mobilityTable.h:52
kingMobility.h
osl::checkmate
Definition king8Info.h:12
osl::effect
Definition effectedNumTable.h:8
osl::misc::mask_t
GeneralMask< mask_int_t > mask_t
Definition mask.h:351
osl
Definition additionalEffect.h:6
osl::Ptype
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
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::KING
@ KING
Definition basic_type.h:93
osl::KNIGHT
@ KNIGHT
Definition basic_type.h:97
osl::SILVER
@ SILVER
Definition basic_type.h:98
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::PSILVER
@ PSILVER
Definition basic_type.h:90
osl::Ptype_Table
const PtypeTable Ptype_Table
Definition tables.cc:97
osl::EMPTY_NUM
const int EMPTY_NUM
Definition basic_type.h:778
osl::longToShort
constexpr Direction longToShort(Direction d)
Definition basic_type.h:380
osl::Board_Table
const BoardTable Board_Table
Definition tables.cc:95
osl::primDirUnsafe
constexpr Direction primDirUnsafe(Direction d)
8方向について，primitiveな4方向を求める dとしてknight, INVALIDなども来る
Definition basic_type.h:374
osl::inverseUnsafe
constexpr Direction inverseUnsafe(Direction d)
Definition basic_type.h:354
osl::Direction
Direction
Definition basic_type.h:310
osl::UL
@ UL
Definition basic_type.h:313
osl::isPromoted
bool isPromoted(Ptype ptype)
ptypeがpromote後の型かどうかのチェック
Definition basic_type.h:137
osl::Offset32
Offset32Base< 8, 9 > Offset32
Definition offset32.h:63
osl::operator!=
bool operator!=(Offset l, Offset r)
Definition basic_type.h:516
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::__attribute__
const PtypeO PTYPEO_EDGE __attribute__((unused))
osl::HIRATE
@ HIRATE
Definition simpleState.h:21
osl::PtypeO
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
Definition basic_type.h:199
osl::primDir
constexpr Direction primDir(Direction d)
8方向について，primitiveな4方向を求める
Definition basic_type.h:366
osl::isLong
constexpr bool isLong(Direction d)
Definition basic_type.h:350
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::captured
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に，ownerを反転する．
Definition basic_type.h:264
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
numSimpleEffect.h
osl::DirectionPlayerTraits
Definition directionTraits.h:242
osl::DirectionTraits::mask
static const unsigned int mask
Definition directionTraits.h:227
osl::DirectionTraits::blackOffset
static const Offset blackOffset()
Definition directionTraits.h:231
osl::DirectionTraits::isLong
static const bool isLong
Definition directionTraits.h:228
osl::PtypeDirectionTraits::canMove
static const bool canMove
Definition ptypeTraits.h:342
osl::PtypeFuns
Definition ptypeTraits.h:311
osl::PtypeFuns::indexMask
static const uint64_t indexMask
Definition ptypeTraits.h:318
osl::PtypeTraits
Definition ptypeTraits.h:12
osl::misc::Align16New
Definition align16New.h:12
osl::misc::Int2Type
Definition basic_type.h:69
osl::misc::Player2Type
Definition basic_type.h:75