king8Info.h
Go to the documentation of this file.
/* king8Info.h
*/
#ifndef OSL_CHECKMATE_KING8INFO_H
#define OSL_CHECKMATE_KING8INFO_H
#include "osl/numEffectState.h"
#include "osl/additionalEffect.h"
#include <iosfwd>
namespace osl
{
namespace checkmate
{
class King8Info
{
uint64_t value;
public:
explicit King8Info(uint64_t v) : value(v)
{
}
template<Player P>
static const King8Info make(NumEffectState const& state,Square king, PieceMask pinned);
template<Player P>
static const King8Info make(NumEffectState const& state,Square king);
static const King8Info make(Player attack, NumEffectState const& state);
static const King8Info makeWithPin(Player attack, NumEffectState const& state,
const PieceMask& pinned);
uint64_t uint64Value() const { return value; }
unsigned int dropCandidate() const
{
return (unsigned int)(value&0xffull);
}
unsigned int liberty() const
{
return (unsigned int)((value>>8)&0xffull);
}
unsigned int libertyDropMask() const
{
return (unsigned int)(value&0xffffull);
}
unsigned int libertyCandidate() const
{
return (unsigned int)((value>>16)&0xffull);
}
unsigned int moveCandidate2() const
{
return (unsigned int)((value>>24)&0xffull);
}
unsigned int spaces() const
{
return (unsigned int)((value>>32)&0xffull);
}
unsigned int moves() const
{
return (unsigned int)((value>>40)&0xffull);
}
unsigned int libertyCount() const
{
return (unsigned int)((value>>48)&0xfull);
}
template<Player P,Direction Dir>
unsigned int moveCandidateDir(NumEffectState const& state,Square target) const{
if((value & (1ull<<(24+Dir)))==0) return 0;
Square pos=target-DirectionPlayerTraits<Dir,P>::offset();
if(state.countEffect(P,pos)<2 &&
!effect_util::AdditionalEffect::hasEffect(state,pos,P)) return 0;
return 1;
}
template<Player P>
unsigned int countMoveCandidate(NumEffectState const& state) const
{
const Player altP=alt(P);
Square king=state.kingSquare<altP>();
return moveCandidateDir<P,UL>(state,king)+
moveCandidateDir<P,U>(state,king)+
moveCandidateDir<P,UR>(state,king)+
moveCandidateDir<P,L>(state,king)+
moveCandidateDir<P,R>(state,king)+
moveCandidateDir<P,DL>(state,king)+
moveCandidateDir<P,D>(state,king)+
moveCandidateDir<P,DR>(state,king);
}
unsigned int countMoveCandidate(Player player, NumEffectState const& state) const
{
if(player==BLACK) return countMoveCandidate<BLACK>(state);
else return countMoveCandidate<WHITE>(state);
}
template<Player P>
unsigned int moveCandidateMask(NumEffectState const& state) const
{
const Player altP=alt(P);
Square king=state.kingSquare<altP>();
return (moveCandidateDir<P,UL>(state,king)<<UL)+
(moveCandidateDir<P,U>(state,king)<<U)+
(moveCandidateDir<P,UR>(state,king)<<UR)+
(moveCandidateDir<P,L>(state,king)<<L)+
(moveCandidateDir<P,R>(state,king)<<R)+
(moveCandidateDir<P,DL>(state,king)<<DL)+
(moveCandidateDir<P,D>(state,king)<<D)+
(moveCandidateDir<P,DR>(state,king)<<DR);
}
template<Player P>
bool hasMoveCandidate(NumEffectState const& state) const
{
const Player altP=alt(P);
Square king=state.kingSquare<altP>();
if(moveCandidateDir<P,U>(state,king)!=0) return true;
if(moveCandidateDir<P,UL>(state,king)!=0) return true;
if(moveCandidateDir<P,UR>(state,king)!=0) return true;
if(moveCandidateDir<P,L>(state,king)!=0) return true;
if(moveCandidateDir<P,R>(state,king)!=0) return true;
if(moveCandidateDir<P,D>(state,king)!=0) return true;
if(moveCandidateDir<P,DL>(state,king)!=0) return true;
if(moveCandidateDir<P,DR>(state,king)!=0) return true;
return false;
}
private:
template<Player P,Direction Dir>
static uint64_t
#ifdef __GNUC__
__attribute__ ((pure))
#endif
hasEffectMask(NumEffectState const& state,Square target, PieceMask pinned,
PieceMask on_board_defense);
};
std::ostream& operator<<(std::ostream&, King8Info);
} // namespace checkmate
using checkmate::King8Info;
} // namespace osl
#endif /* OSL_CHECKMATE_KING8INFO_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
additionalEffect.h
osl::NumEffectState
利きを持つ局面
Definition numEffectState.h:34
osl::NumEffectState::countEffect
int countEffect(Player player, Square target) const
利きの数を数える.
Definition numEffectState.h:266
osl::PieceMask
駒番号のビットセット.
Definition pieceMask.h:21
osl::SimpleState::kingSquare
Square kingSquare() const
Definition simpleState.h:94
osl::Square
Definition basic_type.h:532
osl::checkmate::King8Info
敵玉の8近傍の状態を表す.
Definition king8Info.h:29
osl::checkmate::King8Info::uint64Value
uint64_t uint64Value() const
Definition king8Info.h:46
osl::checkmate::King8Info::make
static const King8Info make(NumEffectState const &state, Square king)
osl::checkmate::King8Info::libertyCandidate
unsigned int libertyCandidate() const
16-23 bit 目を 0-7bitにshiftして返す
Definition king8Info.h:64
osl::checkmate::King8Info::liberty
unsigned int liberty() const
8-15 bit 目を 0-7bitにshiftして返す
Definition king8Info.h:54
osl::checkmate::King8Info::countMoveCandidate
unsigned int countMoveCandidate(NumEffectState const &state) const
Definition king8Info.h:95
osl::checkmate::King8Info::moveCandidate2
unsigned int moveCandidate2() const
24-31 bit 目を 0-7bitにshiftして返す
Definition king8Info.h:69
osl::checkmate::King8Info::makeWithPin
static const King8Info makeWithPin(Player attack, NumEffectState const &state, const PieceMask &pinned)
alt(attack) のking について計算.
Definition king8Info.cc:159
osl::checkmate::King8Info::King8Info
King8Info(uint64_t v)
Definition king8Info.h:32
osl::checkmate::King8Info::moveCandidateMask
unsigned int moveCandidateMask(NumEffectState const &state) const
Definition king8Info.h:114
osl::checkmate::King8Info::libertyDropMask
unsigned int libertyDropMask() const
0-15bit
Definition king8Info.h:59
osl::checkmate::King8Info::dropCandidate
unsigned int dropCandidate() const
0-7 bit 目を返す
Definition king8Info.h:49
osl::checkmate::King8Info::hasMoveCandidate
bool hasMoveCandidate(NumEffectState const &state) const
Definition king8Info.h:128
osl::checkmate::King8Info::make
static const King8Info make(NumEffectState const &state, Square king, PieceMask pinned)
osl::checkmate::King8Info::libertyCount
unsigned int libertyCount() const
libertyの数
Definition king8Info.h:82
osl::checkmate::King8Info::value
uint64_t value
Definition king8Info.h:30
osl::checkmate::King8Info::moves
unsigned int moves() const
Definition king8Info.h:77
osl::checkmate::King8Info::hasEffectMask
static uint64_t hasEffectMask(NumEffectState const &state, Square target, PieceMask pinned, PieceMask on_board_defense)
alt(P)の玉にDirの方向で迫るcanMoveMaskを計算する.
Definition king8Info.cc:67
osl::checkmate::King8Info::countMoveCandidate
unsigned int countMoveCandidate(Player player, NumEffectState const &state) const
Definition king8Info.h:108
osl::checkmate::King8Info::moveCandidateDir
unsigned int moveCandidateDir(NumEffectState const &state, Square target) const
Definition king8Info.h:87
osl::checkmate::King8Info::spaces
unsigned int spaces() const
Definition king8Info.h:73
osl::checkmate
Definition king8Info.h:12
osl::checkmate::operator<<
std::ostream & operator<<(std::ostream &, King8Info)
Definition king8Info.cc:10
osl
Definition additionalEffect.h:6
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::U
@ U
Definition basic_type.h:314
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::Player
Player
Definition basic_type.h:8
osl::BLACK
@ BLACK
Definition basic_type.h:9
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::effect_util::AdditionalEffect::hasEffect
static bool hasEffect(const NumEffectState &, Square target, Player attack)
target に attack の追加利きが一つでもあるか． 相手の影利きが先にある場合は対象としない．
Definition additionalEffect.cc:5