pawnDropCheckmate.h
Go to the documentation of this file.
/* pawnDropCheckmate.h
*/
#ifndef OSL_MOVE_CLASSIFIER_PAWNDROPCHECKMATE_H
#define OSL_MOVE_CLASSIFIER_PAWNDROPCHECKMATE_H
#include "osl/numEffectState.h"
#include "osl/bits/king8Info.h"
namespace osl
{
namespace move_classifier
{
template <Player P>
struct PawnDropCheckmate
{
static bool canEscape(const NumEffectState& state, Square kingSquare,
Direction dir, Square dropAt);
static bool escape7(const NumEffectState& state,
Square kingSquare, Square to);
static bool isMember(const NumEffectState& state,
Ptype ptype,Square from,Square to)
{
// 打歩
if (! from.isPieceStand())
return false;
if (ptype != PAWN)
return false;
const Player Opponent = alt(P);
const Piece king = state.template kingPiece<Opponent>();
const Square king_position = king.square();
// DirectionPlayerTraits?
// 玉頭
if (king_position != (to + DirectionPlayerTraits<U,P>::offset()))
return false;
// 玉で取れない
if (! state.hasEffectAt(P, to))
return false;
if (King8Info(state.Iking8Info(Opponent)).liberty() != 0)
return false;
// 玉以外の駒で取れない
if (state.safeCaptureNotByKing<Opponent>(to, king)
!= Piece::EMPTY())
return false;
// どこにも逃げられない
return escape7(state, king_position, to);
}
};
} // namespace move_classifier
} // namespace osl
template <osl::Player P>
bool
#ifdef __GNUC__
__attribute__ ((pure))
#endif
osl::move_classifier::PawnDropCheckmate<P>::
canEscape(const NumEffectState& state, Square kingSquare,
Direction dir, Square dropAt)
{
const Player Opponent = alt(P);
const Square target
= kingSquare + Board_Table.getOffset(Opponent, dir);
const Piece p = state.pieceAt(target);
if (p.isOnBoardByOwner<Opponent>())
return false; // 自分の駒がいたら移動不能
if (target.isEdge())
return false;
Piece attacker;
if (! state.template hasEffectAt<P>(target, attacker))
return true; // 利きがない
if (attacker == Piece::EMPTY())
return false; // 攻撃側に複数の利き
assert(attacker.owner() == P);
// drop によりふさがれた利きなら逃げられる
// -OU
// XXX+FU+HI
// の場合のXXXなど．
const Offset shortOffset
= Board_Table.getShortOffsetNotKnight(Offset32(target,dropAt));
if (shortOffset.zero())
return false;
const Square attackFrom = attacker.square();
return shortOffset
== Board_Table.getShortOffsetNotKnight(Offset32(dropAt,attackFrom));
}
template <osl::Player P>
bool
#ifdef __GNUC__
__attribute__ ((pure))
#endif
osl::move_classifier::PawnDropCheckmate<P>::
escape7(const NumEffectState& state, Square king_position, Square to)
{
// U は歩
if (canEscape(state, king_position, UL, to))
return false;
if (canEscape(state, king_position, UR, to))
return false;
if (canEscape(state, king_position, L, to))
return false;
if (canEscape(state, king_position, R, to))
return false;
if (canEscape(state, king_position, DL, to))
return false;
if (canEscape(state, king_position, D, to))
return false;
if (canEscape(state, king_position, DR, to))
return false;
return true;
}
#endif /* OSL_MOVE_CLASSIFIER_PAWNDROPCHECKMATE_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::NumEffectState
利きを持つ局面
Definition numEffectState.h:34
osl::NumEffectState::hasEffectAt
bool hasEffectAt(Square target) const
対象とするマスにあるプレイヤーの利きがあるかどうか.
Definition numEffectState.h:324
osl::NumEffectState::safeCaptureNotByKing
Piece safeCaptureNotByKing(Square target, Piece king) const
玉の素抜きなしに合法手でtargetに移動可能かを判定
osl::NumEffectState::Iking8Info
uint64_t Iking8Info(Player king) const
Definition numEffectState.h:78
osl::Offset
座標の差分
Definition basic_type.h:430
osl::Offset::zero
bool zero() const
Definition basic_type.h:502
osl::Piece
駒.
Definition basic_type.h:788
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::isOnBoardByOwner
bool isOnBoardByOwner() const
piece がプレイヤーPの持ち物でかつボード上にある駒の場合は true.
Definition basic_type.h:852
osl::Piece::EMPTY
static const Piece EMPTY()
Definition basic_type.h:797
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::isEdge
bool isEdge() const
onBoardから8近傍のオフセットを足した点がedgeかどうかの判定 そこそこ速くなった．
Definition basic_type.h:591
osl::checkmate::King8Info
敵玉の8近傍の状態を表す.
Definition king8Info.h:29
osl::checkmate::King8Info::liberty
unsigned int liberty() const
8-15 bit 目を 0-7bitにshiftして返す
Definition king8Info.h:54
king8Info.h
osl::mobility::__attribute__
long long v2di __attribute__((vector_size(16)))
Definition kingMobility.h:22
osl::move_classifier
Definition check_.h:10
osl
Definition additionalEffect.h:6
osl::Ptype
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
osl::PAWN
@ PAWN
Definition basic_type.h:95
osl::Board_Table
const BoardTable Board_Table
Definition tables.cc:95
osl::Direction
Direction
Definition basic_type.h:310
osl::R
@ R
Definition basic_type.h:317
osl::D
@ D
Definition basic_type.h:319
osl::UL
@ UL
Definition basic_type.h:313
osl::DR
@ DR
Definition basic_type.h:320
osl::L
@ L
Definition basic_type.h:316
osl::UR
@ UR
Definition basic_type.h:315
osl::DL
@ DL
Definition basic_type.h:318
osl::Offset32
Offset32Base< 8, 9 > Offset32
Definition offset32.h:63
osl::Player
Player
Definition basic_type.h:8
osl::__attribute__
const PtypeO PTYPEO_EDGE __attribute__((unused))
osl::alt
constexpr Player alt(Player player)
Definition basic_type.h:13
numEffectState.h
osl::DirectionPlayerTraits
Definition directionTraits.h:242
osl::move_classifier::PawnDropCheckmate
打歩詰の判定.
Definition pawnDropCheckmate.h:19
osl::move_classifier::PawnDropCheckmate::canEscape
static bool canEscape(const NumEffectState &state, Square kingSquare, Direction dir, Square dropAt)
kingSquare に居る alt(P)の玉が dir 方向に逃げられるか.
Definition pawnDropCheckmate.h:65
osl::move_classifier::PawnDropCheckmate::escape7
static bool escape7(const NumEffectState &state, Square kingSquare, Square to)
王が前以外に移動可能か
Definition pawnDropCheckmate.h:101
osl::move_classifier::PawnDropCheckmate::isMember
static bool isMember(const NumEffectState &state, Ptype ptype, Square from, Square to)
Definition pawnDropCheckmate.h:28