17 threatmate_move =
Move();
18 attack_shadow.fill(
false);
21 move_candidate_exists[
BLACK] = king8Info(
BLACK).hasMoveCandidate<
WHITE>(*state);
22 move_candidate_exists[
WHITE] = king8Info(
WHITE).hasMoveCandidate<
BLACK>(*state);
24 checkmate_defender[
BLACK] = findCheckmateDefender(*state,
BLACK);
25 checkmate_defender[
WHITE] = findCheckmateDefender(*state,
WHITE);
28 if (state->hasChangedEffects())
29 changed_effects = state->changedEffects(
alt(turn));
31 changed_effects.invalidate();
32 threatened[turn] = state->inCheck(turn)
33 ? state->kingPiece(turn) : state->findThreatenedPiece(turn);
34 threatened[
alt(turn)] = state->findThreatenedPiece(
alt(turn));
37 possible_threatmate_ptype
38 = checkmate::Immediate_Checkmate_Table.dropPtypeMask(king8Info(
alt(state->turn())));
39 const Square king = state->kingSquare(
alt(state->turn()));
43 if (state->pieceAt(knight_attack).isEmpty()
44 && ! state->hasEffectAt(
alt(state->turn()), knight_attack)) {
50 if (possible_threatmate_ptype & (1<<p))
51 if (state->hasPieceOnStand(state->turn(),
static_cast<Ptype>(p)))
55 bookmove.fill(
Move());
61 copy.copyFrom(*state);
63 const Square king = state->kingSquare(
alt(turn));
64 effect_util::SendOffSquare::find(turn, *state, king, sendoffs);
66 updatePinnedGenerals(
BLACK);
67 updatePinnedGenerals(
WHITE);
69 makePinOfLongPieces();
73 king8_long_pieces.push_back(p);
75 BlockLong::updateCache(*
this);
76 if (! history->hasLastMove() || !history->lastMove().isNormal()) {
80 last_move_ptype5 =
unpromote(history->lastMove().ptype());
81 if (last_move_ptype5 ==
SILVER)
82 last_move_ptype5 =
GOLD;
83 else if (last_move_ptype5 ==
KNIGHT)
84 last_move_ptype5 =
LANCE;
85 else if (
isMajor(last_move_ptype5))
87 last_add_effect = state->effectedMask(
alt(turn))
88 & state->effectedChanged(
alt(turn));
90 PatternCommon::updateCache(*
this);
93 static const BookInMemory& book = BookInMemory::instance();
95 for (
size_t i=0; i<bookmove.size(); ++i)
106 if (state->inCheck())
108 for (
int i=0; i<40; ++i) {
109 const Piece p = state->pieceOf(i);
116 if (long_effect[0].none() || long_effect[1].none())
continue;
119 attack_piece[0] = state->findLongAttackAt(p,
U);
120 attack_piece[1] = state->findLongAttackAt(p,
D);
122 && attack_piece[0].owner() != attack_piece[1].owner()) {
123 pin_by_opposing_sliders.push_back(p);
130 attack_piece[0] = state->findLongAttackAt(p,
L);
131 attack_piece[1] = state->findLongAttackAt(p,
R);
133 && attack_piece[0].owner() != attack_piece[1].owner()) {
134 pin_by_opposing_sliders.push_back(p);
141 attack_piece[0] = state->findLongAttackAt(p,
UL);
142 attack_piece[1] = state->findLongAttackAt(p,
DR);
144 && attack_piece[0].owner() != attack_piece[1].owner()) {
145 pin_by_opposing_sliders.push_back(p);
148 attack_piece[0] = state->findLongAttackAt(p,
UR);
149 attack_piece[1] = state->findLongAttackAt(p,
DL);
151 && attack_piece[0].owner() != attack_piece[1].owner()) {
152 pin_by_opposing_sliders.push_back(p);
163 const unsigned int spaces = king8info.
spaces();
164 if (spaces == 0 || (spaces & (spaces-1)))
165 return std::make_pair(Piece::EMPTY(),
Square());
170 return std::make_pair(Piece::EMPTY(),
Square());
172 drop_candidate &= 0xff00;
173 drop_candidate += spaces;
174 mask_t drop_ptype=mask_t::makeDirect
175 (checkmate::Immediate_Checkmate_Table.dropPtypeMaskOf(drop_candidate));
176 while(drop_ptype.any()){
181 return std::make_pair(Piece::EMPTY(),
Square());
187 exchange_pins[owner].clear();
188 PieceMask attacked = state->piecesOnBoard(owner)
189 & state->effectedMask(owner) & state->effectedMask(
alt(owner));
190 while (attacked.
any()) {
192 const int a = state->countEffect(
alt(owner), p.
square());
193 const int d = state->countEffect(owner, p.
square());
196 const Piece attack_p = state->findCheapAttack(
alt(owner), p.
square());
197 const Piece support = state->findCheapAttack(owner, p.
square());
203 directions &= directions-1;
207 Piece tp = state->pieceAt(target);
209 assert(state->hasEffectByPiece(support, target));
210 if (state->countEffect(owner, target)
211 <= state->countEffect(
alt(owner), target)+1
212 - state->hasEffectByPiece(attack_p, target)
213 && ! state->hasEffectIf(support.
ptypeO(), target, p.
square()))
214 exchange_pins[owner].push_back
237 if (last_move.
isNormal() && Neighboring8Direct::hasEffect
255 for (
int x=1; x<=9; ++x) {
256 for (
int y=1; y<=9; ++y) {
257 const Square position(x,y);
const Offset getOffset(Direction dir) const
PtypeO ptypeO() const
移動後のPtype, i.e., 成る手だった場合成った後
bool isNormal() const
INVALID でも PASS でもない.
const checkmate::King8Info king8Info(Player king) const
int countEffect(Player player, Square target) const
利きの数を数える.
bool hasEffectAt(Square target) const
対象とするマスにあるプレイヤーの利きがあるかどうか.
const Piece findCheapAttack(Player P, Square square) const
bool inCheck(Player P) const
Pの玉が王手状態
const Square square() const
bool isOnBoardByOwner() const
piece がプレイヤーPの持ち物でかつボード上にある駒の場合は true.
int getMoveMask(Ptype ptype) const
bool hasPieceOnStand(Player player, Ptype ptype) const
Square kingSquare() const
const Piece pieceAt(Square sq) const
unsigned int index() const
void find(const HashKey &key, MoveVector &out) const
深さ固定で,その深さまで depth first searchで読む詰将棋.
const ProofDisproof hasCheckmateMoveOfTurn(int depth, Move &best_move)
unsigned int libertyDropMask() const
0-15bit
unsigned int spaces() const
証明数(proof number)と反証数(disproof number).
bool isCheckmateSuccess() const
bool operator==(const PinnedGeneral &l, const PinnedGeneral &r)
const PtypeTable Ptype_Table
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す
const BoardTable Board_Table
constexpr bool isPiece(Ptype ptype)
ptypeが空白やEDGEでないかのチェック
bool isMajor(Ptype ptype)
constexpr Player alt(Player player)
void updatePinnedGenerals(Player owner)
static std::pair< Piece, Square > findCheckmateDefender(const NumEffectState &state, Player king)
CArray< Piece, 2 > threatened
const NumEffectState * state
CArray2d< bool, 40, 2 > attack_shadow
PieceVector king8_long_pieces
const MoveStack * history
static Move findShortThreatmate(const NumEffectState &, Move last_move)
CArray< bool, 2 > move_candidate_exists
CArray< pinned_gs_t, 2 > exchange_pins
CArray< std::pair< Piece, Square >, 2 > checkmate_defender
CArray< pattern_square_t, Square::SIZE > pattern_cache
void makePinOfLongPieces()
PieceMask last_add_effect
CArray< PieceMask, 2 > pin
CArray2d< long_attack_t, 40, 8 > long_attack_cache
PieceVector pin_by_opposing_sliders