17#if (defined(__i386__) || defined(__x86_64__)) && !defined(OSL_NO_SSE)
49template<osl::Player P>
53#ifdef ALLOW_KING_ABSENCE
67 effects.effected_mask[0].resetAll();
68 effects.effected_mask[1].resetAll();
69 effects.effected_changed_mask[0].resetAll();
70 effects.effected_changed_mask[1].resetAll();
71 for(
int num=0;num<40;num++){
81 effects.effected_mask[i].set(num);
82 effects.effected_changed_mask[i].set(num);
130 if (
pieces.none() || ppieces.none())
132 const int num =
pieces.bsf(), nump = ppieces.bsf();
135 return pieceOf(std::min(num, nump));
144 int pp=-1, npp=-1, ret=-1;
146 for (
int i=lance_index; i>=0; --i) {
154 if (notpromoted.
any())
155 npp = notpromoted.
bsr() + i*32;
156 ret = std::max(pp, npp);
179 const Square from = last_move.
from(), to = last_move.
to();
247 pin_or_open_backup, king_mobility_backup,
248 promoted_backup, effected_mask_backup, effected_changed_mask_backup,king8infos_backup,mobilityTable);
253 pin_or_open_backup, king_mobility_backup,
254 promoted_backup, effected_mask_backup, effected_changed_mask_backup,king8infos_backup,mobilityTable);
264 int num0, num1, num1Index;
275 capturePtypeO,
newPtypeO, num0, num1, num1Index,num1Mask,
276 pin_or_open_backup, king_mobility_backup,
277 promoted_backup, effected_mask_backup, effected_changed_mask_backup,king8infos_backup,mobilityTable);
281 capturePtypeO,
newPtypeO, num0, num1, num1Index,num1Mask,
282 pin_or_open_backup, king_mobility_backup,
283 promoted_backup, effected_mask_backup, effected_changed_mask_backup,king8infos_backup,mobilityTable);
286 if (capturePtype==
PAWN)
307 pin_or_open_backup, king_mobility_backup,
308 effected_mask_backup, effected_changed_mask_backup,king8infos_backup,mobilityTable);
312 pin_or_open_backup, king_mobility_backup,
313 effected_mask_backup, effected_changed_mask_backup,king8infos_backup,mobilityTable);
319template<osl::Player P>
322 Piece& oldPiece,
int& num,
332 mobility_backup =
effects.mobilityTable;
335 effected_mask_backup =
effects.effected_mask;
336 effected_changed_mask_backup =
effects.effected_changed_mask;
344 oldPtypeO=oldPiece.
ptypeO();
345 new_ptypeo=newPiece.
ptypeO();
349 effects.clearEffectedChanged();
350 effects.template doEffect<NumBitmapEffect::Sub,true>(*
this,oldPtypeO,from,num);
353 effects.effectedNumTable[num].clear();
355 effects.template doBlockAt<NumBitmapEffect::Sub,true>(*
this,to,num);
357 effects.template doBlockAt<NumBitmapEffect::Add,true>(*
this,from,num);
358 effects.template doEffect<NumBitmapEffect::Add,true>(*
this,new_ptypeo,to,num);
414 effects.effectedNumTable[num].clear();
419 effects.invalidateChangedEffects();
423 effects.effected_mask = effected_mask_backup;
424 effects.effected_changed_mask = effected_changed_mask_backup;
425 effects.mobilityTable = mobility_backup;
429template<osl::Player P>
433 int& numIndex,
mask_t& numMask,
442 mobility_backup =
effects.mobilityTable;
445 effected_mask_backup =
effects.effected_mask;
446 effected_changed_mask_backup =
effects.effected_changed_mask;
447#if OSL_WORDSIZE == 64
449#elif OSL_WORDSIZE == 32
452 const mask_t ownMochigoma=
454 assert(ownMochigoma.
any());
456 int numLow = ownMochigoma.
bsf();
457 num = numLow|(numIndex<<5);
459 Piece newPiece=oldPiece;
464 effects.clearEffectedChanged();
465 effects.template doBlockAt<NumBitmapEffect::Sub,true>(*
this,to,num);
466 effects.template doEffect<NumBitmapEffect::Add,true>(*
this,ptypeO,to,num);
501template<osl::Player P>
516 effects.template doEffect<NumBitmapEffect::Sub,false>(*
this,ptypeO,to,num);
517 effects.template doBlockAt<NumBitmapEffect::Add,false>(*
this,to,num);
519 effects.effectedNumTable[num].clear();
520 effects.invalidateChangedEffects();
523 effects.effected_mask = effected_mask_backup;
524 effects.effected_changed_mask = effected_changed_mask_backup;
525 effects.mobilityTable = mobility_backup;
529template<osl::Player P>
534 PtypeO& new_ptypeo,
int& num0,
int& num1,
535 int& num1Index,
mask_t& num1Mask,
544 mobility_backup =
effects.mobilityTable;
547 effected_mask_backup =
effects.effected_mask;
548 effected_changed_mask_backup =
effects.effected_changed_mask;
555 standMask(P).xorMask(num1Index,num1Mask);
563 oldPtypeO=oldPiece.
ptypeO();
564 new_ptypeo=newPiece.
ptypeO();
565 capturePtypeO=target.
ptypeO();
568 effects.clearEffectedChanged();
570 effects.template doEffect<NumBitmapEffect::Sub,true>(*
this,capturePtypeO,to,num1);
571 effects.template doEffect<NumBitmapEffect::Sub,true>(*
this,oldPtypeO,from,num0);
573 effects.template doBlockAt<NumBitmapEffect::Add,true>(*
this,from,num0);
575 effects.effectedNumTable[num1].clear();
577 effects.template doEffect<NumBitmapEffect::Add,true>(*
this,new_ptypeo,to,num0);
624template<osl::Player P>
629 int num1Index,
mask_t num1Mask,
638 standMask(P).xorMask(num1Index,num1Mask);
642 effects.effectedNumTable[num0].clear();
645 effects.template doEffect<NumBitmapEffect::Sub,false>(*
this,
newPtypeO,to,num0);
648 effects.template doBlockAt<NumBitmapEffect::Sub,false>(*
this,from,num0);
649 effects.template doEffect<NumBitmapEffect::Add,false>(*
this,capturePtypeO,to,num1);
650 effects.template doEffect<NumBitmapEffect::Add,false>(*
this,oldPtypeO,from,num0);
651 effects.invalidateChangedEffects();
655 effects.effected_mask = effected_mask_backup;
656 effects.effected_changed_mask = effected_changed_mask_backup;
657 effects.mobilityTable = mobility_backup;
668 std::cerr <<
"error before effect\n";
676 std::cerr <<
"Effect error 1" << std::endl;
678 for(
int y=1;y<=9;y++)
684 std::cerr << pos <<
",real=" <<
effects.effectSetAt(pos) <<
",ideal=" << effects1.
effectSetAt(pos) << std::endl;
687 for(
int num=0;num<=39;num++){
688 for(
int i=0;i<8;i++){
691 std::cerr <<
"piece=" <<
pieceOf(num) <<
",num=" << num <<
",d=" << d <<
",v1=" <<
effects.effectedNumTable[num][d] <<
",v2=" << effects1.
effectedNumTable[num][d] << std::endl;
695 std::cerr <<
effects.effectedNumTable << std::endl;
699 for (
int z=0; z<2; ++z) {
701#ifdef ALLOW_KING_ABSENCE
706 const PieceMask pin2 = effect_util::Pin::make(*
this, p);
707 if (
pin(p) != pin2) {
709 std::cerr <<
"pin for " << p <<
" differs " <<
pin(p) <<
" " << pin2 <<
"\n";
716 std::cerr <<
"king8info for " << p <<
" differs \n" <<
King8Info(
Iking8Info(p)) <<
"\n" << king8info2 <<
"\n";
725 std::cerr <<
"promoted differs " << p <<
" " <<
promoted <<
" " <<
promoted.test(i) <<
"\n";
742 each_effect[i].clear();
743 prev_effect[i].clear();
745 for (
int x=1; x<=9; ++x) {
746 for (
int y=1; y<=9; ++y) {
750 each_effect[i].set(sq);
752 prev_effect[i].set(sq);
754 if (! changed_all.
test(sq))
759 std::cerr <<
"changedEffects unset\n" << *
this << moved << sq <<
"\n";
764 for (
int i=0; i<2; ++i)
767 if (! changed_squares[pl].test(sq))
773 std::cerr <<
"changedEffects unset for " << pl <<
"\n" << *
this << moved << sq <<
"\n";
784 if (each_effect[i] == prev_effect[i])
786 if (! changed_effect_pieces.
test(i)) {
789 std::cerr <<
"changedPieces() unset\n" << *
this << moved << i
790 <<
" " << each_effect[i] <<
" != " << prev_effect[i] <<
"\n";
798 for (
int j=0; j<2; ++j)
807 std::cerr <<
"effectedChanged(" << pl <<
") unset\n" << *
this << moved << i
818template <
bool show_error>
820#if (defined __GNUC__) && (! defined GPSONE) && (! defined GPSUSIONE)
839 std::cerr <<
" No such move2 : " << move << std::endl;
860 os<< static_cast<SimpleState const&>(*
this);
861 for(
int y=1;y<=9;y++){
863 for(
int x=9;x>0;x--){
938#if (defined(__i386__) || defined(__x86_64__)) && !defined(OSL_NO_SSE)
940 v2di b16=*((v2di*)&src.
board[16]);
941 v2di b20=*((v2di*)&src.
board[20]);
942 v2di b24=*((v2di*)&src.
board[24]);
943 v2di b32=*((v2di*)&src.
board[32]);
944 v2di b36=*((v2di*)&src.
board[36]);
945 v2di b40=*((v2di*)&src.
board[40]);
946 v2di b48=*((v2di*)&src.
board[48]);
947 v2di b52=*((v2di*)&src.
board[52]);
948 v2di b56=*((v2di*)&src.
board[56]);
950 *((v2di*)&(*this).board[16])=b16;
951 *((v2di*)&(*this).board[20])=b20;
952 *((v2di*)&(*this).board[24])=b24;
953 *((v2di*)&(*this).board[32])=b32;
954 *((v2di*)&(*this).board[36])=b36;
955 *((v2di*)&(*this).board[40])=b40;
956 *((v2di*)&(*this).board[48])=b48;
957 *((v2di*)&(*this).board[52])=b52;
958 *((v2di*)&(*this).board[56])=b56;
961 v2di b64=*((v2di*)&src.
board[64]);
962 v2di b68=*((v2di*)&src.
board[68]);
963 v2di b72=*((v2di*)&src.
board[72]);
965 v2di b80=*((v2di*)&src.
board[80]);
966 v2di b84=*((v2di*)&src.
board[84]);
967 v2di b88=*((v2di*)&src.
board[88]);
969 v2di b96=*((v2di*)&src.
board[96]);
970 v2di b100=*((v2di*)&src.
board[100]);
971 v2di b104=*((v2di*)&src.
board[104]);
974 *((v2di*)&(*this).board[64])=b64;
975 *((v2di*)&(*this).board[68])=b68;
976 *((v2di*)&(*this).board[72])=b72;
978 *((v2di*)&(*this).board[80])=b80;
979 *((v2di*)&(*this).board[84])=b84;
980 *((v2di*)&(*this).board[88])=b88;
982 *((v2di*)&(*this).board[96])=b96;
983 *((v2di*)&(*this).board[100])=b100;
984 *((v2di*)&(*this).board[104])=b104;
986 v2di b112=*((v2di*)&src.
board[112]);
987 v2di b116=*((v2di*)&src.
board[116]);
988 v2di b120=*((v2di*)&src.
board[120]);
990 v2di b128=*((v2di*)&src.
board[128]);
991 v2di b132=*((v2di*)&src.
board[132]);
992 v2di b136=*((v2di*)&src.
board[136]);
994 v2di b144=*((v2di*)&src.
board[144]);
995 v2di b148=*((v2di*)&src.
board[148]);
996 v2di b152=*((v2di*)&src.
board[152]);
998 *((v2di*)&(*this).board[112])=b112;
999 *((v2di*)&(*this).board[116])=b116;
1000 *((v2di*)&(*this).board[120])=b120;
1002 *((v2di*)&(*this).board[128])=b128;
1003 *((v2di*)&(*this).board[132])=b132;
1004 *((v2di*)&(*this).board[136])=b136;
1006 *((v2di*)&(*this).board[144])=b144;
1007 *((v2di*)&(*this).board[148])=b148;
1008 *((v2di*)&(*this).board[152])=b152;
1010 v2di p0=*((v2di*)&src.
pieces[0]);
1011 v2di p4=*((v2di*)&src.
pieces[4]);
1012 v2di p8=*((v2di*)&src.
pieces[8]);
1013 v2di p12=*((v2di*)&src.
pieces[12]);
1014 v2di p16=*((v2di*)&src.
pieces[16]);
1015 v2di p20=*((v2di*)&src.
pieces[20]);
1016 v2di p24=*((v2di*)&src.
pieces[24]);
1017 v2di p28=*((v2di*)&src.
pieces[28]);
1018 v2di p32=*((v2di*)&src.
pieces[32]);
1019 v2di p36=*((v2di*)&src.
pieces[36]);
1020 *((v2di*)&(*this).pieces[0])=p0;
1021 *((v2di*)&(*this).pieces[4])=p4;
1022 *((v2di*)&(*this).pieces[8])=p8;
1023 *((v2di*)&(*this).pieces[12])=p12;
1024 *((v2di*)&(*this).pieces[16])=p16;
1025 *((v2di*)&(*this).pieces[20])=p20;
1026 *((v2di*)&(*this).pieces[24])=p24;
1027 *((v2di*)&(*this).pieces[28])=p28;
1028 *((v2di*)&(*this).pieces[32])=p32;
1029 *((v2di*)&(*this).pieces[36])=p36;
1032 for(
int x=1;x<=9;x++)
1033 for(
int y=1;y<=9;y++)
1035 (*this).pieces=src.
pieces;
1056 return ConditionAdaptor<SafeMove>::isMember(*
this, move);
1061 return PlayerMoveAdaptor<Check>::isMember(*
this, move);
1066 return PlayerMoveAdaptor<PawnDropCheckmate>::isMember(*
this, move);
1071 return PlayerMoveAdaptor<DirectCheck>::isMember(*
this, move);
1077 return ConditionAdaptor<OpenCheck>::isMember(*
this, move);
1098 std::copy_if(all_moves.
begin(), all_moves.
end(), std::back_inserter(moves),
1100 return this->isSafeMove(m) && ! this->isPawnDropCheckmate(m);
1110 for (
int i=0, iend=moves.
size(); i<iend; ++i) {
1111 const Move move = moves[i];
void push_back(const T &e)
static const King8Info make(NumEffectState const &state, Square king, PieceMask pinned)
const Move unpromote() const
promote moveからunpromote moveを作る
PtypeO capturePtypeO() const
bool isNormal() const
INVALID でも PASS でもない.
int promoteMask() const
pieceに使うためのmaskなので
Ptype oldPtype() const
移動前のPtype, i.e., 成る手だった場合成る前
bool hasIgnoredUnpromote() const
MoveをunpromoteするとcutUnpromoteなMoveになる
const Square from() const
Direction pinnedDir(Piece p) const
pinされた駒がPのKingから見てどの方向か?
void generateLegal(MoveVector &) const
全ての合法手を生成する.
const NumBitmapEffect effectSetAt(Square sq) const
bool hasEffectByWithRemove(Square target, Square removed) const
void recalcPinOpen(Square changed, Direction &lastDir, Player defense)
void doCaptureMove(Square from, Square to, Piece target, int promoteMask)
const checkmate::King8Info king8Info(Player king) const
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)
bool isOpenCheck(Move move) const
const BoardMask changedEffects(Player pl) const
CArray< PieceMask, 2 > pieces_onboard
const Piece selectCheapPiece(PieceMask effect) const
利きの中から安そうな駒を選ぶ
bool isPawnDropCheckmate(Move move) const
const PieceMask effectedMask(Player pl) const
pl からの利きが(1つ以上)ある駒一覧
void doSimpleMove(Square from, Square to, int promoteMask)
void makePinOpenDir(Square target, PieceMask &pins, PieceMask const &onBoard, Player defense)
void forEachEffect(const PieceMask &pieces, Square sq, Action &action) const
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)
bool wasCheckEvasion(Move last_move) const
bool isAlmostValidMove(Move move) const
合法手かどうかを簡単に検査する.局面に依存するチェックのみ. ルール上指せない手である可能性がある場合は,isValidMove を用いる.
bool hasEffectByPiece(Piece attack, Square target) const
駒attack が target に利きを持つか (旧hasEffectToと統合)
const PieceMask effectedChanged(Player pl) const
前の指手でeffectedMask(pl)が変化したか.
void copyFrom(const NumEffectState &src)
主要部分を高速にコピーする.
void generateAllUnsafe(MoveVector &) const
自殺を含めてすべての手を生成
PieceMask makePinOpen(Square target, Player defense)
bool isDirectCheck(Move move) const
bool hasEffectAt(Square target) const
対象とするマスにあるプレイヤーの利きがあるかどうか.
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)
const PieceMask pin(Player king) const
NumEffectState(const SimpleState &st=SimpleState(HIRATE))
const NumBitmapEffect changedPieces() const
const Piece findThreatenedPiece(Player P) const
取られそうなPの駒で価値が最大のもの
effect::NumSimpleEffectTable effects
Piece safeCaptureNotByKing(Square target, Piece king) const
玉の素抜きなしに合法手でtargetに移動可能かを判定
const PieceMask promotedPieces() const
void findEffect(Player P, Square target, PieceVector &out) const
target に利きのあるPieceをoutに格納する
bool hasEffectIf(PtypeO ptypeo, Square attacker, Square target) const
attackerにptypeoの駒がいると仮定した場合にtargetに利きがあるかどうか を stateをupdateしないで確かめる.
void doDropMove(Square to, Ptype ptype)
bool inCheck(Player P) const
Pの玉が王手状態
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)
KingMobility king_mobility
void showEffect(std::ostream &os) const
CArray< uint64_t, 2 > king8infos
CArray< PieceMask, 2 > pin_or_open
bool isSafeMove(Move move) const
const PieceMask & piecesOnBoard(Player p) const
uint64_t Iking8Info(Player king) const
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)
bool isConsistent(bool showError=true) const
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)
bool isCheck(Move move) const
const mask_t allEffectAt(Player P, Square target) const
void generateWithFullUnpromotions(MoveVector &) const
打歩詰め絡み以外では有利にはならない手も含め, 全ての合法手を生成す る(Move::ignoredUnpromoteも生成する).
const mask_t getMask(int num) const
void clearBit()
unpromote(PTYPE) の駒のbit を消す
static const mask_t numToMask(int num)
bool isPromoted() const
promoteした駒かどうかをチェックする
const Square square() const
const Piece promoteWithMask(int promote_mask) const
static const Piece EMPTY()
const Piece captured() const
取られたpieceを作成.
CArray< BitXmask, 2 > pawnMask
const Piece pieceOnBoard(Square sq) const
bool isAlmostValidDrop(Move move) const
CArray< Piece, Square::SIZE > board
static bool isValidMoveByRule(Move move, bool show_error)
盤面以外の部分の反則のチェック
CArray< CArray< char, PTYPE_SIZE-PTYPE_BASIC_MIN >, 2 > stand_count
void setPieceOf(int num, Piece p)
void clearPawn(Player pl, Square sq)
(internal)
PieceMask & standMask(Player p)
bool isOnBoard(int num) const
CArray< PieceMask, 2 > stand_mask
void setBoard(Square sq, Piece piece)
CArray< Piece, Piece::SIZE > pieces
全てのpieceが登録されている
bool testValidityOtherThanEffect(Move move) const
const Piece pieceOf(int num) const
bool isConsistent(bool show_error=true) const
void setPawn(Player pl, Square sq)
(internal)
Square kingSquare() const
const Piece pieceAt(Square sq) const
unsigned int index() const
bool isPieceStand() const
static const Square STAND()
uint64_t uint64Value() const
bool test(unsigned int i) const
bool anyInRange(const BoardMask &mask) const
static int numToIndex(int)
EffectedNumTable effectedNumTable
effected num
const NumBitmapEffect effectSetAt(Square pos) const
ある位置の利きデータを取り出す.
GeneralMask lowestBit() const
non-zeroのmaskのsetされているビットをLSBから探し,そのビットだけがsetされたmaskを返す.
static void generate(const NumEffectState &state, Action &action)
const std::string show(Move)
GeneralMask< mask_int_t > mask_t
const PtypeTable Ptype_Table
Ptype getPtype(PtypeO ptypeO)
const PieceTable Piece_Table
constexpr Player indexToPlayer(int n)
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す
const BoardTable Board_Table
constexpr Direction primDirUnsafe(Direction d)
8方向について,primitiveな4方向を求める dとしてknight, INVALIDなども来る
const BoardMaskTable3x3 Board_Mask_Table3x3
const PtypeO PTYPEO_EDGE __attribute__((unused))
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
constexpr Direction primDir(Direction d)
8方向について,primitiveな4方向を求める
constexpr Player alt(Player player)
PtypeO newPtypeO(Player player, Ptype ptype)
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に,ownerを反転する.
bool operator==(Square l, Square r)
static void generate(Player p, const NumEffectState &state, MoveVector &)
static void generate(const NumEffectState &state, MoveVector &out)
不成の受けも作成