numEffectState.cc
Go to the documentation of this file.
/* numEffectState.cc
*/
#include "osl/numEffectState.h"
#include "osl/numEffectState.tcc"
#include "osl/simpleState.tcc"
#include "osl/bits/numSimpleEffect.tcc"
#include "osl/move_classifier/moveAdaptor.h"
#include "osl/move_classifier/check_.h"
#include "osl/move_classifier/safeMove.h"
#include "osl/move_classifier/pawnDropCheckmate.h"
#include "osl/move_generator/allMoves.h"
#include "osl/move_generator/escape_.h"
#include "osl/move_generator/move_action.h"
#include "osl/move_generator/effect_action.h"
#include <iostream>
#if (defined(__i386__) || defined(__x86_64__)) && !defined(OSL_NO_SSE)
#include <emmintrin.h>
typedef __v2di v2di;
#endif
bool osl::operator==(const NumEffectState& st1,
const NumEffectState& st2)
{
assert(st1.isConsistent(true));
assert(st2.isConsistent(true));
if (!(st1.effects == st2.effects))
return false;
if (!(st1.pieces_onboard == st2.pieces_onboard))
return false;
if (!(st1.promoted == st2.promoted))
return false;
if (!(st1.pin_or_open == st2.pin_or_open))
return false;
if (!(st1.king_mobility == st2.king_mobility))
return false;
if (!(st1.king8infos == st2.king8infos))
return false;
return (static_cast<const SimpleState&>(st1)
== static_cast<const SimpleState&>(st2));
}
const osl::checkmate::King8Info osl::
NumEffectState::king8Info(Player king) const
{
return King8Info(Iking8Info(king));
}
template<osl::Player P>
void osl::NumEffectState::makeKing8Info()
{
const Player altP=alt(P);
#ifdef ALLOW_KING_ABSENCE
if (kingSquare<P>().isPieceStand())
return;
#endif
king8infos[P]=King8Info::make<altP>(*this,kingSquare<P>()).uint64Value();
}
osl::
NumEffectState::NumEffectState(const SimpleState& st)
: SimpleState(st),effects(st)
{
pieces_onboard[0].resetAll();
pieces_onboard[1].resetAll();
promoted.resetAll();
effects.effected_mask[0].resetAll();
effects.effected_mask[1].resetAll();
effects.effected_changed_mask[0].resetAll();
effects.effected_changed_mask[1].resetAll();
for(int num=0;num<40;num++){
Piece p=pieceOf(num);
if (p.isOnBoard()){
pieces_onboard[p.owner()].set(num);
if (p.isPromoted())
promoted.set(num);
for(int i=0;i<2;i++){
Player pl=indexToPlayer(i);
if(hasEffectAt(pl,p.square()))
{
effects.effected_mask[i].set(num);
effects.effected_changed_mask[i].set(num);
}
}
}
}
makePinOpen(BLACK);
makePinOpen(WHITE);
if(kingSquare<BLACK>().isOnBoard())
makeKing8Info<BLACK>();
if(kingSquare<WHITE>().isOnBoard())
makeKing8Info<WHITE>();
}
osl::
NumEffectState::~NumEffectState()
{
}
const osl::Piece osl::
NumEffectState::selectCheapPiece(PieceMask effect) const
{
if (! effect.any())
return Piece::EMPTY();
mask_t pieces = effect.selectBit<PAWN>(), ppieces;
if (pieces.any())
{
ppieces = pieces & promoted.getMask<PAWN>();
pieces &= ~ppieces;
if (pieces.any())
return pieceOf(pieces.bsf()+PtypeFuns<PAWN>::indexNum*32);
return pieceOf(ppieces.bsf()+PtypeFuns<PAWN>::indexNum*32);
}
pieces = effect.selectBit<LANCE>();
if (pieces.any())
{
ppieces = pieces & promoted.getMask<LANCE>();
pieces &= ~ppieces;
if (pieces.any())
return pieceOf(pieces.bsf()+PtypeFuns<LANCE>::indexNum*32);
return pieceOf(ppieces.bsf()+PtypeFuns<LANCE>::indexNum*32);
}
mask_t king = effect.selectBit<KING>();
effect.clearBit<KING>();
if (effect.none())
return pieceOf(king.bsf()+PtypeFuns<KING>::indexNum*32);
// depends on current piece numbers: <FU 0>, KE 18, GI 22, KI 26, <OU 30>, <KY 32>, KA 36, HI 38,
const int index = 0;
ppieces = effect.getMask(index) & promoted.getMask(index);
pieces = effect.getMask(index) & ~ppieces;
if (pieces.none() || ppieces.none())
return pieceOf(pieces.any() ? pieces.bsf() : ppieces.bsf());
const int num = pieces.bsf(), nump = ppieces.bsf();
if (Piece_Table.getPtypeOf(num) == Piece_Table.getPtypeOf(nump))
return pieceOf(num);
return pieceOf(std::min(num, nump));
}
const osl::Piece osl::
NumEffectState::findThreatenedPiece(Player P) const
{
assert(! inCheck(P));
PieceMask pieces = piecesOnBoard(P) & effectedMask(alt(P));
PieceMask nolance = pieces; nolance.clearBit<LANCE>();
int pp=-1, npp=-1, ret=-1;
const int lance_index = PtypeFuns<LANCE>::indexNum; // 64bit: 0, 32bit: 1
for (int i=lance_index; i>=0; --i) {
mask_t all = nolance.getMask(i);
mask_t promoted = all & promotedPieces().getMask(i);
mask_t notpromoted = all & ~promoted;
if (promoted.any()) {
pp = promoted.bsr() + i*32;
notpromoted &= ~Ptype_Table.getMaskLow(Piece_Table.getPtypeOf(pp));
}
if (notpromoted.any())
npp = notpromoted.bsr() + i*32;
ret = std::max(pp, npp);
if (ret >= PtypeTraits<KNIGHT>::indexMin)
return pieceOf(ret);
}
mask_t lance = pieces.selectBit<LANCE>();
if (lance.any()) {
mask_t plance = lance & promotedPieces().getMask(lance_index);
if (plance.any())
return pieceOf(plance.bsr()+lance_index*32);
return pieceOf(lance.bsr()+lance_index*32);
}
if (ret >= 0) {
assert(Piece_Table.getPtypeOf(ret) == PAWN);
return pieceOf(ret);
}
return Piece::EMPTY();
}
bool osl::
NumEffectState::wasCheckEvasion(Move last_move) const
{
if (! last_move.isNormal())
return false;
const Square from = last_move.from(), to = last_move.to();
if (last_move.ptype() == KING) {
if (last_move.isCapture()
&& hasEffectIf(last_move.capturePtypeO(), to, from))
return true;
return hasEffectAt(turn(), from);
}
if (last_move.isCapture())
return hasEffectIf(last_move.capturePtypeO(), to,
kingSquare(alt(turn())))
&& !Board_Table.isBetweenSafe(from, to,
kingSquare(alt(turn())));
const Piece piece = pieceOnBoard(to);
if (! pin(alt(turn())).test(piece.number()))
return false;
if (last_move.isDrop() || last_move.oldPtype() == KNIGHT)
return true;
const Direction d=pinnedDir(piece);
return primDir(d)
!=primDirUnsafe(Board_Table.getShort8Unsafe(piece.owner(), from,to));
}
void osl::NumEffectState::makeMove(Move move)
{
assert(turn() == move.player());
if (move.isPass()) {
makeMovePass();
return;
}
assert(isAlmostValidMove(move));
const Square from=move.from();
const Square to=move.to();
if (from.isPieceStand())
{
doDropMove(to,move.ptype());
}
else
{
const Piece captured = pieceOnBoard(to);
if (captured != Piece::EMPTY())
{
doCaptureMove(from,to,captured,move.promoteMask());
}
else
{
doSimpleMove(from,to,move.promoteMask());
}
}
changeTurn();
}
void osl::NumEffectState::
doSimpleMove(Square from, Square to, int promoteMask)
{
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;
mobility::MobilityTable mobilityTable;
if (turn()==BLACK){
prologueSimple(Player2Type<BLACK>(), 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,mobilityTable);
}
else{
prologueSimple(Player2Type<WHITE>(), 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,mobilityTable);
}
if (promoteMask!=0 && num < PtypeTraits<PAWN>::indexLimit)
clearPawn(turn(),from);
}
void osl::NumEffectState::
doCaptureMove(Square from, Square to, Piece target, int promoteMask)
{
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;
mobility::MobilityTable mobilityTable;
if(turn()==BLACK){
prologueCapture(Player2Type<BLACK>(), 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,mobilityTable);
}
else{
prologueCapture(Player2Type<WHITE>(), 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,mobilityTable);
}
const Ptype capturePtype=target.ptype();
if (capturePtype==PAWN)
clearPawn(alt(turn()),to);
if (promoteMask!=0 && num0<PtypeTraits<PAWN>::indexLimit)
clearPawn(turn(),from);
}
void osl::NumEffectState::
doDropMove(Square to,Ptype ptype)
{
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;
mobility::MobilityTable mobilityTable;
if(turn()==BLACK){
prologueDrop(Player2Type<BLACK>(), to, ptype, oldPiece, num, ptypeO, numIndex, numMask,
pin_or_open_backup, king_mobility_backup,
effected_mask_backup, effected_changed_mask_backup,king8infos_backup,mobilityTable);
}
else{
prologueDrop(Player2Type<WHITE>(), to, ptype, oldPiece, num, ptypeO, numIndex, numMask,
pin_or_open_backup, king_mobility_backup,
effected_mask_backup, effected_changed_mask_backup,king8infos_backup,mobilityTable);
}
if (ptype==PAWN)
setPawn(turn(),to);
}
template<osl::Player P>
void osl::NumEffectState::
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)
{
mobility_backup = effects.mobilityTable;
pin_or_open_backup = pin_or_open;
king_mobility_backup = king_mobility;
effected_mask_backup = effects.effected_mask;
effected_changed_mask_backup = effects.effected_changed_mask;
king8infos_backup=king8infos;
oldPiece=pieceAt(from);
Piece newPiece=oldPiece.promoteWithMask(promoteMask);
newPiece+=(to-from);
num=oldPiece.number();
oldPtypeO=oldPiece.ptypeO();
new_ptypeo=newPiece.ptypeO();
// 自分自身の効きを外す
setPieceOf(num,newPiece);
effects.clearChangedEffects();
effects.clearEffectedChanged();
effects.template doEffect<NumBitmapEffect::Sub,true>(*this,oldPtypeO,from,num);
// 自分自身がブロックしていたpromote?の延長
// あるいは自分自身のブロック
effects.effectedNumTable[num].clear();
setBoard(to,newPiece);
effects.template doBlockAt<NumBitmapEffect::Sub,true>(*this,to,num);
setBoard(from,Piece::EMPTY());
effects.template doBlockAt<NumBitmapEffect::Add,true>(*this,from,num);
effects.template doEffect<NumBitmapEffect::Add,true>(*this,new_ptypeo,to,num);
if (oldPtypeO == newPtypeO(P,KING))
makePinOpen(P);
else {
Direction lastD=UL;
pin_or_open[P].reset(num);
recalcPinOpen(from,lastD,P);
recalcPinOpen(to,lastD,P);
}
{
Direction lastD=UL;
pin_or_open[alt(P)].reset(num);
recalcPinOpen(from,lastD,alt(P));
recalcPinOpen(to,lastD,alt(P));
}
promoted_backup = promoted;
if (promoteMask)
promoted.set(num);
if(hasEffectAt(BLACK,to))
effects.effected_mask[BLACK].set(num);
else
effects.effected_mask[BLACK].reset(num);
if(hasEffectAt(WHITE,to))
effects.effected_mask[WHITE].set(num);
else
effects.effected_mask[WHITE].reset(num);
effects.effected_changed_mask[BLACK].set(num);
effects.effected_changed_mask[WHITE].set(num);
{
BoardMask changed=changedEffects(BLACK)|changedEffects(WHITE);
changed.set(from);
changed.set(to);
if(changed.anyInRange(Board_Mask_Table3x3.mask(kingSquare<BLACK>()))
|| pin_or_open[BLACK]!=pin_or_open_backup[BLACK])
makeKing8Info<BLACK>();
if(changed.anyInRange(Board_Mask_Table3x3.mask(kingSquare<WHITE>()))
|| pin_or_open[WHITE]!=pin_or_open_backup[WHITE])
makeKing8Info<WHITE>();
}
}
void osl::NumEffectState::
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)
{
setPieceOf(num,oldPiece);
effects.doEffect<NumBitmapEffect::Sub,false>(*this,newPtypeO,to,num);
setBoard(from,oldPiece);
effects.effectedNumTable[num].clear();
effects.doBlockAt<NumBitmapEffect::Sub,false>(*this,from,num);
setBoard(to,Piece::EMPTY());
effects.doBlockAt<NumBitmapEffect::Add,false>(*this,to,num);
effects.doEffect<NumBitmapEffect::Add,false>(*this,oldPtypeO,from,num);
effects.invalidateChangedEffects();
pin_or_open = pin_or_open_backup;
king_mobility = king_mobility_backup;
promoted = promoted_backup;
effects.effected_mask = effected_mask_backup;
effects.effected_changed_mask = effected_changed_mask_backup;
effects.mobilityTable = mobility_backup;
king8infos = king8infos_backup;
}
template<osl::Player P>
void osl::NumEffectState::
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)
{
king8infos_backup = king8infos;
mobility_backup = effects.mobilityTable;
pin_or_open_backup = pin_or_open;
king_mobility_backup = king_mobility;
effected_mask_backup = effects.effected_mask;
effected_changed_mask_backup = effects.effected_changed_mask;
#if OSL_WORDSIZE == 64
numIndex=0;
#elif OSL_WORDSIZE == 32
numIndex=Ptype_Table.getIndex(ptype);
#endif
const mask_t ownMochigoma=
standMask(P).getMask(numIndex) & Ptype_Table.getMaskLow(ptype);
assert(ownMochigoma.any());
numMask=ownMochigoma.lowestBit();
int numLow = ownMochigoma.bsf();
num = numLow|(numIndex<<5);
oldPiece=pieceOf(num);
Piece newPiece=oldPiece;
newPiece+=to-Square::STAND();
ptypeO=newPiece.ptypeO();
setPieceOf(num,newPiece);
effects.clearChangedEffects();
effects.clearEffectedChanged();
effects.template doBlockAt<NumBitmapEffect::Sub,true>(*this,to,num);
effects.template doEffect<NumBitmapEffect::Add,true>(*this,ptypeO,to,num);
setBoard(to,newPiece);
standMask(P).xorMask(numIndex,numMask);
stand_count[P][ptype-PTYPE_BASIC_MIN]--;
pieces_onboard[P].xorMask(numIndex,numMask);
{
Direction lastD=UL;
recalcPinOpen(to,lastD,P);
}
{
Direction lastD=UL;
recalcPinOpen(to,lastD,alt(P));
}
if(hasEffectAt(BLACK,to))
effects.effected_mask[BLACK].set(num);
else
effects.effected_mask[BLACK].reset(num);
if (hasEffectAt(WHITE,to))
effects.effected_mask[WHITE].set(num);
else
effects.effected_mask[WHITE].reset(num);
effects.effected_changed_mask[BLACK].set(num);
effects.effected_changed_mask[WHITE].set(num);
{
BoardMask changed=changedEffects(BLACK)|changedEffects(WHITE);
changed.set(to);
if(changed.anyInRange(Board_Mask_Table3x3.mask(kingSquare<BLACK>()))
|| pin_or_open[BLACK]!=pin_or_open_backup[BLACK])
makeKing8Info<BLACK>();
if(changed.anyInRange(Board_Mask_Table3x3.mask(kingSquare<WHITE>()))
|| pin_or_open[WHITE]!=pin_or_open_backup[WHITE])
makeKing8Info<WHITE>();
}
}
template<osl::Player P>
void osl::NumEffectState::
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)
{
standMask(P).xorMask(numIndex,numMask);
stand_count[P][ptype-PTYPE_BASIC_MIN]++;
pieces_onboard[P].xorMask(numIndex,numMask);
setBoard(to,Piece::EMPTY());
effects.template doEffect<NumBitmapEffect::Sub,false>(*this,ptypeO,to,num);
effects.template doBlockAt<NumBitmapEffect::Add,false>(*this,to,num);
setPieceOf(num,oldPiece);
effects.effectedNumTable[num].clear();
effects.invalidateChangedEffects();
pin_or_open = pin_or_open_backup;
king_mobility = king_mobility_backup;
effects.effected_mask = effected_mask_backup;
effects.effected_changed_mask = effected_changed_mask_backup;
effects.mobilityTable = mobility_backup;
king8infos = king8infos_backup;
}
template<osl::Player P>
void osl::NumEffectState::
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)
{
mobility_backup = effects.mobilityTable;
pin_or_open_backup = pin_or_open;
king_mobility_backup = king_mobility;
effected_mask_backup = effects.effected_mask;
effected_changed_mask_backup = effects.effected_changed_mask;
king8infos_backup = king8infos;
num1=target.number();
num1Index=PieceMask::numToIndex(num1);
num1Mask=PieceMask::numToMask(num1);
pieces_onboard[alt(P)].xorMask(num1Index,num1Mask);
standMask(P).xorMask(num1Index,num1Mask);
oldPiece=pieceAt(from);
Piece newPiece=oldPiece.promoteWithMask(promoteMask);
newPiece+=(to-from);
num0=oldPiece.number();
setPieceOf(num0,newPiece);
setPieceOf(num1,target.captured());
oldPtypeO=oldPiece.ptypeO();
new_ptypeo=newPiece.ptypeO();
capturePtypeO=target.ptypeO();
stand_count[P][unpromote(getPtype(capturePtypeO))-PTYPE_BASIC_MIN]++;
effects.clearChangedEffects();
effects.clearEffectedChanged();
effects.setChangedPieces(effectSetAt(to));
effects.template doEffect<NumBitmapEffect::Sub,true>(*this,capturePtypeO,to,num1);
effects.template doEffect<NumBitmapEffect::Sub,true>(*this,oldPtypeO,from,num0);
setBoard(from,Piece::EMPTY());
effects.template doBlockAt<NumBitmapEffect::Add,true>(*this,from,num0);
effects.effectedNumTable[num0]=effects.effectedNumTable[num1];
effects.effectedNumTable[num1].clear();
setBoard(to,newPiece);
effects.template doEffect<NumBitmapEffect::Add,true>(*this,new_ptypeo,to,num0);
if (oldPtypeO == newPtypeO(P,KING))
makePinOpen(P);
else {
Direction lastD=UL;
pin_or_open[P].reset(num0);
pin_or_open[P].reset(num1); // captured is not pin
recalcPinOpen(from,lastD,P);
recalcPinOpen(to,lastD,P);
}
{
Direction lastD=UL;
pin_or_open[alt(P)].reset(num0);
pin_or_open[alt(P)].reset(num1); // captured is not pin
recalcPinOpen(from,lastD,alt(P));
recalcPinOpen(to,lastD,alt(P));
}
promoted_backup = promoted;
promoted.reset(num1);
effects.effected_mask[BLACK].reset(num1);
effects.effected_mask[WHITE].reset(num1);
if (promoteMask)
promoted.set(num0);
if(hasEffectAt(BLACK,to))
effects.effected_mask[BLACK].set(num0);
else
effects.effected_mask[BLACK].reset(num0);
if(hasEffectAt(WHITE,to))
effects.effected_mask[WHITE].set(num0);
else
effects.effected_mask[WHITE].reset(num0);
effects.effected_changed_mask[BLACK].set(num0);
effects.effected_changed_mask[WHITE].set(num0);
{
BoardMask changed=changedEffects(BLACK)|changedEffects(WHITE);
changed.set(from);
changed.set(to);
if(changed.anyInRange(Board_Mask_Table3x3.mask(kingSquare<BLACK>()))
|| pin_or_open[BLACK]!=pin_or_open_backup[BLACK])
makeKing8Info<BLACK>();
if(changed.anyInRange(Board_Mask_Table3x3.mask(kingSquare<WHITE>()))
|| pin_or_open[WHITE]!=pin_or_open_backup[WHITE])
makeKing8Info<WHITE>();
}
}
template<osl::Player P>
void osl::NumEffectState::
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)
{
standMask(P).xorMask(num1Index,num1Mask);
stand_count[P][unpromote(getPtype(capturePtypeO))-PTYPE_BASIC_MIN]--;
pieces_onboard[alt(P)].xorMask(num1Index,num1Mask);
effects.effectedNumTable[num1]=effects.effectedNumTable[num0];
effects.effectedNumTable[num0].clear();
setPieceOf(num0,oldPiece);
setPieceOf(num1,target);
effects.template doEffect<NumBitmapEffect::Sub,false>(*this,newPtypeO,to,num0);
setBoard(from,oldPiece);
setBoard(to,target);
effects.template doBlockAt<NumBitmapEffect::Sub,false>(*this,from,num0);
effects.template doEffect<NumBitmapEffect::Add,false>(*this,capturePtypeO,to,num1);
effects.template doEffect<NumBitmapEffect::Add,false>(*this,oldPtypeO,from,num0);
effects.invalidateChangedEffects();
pin_or_open = pin_or_open_backup;
king_mobility = king_mobility_backup;
promoted = promoted_backup;
effects.effected_mask = effected_mask_backup;
effects.effected_changed_mask = effected_changed_mask_backup;
effects.mobilityTable = mobility_backup;
king8infos = king8infos_backup;
}
#ifndef MINIMAL
bool osl::NumEffectState::isConsistent(bool showError) const
{
if (!SimpleState::isConsistent(showError))
{
if (showError)
std::cerr << "error before effect\n";
return false;
}
effect::NumSimpleEffectTable effects1(*this);
if (!(effects1==effects))
{
if (showError)
{
std::cerr << "Effect error 1" << std::endl;
std::cerr << *this;
for(int y=1;y<=9;y++)
for(int x=9;x>0;x--)
{
Square pos(x,y);
if (!(effects1.effectSetAt(pos)==effects.effectSetAt(pos)))
{
std::cerr << pos << ",real=" << effects.effectSetAt(pos) << ",ideal=" << effects1.effectSetAt(pos) << std::endl;
}
}
for(int num=0;num<=39;num++){
for(int i=0;i<8;i++){
Direction d=static_cast<Direction>(i);
if(effects.effectedNumTable[num][d]!=effects1.effectedNumTable[num][d]){
std::cerr << "piece=" << pieceOf(num) << ",num=" << num << ",d=" << d << ",v1=" << effects.effectedNumTable[num][d] << ",v2=" << effects1.effectedNumTable[num][d] << std::endl;
}
}
}
std::cerr << effects.effectedNumTable << std::endl;
}
return false;
}
for (int z=0; z<2; ++z) {
const Player p = indexToPlayer(z);
#ifdef ALLOW_KING_ABSENCE
if (kingSquare(p).isPieceStand())
continue;
#endif
#if 0
const PieceMask pin2 = effect_util::Pin::make(*this, p);
if (pin(p) != pin2) {
if (showError)
std::cerr << "pin for " << p << " differs " << pin(p) << " " << pin2 << "\n";
return false;
}
#endif
King8Info king8info2 = King8Info::make(alt(p), *this);
if (King8Info(Iking8Info(p)).uint64Value() != king8info2.uint64Value()) {
if (showError)
std::cerr << "king8info for " << p << " differs \n" << King8Info(Iking8Info(p)) << "\n" << king8info2 << "\n";
return false;
}
}
for (int i=0; i<Piece::SIZE; ++i) {
const Piece p = pieceOf(i);
if (p.isOnBoard()) {
if (promoted.test(i) != p.isPromoted()) {
if (showError)
std::cerr << "promoted differs " << p << " " << promoted << " " << promoted.test(i) << "\n";
return false;
}
}
}
return true;
}
#endif
bool osl::NumEffectState::isConsistent(const NumEffectState& prev, Move moved, bool show_error) const
{
// test changedEffects
const CArray<BoardMask,2> changed_squares
= {{ changedEffects(BLACK), changedEffects(WHITE) }};
const BoardMask changed_all = changed_squares[BLACK] | changed_squares[WHITE];
CArray<BoardMask, Piece::SIZE> each_effect, prev_effect;
for (int i=0; i<Piece::SIZE; ++i) {
each_effect[i].clear();
prev_effect[i].clear();
}
for (int x=1; x<=9; ++x) {
for (int y=1; y<=9; ++y) {
const Square sq(x, y);
for (int i=0; i<Piece::SIZE; ++i) {
if (effectSetAt(sq).test(i))
each_effect[i].set(sq);
if (prev.effectSetAt(sq).test(i))
prev_effect[i].set(sq);
}
if (! changed_all.test(sq))
{
if (effectSetAt(sq) != prev.effectSetAt(sq)) {
#ifndef MINIMAL
if (show_error)
std::cerr << "changedEffects unset\n" << *this << moved << sq << "\n";
#endif
return false;
}
}
for (int i=0; i<2; ++i)
{
const Player pl = indexToPlayer(i);
if (! changed_squares[pl].test(sq))
{
if ((effectSetAt(sq) & piecesOnBoard(pl))
!= (prev.effectSetAt(sq) & prev.piecesOnBoard(pl))) {
#ifndef MINIMAL
if (show_error)
std::cerr << "changedEffects unset for " << pl << "\n" << *this << moved << sq << "\n";
#endif
return false;
}
}
}
}
}
// test changedPieces()
const NumBitmapEffect changed_effect_pieces = changedPieces();
for (int i=0; i<Piece::SIZE; ++i) {
if (each_effect[i] == prev_effect[i])
continue;
if (! changed_effect_pieces.test(i)) {
#ifndef MINIMAL
if (show_error)
std::cerr << "changedPieces() unset\n" << *this << moved << i
<< " " << each_effect[i] << " != " << prev_effect[i] << "\n";
#endif
return false;
}
}
// test effectedChanged(Player pl)
for (int i=0; i<Piece::SIZE; ++i)
{
for (int j=0; j<2; ++j)
{
const Player pl = indexToPlayer(j);
if (prev.pieceOf(i).square() == moved.to())
continue; // captured
if (prev.effectedMask(pl).test(i) != effectedMask(pl).test(i)) {
if (! effectedChanged(pl).test(i)) {
#ifndef MINIMAL
if (show_error)
std::cerr << "effectedChanged(" << pl << ") unset\n" << *this << moved << i
<< " " << prev.effectedChanged(pl) << " != " << prev.effectedChanged(WHITE) << "\n";
#endif
return false;
}
}
}
}
return true;
}
template <bool show_error>
bool
#if (defined __GNUC__) && (! defined GPSONE) && (! defined GPSUSIONE)
__attribute__ ((used,noinline))
#endif
osl::NumEffectState::isAlmostValidMove(Move move) const{
assert(move.isValid());
assert(move.isNormal());
assert(this->turn() == move.player());
assert(isValidMoveByRule(move, true));
const Square from=move.from();
if (from.isPieceStand()) // 打つ手
return isAlmostValidDrop<show_error>(move);
const Square to=move.to();
const Piece from_piece = this->pieceAt(from);
if (! testValidityOtherThanEffect<show_error>(move))
return false;
if(!hasEffectByPiece(from_piece,to)){
if (show_error) {
std::cerr << " No such move2 : " << move << std::endl;
}
return false;
}
return true;
}
bool osl::NumEffectState::
isAlmostValidMove(Move move,bool show_error) const{
#ifdef MINIMAL
show_error=false;
#endif
if(show_error)
return isAlmostValidMove<true>(move);
else
return isAlmostValidMove<false>(move);
}
#ifndef MINIMAL
void osl::NumEffectState::showEffect(std::ostream& os) const
{
os<< static_cast<SimpleState const&>(*this);
for(int y=1;y<=9;y++){
os << 'P' << y;
for(int x=9;x>0;x--){
Square pos(x,y);
os << csa::show(pieceAt(pos)) << effectSetAt(pos);
}
os << std::endl;
}
// 持ち駒の表示
for(int num=0;num<Piece::SIZE;num++){
if (standMask(BLACK).test(num)){
os << "P+00" << csa::show(Piece_Table.getPtypeOf(num))
<< std::endl;
}
else if (standMask(WHITE).test(num)){
os << "P-00" << csa::show(Piece_Table.getPtypeOf(num))
<< std::endl;
}
}
}
#endif
osl::PieceMask osl::NumEffectState::
makePinOpen(osl::Square target,osl::Player defense)
{
PieceMask pins;
if(target.isPieceStand()) return pins;
PieceMask mask=piecesOnBoard(alt(defense));
makePinOpenDir<UL>(target,pins,mask,defense);
makePinOpenDir<U>(target,pins,mask,defense);
makePinOpenDir<UR>(target,pins,mask,defense);
makePinOpenDir<L>(target,pins,mask,defense);
makePinOpenDir<R>(target,pins,mask,defense);
makePinOpenDir<DL>(target,pins,mask,defense);
makePinOpenDir<D>(target,pins,mask,defense);
makePinOpenDir<DR>(target,pins,mask,defense);
return pins;
}
void osl::NumEffectState::
makePinOpen(osl::Player defense)
{
pin_or_open[defense]=makePinOpen(kingSquare(defense),defense);
}
const osl::mask_t osl::NumEffectState::
allEffectAt(Player attack, Ptype ptype, Square target) const
{
switch (ptype) {
case PAWN: case PPAWN:
return allEffectAt<PAWN>(attack, target);
case LANCE: case PLANCE:
return allEffectAt<LANCE>(attack, target);
case KNIGHT: case PKNIGHT:
return allEffectAt<KNIGHT>(attack, target);
case SILVER: case PSILVER:
return allEffectAt<SILVER>(attack, target);
case GOLD:
return allEffectAt<GOLD>(attack, target);
case BISHOP: case PBISHOP:
return allEffectAt<BISHOP>(attack, target);
case ROOK: case PROOK:
return allEffectAt<ROOK>(attack, target);
case KING:
return allEffectAt<KING>(attack, target);
default:
assert(0);
}
return mask_t();
}
void osl::NumEffectState::copyFrom(const NumEffectState& src)
{
#ifndef MINIMAL
(*this).used_mask=src.used_mask;
#endif
(*this).stand_mask=src.stand_mask;
#if (defined(__i386__) || defined(__x86_64__)) && !defined(OSL_NO_SSE)
{
v2di b16=*((v2di*)&src.board[16]);
v2di b20=*((v2di*)&src.board[20]);
v2di b24=*((v2di*)&src.board[24]);
v2di b32=*((v2di*)&src.board[32]);
v2di b36=*((v2di*)&src.board[36]);
v2di b40=*((v2di*)&src.board[40]);
v2di b48=*((v2di*)&src.board[48]);
v2di b52=*((v2di*)&src.board[52]);
v2di b56=*((v2di*)&src.board[56]);
*((v2di*)&(*this).board[16])=b16;
*((v2di*)&(*this).board[20])=b20;
*((v2di*)&(*this).board[24])=b24;
*((v2di*)&(*this).board[32])=b32;
*((v2di*)&(*this).board[36])=b36;
*((v2di*)&(*this).board[40])=b40;
*((v2di*)&(*this).board[48])=b48;
*((v2di*)&(*this).board[52])=b52;
*((v2di*)&(*this).board[56])=b56;
v2di b64=*((v2di*)&src.board[64]);
v2di b68=*((v2di*)&src.board[68]);
v2di b72=*((v2di*)&src.board[72]);
v2di b80=*((v2di*)&src.board[80]);
v2di b84=*((v2di*)&src.board[84]);
v2di b88=*((v2di*)&src.board[88]);
v2di b96=*((v2di*)&src.board[96]);
v2di b100=*((v2di*)&src.board[100]);
v2di b104=*((v2di*)&src.board[104]);
*((v2di*)&(*this).board[64])=b64;
*((v2di*)&(*this).board[68])=b68;
*((v2di*)&(*this).board[72])=b72;
*((v2di*)&(*this).board[80])=b80;
*((v2di*)&(*this).board[84])=b84;
*((v2di*)&(*this).board[88])=b88;
*((v2di*)&(*this).board[96])=b96;
*((v2di*)&(*this).board[100])=b100;
*((v2di*)&(*this).board[104])=b104;
v2di b112=*((v2di*)&src.board[112]);
v2di b116=*((v2di*)&src.board[116]);
v2di b120=*((v2di*)&src.board[120]);
v2di b128=*((v2di*)&src.board[128]);
v2di b132=*((v2di*)&src.board[132]);
v2di b136=*((v2di*)&src.board[136]);
v2di b144=*((v2di*)&src.board[144]);
v2di b148=*((v2di*)&src.board[148]);
v2di b152=*((v2di*)&src.board[152]);
*((v2di*)&(*this).board[112])=b112;
*((v2di*)&(*this).board[116])=b116;
*((v2di*)&(*this).board[120])=b120;
*((v2di*)&(*this).board[128])=b128;
*((v2di*)&(*this).board[132])=b132;
*((v2di*)&(*this).board[136])=b136;
*((v2di*)&(*this).board[144])=b144;
*((v2di*)&(*this).board[148])=b148;
*((v2di*)&(*this).board[152])=b152;
v2di p0=*((v2di*)&src.pieces[0]);
v2di p4=*((v2di*)&src.pieces[4]);
v2di p8=*((v2di*)&src.pieces[8]);
v2di p12=*((v2di*)&src.pieces[12]);
v2di p16=*((v2di*)&src.pieces[16]);
v2di p20=*((v2di*)&src.pieces[20]);
v2di p24=*((v2di*)&src.pieces[24]);
v2di p28=*((v2di*)&src.pieces[28]);
v2di p32=*((v2di*)&src.pieces[32]);
v2di p36=*((v2di*)&src.pieces[36]);
*((v2di*)&(*this).pieces[0])=p0;
*((v2di*)&(*this).pieces[4])=p4;
*((v2di*)&(*this).pieces[8])=p8;
*((v2di*)&(*this).pieces[12])=p12;
*((v2di*)&(*this).pieces[16])=p16;
*((v2di*)&(*this).pieces[20])=p20;
*((v2di*)&(*this).pieces[24])=p24;
*((v2di*)&(*this).pieces[28])=p28;
*((v2di*)&(*this).pieces[32])=p32;
*((v2di*)&(*this).pieces[36])=p36;
}
#else
for(int x=1;x<=9;x++)
for(int y=1;y<=9;y++)
(*this).board[Square(x,y).index()]=src.board[Square(x,y).index()];
(*this).pieces=src.pieces;
#endif
(*this).pawnMask=src.pawnMask;
this->stand_count = src.stand_count;
this->player_to_move=src.player_to_move;
effects.copyFrom(src.effects);
this->pieces_onboard=src.pieces_onboard;
(*this).promoted=src.promoted;
(*this).pin_or_open=src.pin_or_open;
(*this).king_mobility=src.king_mobility;
(*this).king8infos=src.king8infos;
}
void osl::NumEffectState::copyFrom(const SimpleState& src)
{
copyFrom(NumEffectState(src));
}
bool osl::NumEffectState::isSafeMove(Move move) const
{
using namespace move_classifier;
return ConditionAdaptor<SafeMove>::isMember(*this, move);
}
bool osl::NumEffectState::isCheck(Move move) const
{
using namespace move_classifier;
return PlayerMoveAdaptor<Check>::isMember(*this, move);
}
bool osl::NumEffectState::isPawnDropCheckmate(Move move) const
{
using namespace move_classifier;
return PlayerMoveAdaptor<PawnDropCheckmate>::isMember(*this, move);
}
bool osl::NumEffectState::isDirectCheck(Move move) const
{
using namespace move_classifier;
return PlayerMoveAdaptor<DirectCheck>::isMember(*this, move);
}
bool osl::NumEffectState::isOpenCheck(Move move) const
{
using namespace move_classifier;
return ConditionAdaptor<OpenCheck>::isMember(*this, move);
}
#ifndef MINIMAL
void osl::NumEffectState::generateAllUnsafe(MoveVector& out) const
{
move_action::Store store(out);
move_generator::AllMoves<move_action::Store>::generate(turn(), *this, store);
}
void osl::NumEffectState::generateLegal(MoveVector& moves) const
{
if (inCheck()) {
// 王手がかかっている時は防ぐ手のみを生成, 王手回避は不成も生成
GenerateEscapeKing::generate(*this, moves);
}
else {
// そうでなければ全ての手を生成
MoveVector all_moves;
GenerateAllMoves::generate(turn(), *this, all_moves);
// この指手は，玉の素抜きがあったり，打歩詰の可能性があるので
// 確認が必要
std::copy_if(all_moves.begin(), all_moves.end(), std::back_inserter(moves),
[&](Move m){
return this->isSafeMove(m) && ! this->isPawnDropCheckmate(m);
});
}
}
void osl::NumEffectState::generateWithFullUnpromotions(MoveVector& moves) const
{
generateLegal(moves);
if (inCheck())
return;
for (int i=0, iend=moves.size(); i<iend; ++i) {
const Move move = moves[i];
if (move.hasIgnoredUnpromote())
moves.push_back(move.unpromote());
}
}
#endif
void osl::NumEffectState::
findEffect(Player P, Square target, PieceVector& out) const
{
effect_action::StorePiece store(&out);
forEachEffect(P, target, store);
}
namespace osl
{
// explicit template instantiation
template bool NumEffectState::
hasEffectByWithRemove<BLACK>(Square, Square) const;
template bool NumEffectState::
hasEffectByWithRemove<WHITE>(Square, Square) const;
template void NumEffectState::makeKing8Info<BLACK>();
template void NumEffectState::makeKing8Info<WHITE>();
template void NumEffectState::
prologueSimple(Player2Type<BLACK>, Square, Square, int, Piece&, int&,
PtypeO&, PtypeO&, CArray<PieceMask,2>&, KingMobility&,
PieceMask&, CArray<PieceMask,2>&, CArray<PieceMask,2>&,
CArray<uint64_t,2>&, MobilityTable&);
template void NumEffectState::
prologueSimple(Player2Type<WHITE>, Square, Square, int, Piece&, int&,
PtypeO&, PtypeO&, CArray<PieceMask,2>&, KingMobility&,
PieceMask&, CArray<PieceMask,2>&, CArray<PieceMask,2>&,
CArray<uint64_t,2>&, MobilityTable&);
template void NumEffectState::
prologueCapture(Player2Type<BLACK>, Square, Square, Piece, int, Piece&,
PtypeO&, PtypeO&, PtypeO&, int&, int&, int&, mask_t&,
CArray<PieceMask,2>&, KingMobility&, PieceMask&,
CArray<PieceMask,2>&, CArray<PieceMask,2>&,
CArray<uint64_t,2>&, MobilityTable&);
template void NumEffectState::
prologueCapture(Player2Type<WHITE>, Square, Square, Piece, int, Piece&,
PtypeO&, PtypeO&, PtypeO&, int&, int&, int&, mask_t&,
CArray<PieceMask,2>&, KingMobility&, PieceMask&,
CArray<PieceMask,2>&, CArray<PieceMask,2>&,
CArray<uint64_t,2>&, MobilityTable&);
template void NumEffectState::
prologueDrop(Player2Type<BLACK>, Square, Ptype, Piece&, int&, PtypeO&,
int&, mask_t&, CArray<PieceMask,2>&, KingMobility&,
CArray<PieceMask,2>&, CArray<PieceMask,2>&,
CArray<uint64_t,2>&, MobilityTable&);
template void NumEffectState::
prologueDrop(Player2Type<WHITE>, Square, Ptype, Piece&, int&, PtypeO&,
int&, mask_t&, CArray<PieceMask,2>&, KingMobility&,
CArray<PieceMask,2>&, CArray<PieceMask,2>&,
CArray<uint64_t,2>&, MobilityTable&);
template void NumEffectState::
epilogueCapture(Player2Type<BLACK>, Square, Square, Piece, Piece, PtypeO, PtypeO,
PtypeO, int, int, int, mask_t, const CArray<PieceMask,2>&,
const KingMobility&, const PieceMask&, const CArray<PieceMask,2>&,
const CArray<PieceMask,2>&, const CArray<uint64_t,2>&,
const MobilityTable&);
template void NumEffectState::
epilogueCapture(Player2Type<WHITE>, Square, Square, Piece, Piece, PtypeO, PtypeO,
PtypeO, int, int, int, mask_t, const CArray<PieceMask,2>&,
const KingMobility&, const PieceMask&, const CArray<PieceMask,2>&,
const CArray<PieceMask,2>&, const CArray<uint64_t,2>&,
const MobilityTable&);
template void NumEffectState::
epilogueDrop(Player2Type<BLACK>, Square, Ptype, Piece, int, PtypeO, int, mask_t,
const CArray<PieceMask,2>&, const KingMobility&, const CArray<PieceMask,2>&,
const CArray<PieceMask,2>&, const CArray<uint64_t,2>&, const MobilityTable&);
template void NumEffectState::
epilogueDrop(Player2Type<WHITE>, Square, Ptype, Piece, int, PtypeO, int, mask_t,
const CArray<PieceMask,2>&, const KingMobility&, const CArray<PieceMask,2>&,
const CArray<PieceMask,2>&, const CArray<uint64_t,2>&, const MobilityTable&);
#ifndef DFPNSTATONE
template Piece
NumEffectState::safeCaptureNotByKing<BLACK>(Square, Piece) const;
template Piece
NumEffectState::safeCaptureNotByKing<WHITE>(Square, Piece) const;
#endif
}
/* ------------------------------------------------------------------------- */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
allMoves.h
check_.h
osl::CArray
Definition container.h:20
osl::FixedCapacityVector::size
size_t size() const
Definition container.h:243
osl::FixedCapacityVector::end
iterator end()
Definition container.h:199
osl::FixedCapacityVector::push_back
void push_back(const T &e)
Definition container.h:204
osl::FixedCapacityVector::begin
iterator begin()
Definition container.h:198
osl::King8Info::make
static const King8Info make(NumEffectState const &state, Square king, PieceMask pinned)
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::isDrop
bool isDrop() const
Definition basic_type.h:1150
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::capturePtypeO
PtypeO capturePtypeO() const
Definition basic_type.h:1185
osl::Move::isNormal
bool isNormal() const
INVALID でも PASS でもない.
Definition basic_type.h:1088
osl::Move::promoteMask
int promoteMask() const
pieceに使うためのmaskなので
Definition basic_type.h:1143
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::to
const Square to() const
Definition basic_type.h:1132
osl::Move::from
const Square from() const
Definition basic_type.h:1125
osl::NumBitmapEffect::Add
@ Add
Definition numBitmapEffect.h:96
osl::NumBitmapEffect::Sub
@ Sub
Definition numBitmapEffect.h:96
osl::NumEffectState
利きを持つ局面
Definition numEffectState.h:34
osl::NumEffectState::pinnedDir
Direction pinnedDir(Piece p) const
pinされた駒がPのKingから見てどの方向か?
Definition numEffectState.h:203
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::hasEffectByWithRemove
bool hasEffectByWithRemove(Square target, Square removed) const
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::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::isOpenCheck
bool isOpenCheck(Move move) const
Definition numEffectState.cc:1074
osl::NumEffectState::changedEffects
const BoardMask changedEffects(Player pl) const
Definition numEffectState.h:144
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::isPawnDropCheckmate
bool isPawnDropCheckmate(Move move) const
Definition numEffectState.cc:1063
osl::NumEffectState::effectedMask
const PieceMask effectedMask(Player pl) const
pl からの利きが(1つ以上)ある駒一覧
Definition numEffectState.h:130
osl::NumEffectState::doSimpleMove
void doSimpleMove(Square from, Square to, int promoteMask)
Definition numEffectState.cc:232
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::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::wasCheckEvasion
bool wasCheckEvasion(Move last_move) const
Definition numEffectState.cc:175
osl::NumEffectState::makeMove
void makeMove(Move move)
Definition numEffectState.cc:201
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::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::pin
const PieceMask pin(Player king) const
Definition numEffectState.h:65
osl::NumEffectState::makeMovePass
void makeMovePass()
Definition numEffectState.h:668
osl::NumEffectState::NumEffectState
NumEffectState(const SimpleState &st=SimpleState(HIRATE))
Definition numEffectState.cc:61
osl::NumEffectState::changedPieces
const NumBitmapEffect changedPieces() const
Definition numEffectState.h:152
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::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::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::inCheck
bool inCheck(Player P) const
Pの玉が王手状態
Definition numEffectState.h:88
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::king_mobility
KingMobility king_mobility
Definition numEffectState.h:40
osl::NumEffectState::makeKing8Info
void makeKing8Info()
Definition numEffectState.cc:50
osl::NumEffectState::showEffect
void showEffect(std::ostream &os) const
Definition numEffectState.cc:858
osl::NumEffectState::~NumEffectState
~NumEffectState()
Definition numEffectState.cc:95
osl::NumEffectState::king8infos
CArray< uint64_t, 2 > king8infos
Definition numEffectState.h:41
osl::NumEffectState::pin_or_open
CArray< PieceMask, 2 > pin_or_open
Definition numEffectState.h:39
osl::NumEffectState::isSafeMove
bool isSafeMove(Move move) const
Definition numEffectState.cc:1053
osl::NumEffectState::piecesOnBoard
const PieceMask & piecesOnBoard(Player p) const
Definition numEffectState.h:63
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::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::allEffectAt
const mask_t allEffectAt(Player P, Square target) const
Definition numEffectState.h:293
osl::NumEffectState::generateWithFullUnpromotions
void generateWithFullUnpromotions(MoveVector &) const
打歩詰め絡み以外では有利にはならない手も含め, 全ての合法手を生成す る（Move::ignoredUnpromoteも生成する）.
Definition numEffectState.cc:1105
osl::PieceMask
駒番号のビットセット.
Definition pieceMask.h:21
osl::PieceMask::getMask
const mask_t getMask(int num) const
Definition pieceMask.h:59
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::numToMask
static const mask_t numToMask(int num)
Definition pieceMask.h:25
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::isPromoted
bool isPromoted() const
promoteした駒かどうかをチェックする
Definition basic_type.h:898
osl::Piece::square
const Square square() const
Definition basic_type.h:832
osl::Piece::owner
Player owner() const
Definition basic_type.h:963
osl::Piece::promoteWithMask
const Piece promoteWithMask(int promote_mask) const
Definition basic_type.h:885
osl::Piece::number
int number() const
Definition basic_type.h:828
osl::Piece::EMPTY
static const Piece EMPTY()
Definition basic_type.h:797
osl::Piece::captured
const Piece captured() const
取られたpieceを作成.
Definition basic_type.h:879
osl::Piece::isOnBoard
bool isOnBoard() const
Definition basic_type.h:985
osl::Piece::SIZE
static const int SIZE
Definition basic_type.h:794
osl::SimpleState
Definition simpleState.h:35
osl::SimpleState::pawnMask
CArray< BitXmask, 2 > pawnMask
Definition simpleState.h:57
osl::SimpleState::pieceOnBoard
const Piece pieceOnBoard(Square sq) const
Definition simpleState.h:170
osl::SimpleState::isAlmostValidDrop
bool isAlmostValidDrop(Move move) const
osl::SimpleState::board
CArray< Piece, Square::SIZE > board
Definition simpleState.h:47
osl::SimpleState::player_to_move
Player player_to_move
手番
Definition simpleState.h:61
osl::SimpleState::isValidMoveByRule
static bool isValidMoveByRule(Move move, bool show_error)
盤面以外の部分の反則のチェック
Definition simpleState.cc:372
osl::SimpleState::stand_count
CArray< CArray< char, PTYPE_SIZE-PTYPE_BASIC_MIN >, 2 > stand_count
Definition simpleState.h:58
osl::SimpleState::used_mask
PieceMask used_mask
Definition simpleState.h:62
osl::SimpleState::setPieceOf
void setPieceOf(int num, Piece p)
Definition simpleState.h:79
osl::SimpleState::clearPawn
void clearPawn(Player pl, Square sq)
(internal)
Definition simpleState.h:138
osl::SimpleState::SimpleState
SimpleState()
Definition simpleState.cc:12
osl::SimpleState::standMask
PieceMask & standMask(Player p)
Definition simpleState.h:124
osl::SimpleState::isOnBoard
bool isOnBoard(int num) const
Definition simpleState.h:176
osl::SimpleState::turn
Player turn() const
Definition simpleState.h:220
osl::SimpleState::changeTurn
void changeTurn()
手番を変更する
Definition simpleState.h:226
osl::SimpleState::stand_mask
CArray< PieceMask, 2 > stand_mask
Definition simpleState.h:56
osl::SimpleState::setBoard
void setBoard(Square sq, Piece piece)
Definition simpleState.h:119
osl::SimpleState::pieces
CArray< Piece, Piece::SIZE > pieces
全てのpieceが登録されている
Definition simpleState.h:55
osl::SimpleState::testValidityOtherThanEffect
bool testValidityOtherThanEffect(Move move) const
osl::SimpleState::pieceOf
const Piece pieceOf(int num) const
Definition simpleState.h:76
osl::SimpleState::isConsistent
bool isConsistent(bool show_error=true) const
Definition simpleState.cc:157
osl::SimpleState::setPawn
void setPawn(Player pl, Square sq)
(internal)
Definition simpleState.h:142
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::index
unsigned int index() const
Definition basic_type.h:572
osl::Square::isPieceStand
bool isPieceStand() const
Definition basic_type.h:576
osl::Square::STAND
static const Square STAND()
Definition basic_type.h:548
osl::checkmate::King8Info
敵玉の8近傍の状態を表す.
Definition king8Info.h:29
osl::checkmate::King8Info::uint64Value
uint64_t uint64Value() const
Definition king8Info.h:46
osl::container::BoardMask
11 x 12
Definition boardMask.h:21
osl::container::BoardMask::set
void set(unsigned int i)
Definition boardMask.h:40
osl::container::BoardMask::test
bool test(unsigned int i) const
Definition boardMask.h:52
osl::container::BoardMask::anyInRange
bool anyInRange(const BoardMask &mask) const
Definition boardMask.h:57
osl::container::PieceMask64::numToIndex
static int numToIndex(int)
Definition pieceMask64.h:16
osl::effect::NumBitmapEffect
現在の定義 (2005/3/4以降)
Definition numBitmapEffect.h:29
osl::effect::NumSimpleEffectTable
局面全体の利きデータ.
Definition numSimpleEffect.h:27
osl::effect::NumSimpleEffectTable::effectedNumTable
EffectedNumTable effectedNumTable
effected num
Definition numSimpleEffect.h:43
osl::effect::NumSimpleEffectTable::effectSetAt
const NumBitmapEffect effectSetAt(Square pos) const
ある位置の利きデータを取り出す.
Definition numSimpleEffect.h:219
osl::misc::GeneralMask::bsr
int bsr() const
Definition mask.h:258
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::lowestBit
GeneralMask lowestBit() const
non-zeroのmaskのsetされているビットをLSBから探し，そのビットだけがsetされたmaskを返す.
Definition mask.h:296
osl::mobility::KingMobility
Definition kingMobility.h:24
osl::mobility::MobilityTable
駒番号からMobilityContentを得る
Definition mobilityTable.h:52
osl::move_generator::AllMoves::generate
static void generate(const NumEffectState &state, Action &action)
effect_action.h
escape_.h
moveAdaptor.h
move_action.h
osl::csa::show
const std::string show(Move)
Definition csa.cc:133
osl::effect
Definition effectedNumTable.h:8
osl::misc::mask_t
GeneralMask< mask_int_t > mask_t
Definition mask.h:351
osl::move_classifier
Definition check_.h:10
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::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::PSILVER
@ PSILVER
Definition basic_type.h:90
osl::Ptype_Table
const PtypeTable Ptype_Table
Definition tables.cc:97
osl::getPtype
Ptype getPtype(PtypeO ptypeO)
Definition basic_type.h:217
osl::Piece_Table
const PieceTable Piece_Table
Definition tables.cc:94
osl::indexToPlayer
constexpr Player indexToPlayer(int n)
Definition basic_type.h:19
osl::unpromote
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に，promote前の型を返す． promoteしていない型の時はそのまま返す
Definition basic_type.h:157
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::Direction
Direction
Definition basic_type.h:310
osl::UL
@ UL
Definition basic_type.h:313
osl::Board_Mask_Table3x3
const BoardMaskTable3x3 Board_Mask_Table3x3
Definition tables.cc:120
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::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::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::operator==
bool operator==(Square l, Square r)
Definition basic_type.h:758
numEffectState.h
numEffectState.tcc
numSimpleEffect.tcc
pawnDropCheckmate.h
safeMove.h
simpleState.tcc
osl::GenerateAllMoves::generate
static void generate(Player p, const NumEffectState &state, MoveVector &)
Definition allMoves.cc:15
osl::GenerateEscapeKing::generate
static void generate(const NumEffectState &state, MoveVector &out)
不成の受けも作成
Definition escape_.cc:9
osl::PtypeFuns
Definition ptypeTraits.h:311
osl::PtypeTraits
Definition ptypeTraits.h:12
osl::effect_action::StorePiece
PieceVector に格納
Definition effect_action.h:151
osl::misc::Player2Type
Definition basic_type.h:75
osl::move_action::Store
指手を MoveVector に保管
Definition move_action.h:16