bishopMobility.h
Go to the documentation of this file.
/* bishopMobility.h
*/
#ifndef MOBILITY_BISHOP_MOBILITY_H
#define MOBILITY_BISHOP_MOBILITY_H
#include "osl/mobility/countMobility.h"
#include <cstdlib>
namespace osl
{
namespace mobility
{
struct BishopMobility
{
public:
template<Player P>
static void countBoth(const NumEffectState& state,Piece p,int& countAll,int& countSafe){
assert(p.ptype()==BISHOP || p.ptype()==PBISHOP);
assert(p.isOnBoard());
assert(p.owner()==P);
const Square pos=p.square();
countMobilityBoth<P,true,true>(state,pos,DirectionPlayerTraits<UL,P>::offset(),countAll,countSafe);
countMobilityBoth<P,true,true>(state,pos,DirectionPlayerTraits<UR,P>::offset(),countAll,countSafe);
countMobilityBoth<P,true,true>(state,pos,DirectionPlayerTraits<DL,P>::offset(),countAll,countSafe);
countMobilityBoth<P,true,true>(state,pos,DirectionPlayerTraits<DR,P>::offset(),countAll,countSafe);
}
static void countBoth(Player pl,const NumEffectState& state,Piece p,int& countAll,int& countSafe){
if(pl==BLACK)
countBoth<BLACK>(state,p,countAll,countSafe);
else
countBoth<WHITE>(state,p,countAll,countSafe);
}
template<Player P>
static int countAll(const NumEffectState& state,int num){
const Square posUL=state.mobilityOf(UL,num);
const Square posUR=state.mobilityOf(UR,num);
const Square posDL=state.mobilityOf(DL,num);
const Square posDR=state.mobilityOf(DR,num);
int count=posDR.y()-posUL.y()+
posDL.y()-posUR.y()-4+
(state.pieceAt(posUR).template canMoveOn<P>() ? 1 : 0)+
(state.pieceAt(posDR).template canMoveOn<P>() ? 1 : 0)+
(state.pieceAt(posUL).template canMoveOn<P>() ? 1 : 0)+
(state.pieceAt(posDL).template canMoveOn<P>() ? 1 : 0);
return count;
}
template<Player P>
static int countAll(const NumEffectState& state,Piece p){
assert(p.ptype()==BISHOP || p.ptype()==PBISHOP);
assert(p.isOnBoard());
assert(p.owner()==P);
return countAll<P>(state,p.number());
}
static int countAll(Player pl,const NumEffectState& state,Piece p){
if(pl==BLACK)
return countAll<BLACK>(state,p);
else
return countAll<WHITE>(state,p);
}
template<Player P, Direction Dir>
static int countAllDir(const NumEffectState& state,Piece p){
assert(p.ptype()==BISHOP || p.ptype()==PBISHOP);
assert(p.isOnBoard());
assert(p.owner()==P);
assert(Dir == UL || Dir == UR || Dir == DL || Dir == DR);
Direction dir = (P == BLACK ? Dir : inverse(Dir));
const Square pos = state.mobilityOf(dir, p.number());
int count = std::abs(pos.y() - p.square().y())
- 1 + (state.pieceAt(pos).template canMoveOn<P>() ? 1 : 0);
return count;
}
template <Direction dir>
static int countAllDir(Player pl,const NumEffectState& state,Piece p){
if(pl==BLACK)
return countAllDir<BLACK, dir>(state,p);
else
return countAllDir<WHITE, dir>(state,p);
}
template<Player P>
static int countSafe(const NumEffectState& state,Piece p){
assert(p.ptype()==BISHOP || p.ptype()==PBISHOP);
assert(p.isOnBoard());
assert(p.owner()==P);
const Square pos=p.square();
return
countMobilitySafe(P,state,pos,DirectionPlayerTraits<UL,P>::offset())+
countMobilitySafe(P,state,pos,DirectionPlayerTraits<UR,P>::offset())+
countMobilitySafe(P,state,pos,DirectionPlayerTraits<DL,P>::offset())+
countMobilitySafe(P,state,pos,DirectionPlayerTraits<DR,P>::offset());
}
static int countSafe(Player pl,const NumEffectState& state,Piece p){
if(pl==BLACK)
return countSafe<BLACK>(state,p);
else
return countSafe<WHITE>(state,p);
}
};
}
}
#endif /* MOBILITY_BISHOP_MOBILITY_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::NumEffectState
利きを持つ局面
Definition numEffectState.h:34
osl::NumEffectState::mobilityOf
Square mobilityOf(Direction d, int num) const
Definition numEffectState.h:175
osl::Piece
駒.
Definition basic_type.h:788
osl::Piece::ptype
Ptype ptype() const
Definition basic_type.h:821
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::number
int number() const
Definition basic_type.h:828
osl::Piece::isOnBoard
bool isOnBoard() const
Definition basic_type.h:985
osl::SimpleState::pieceAt
const Piece pieceAt(Square sq) const
Definition simpleState.h:167
osl::Square
Definition basic_type.h:532
osl::Square::y
int y() const
将棋としてのY座標を返す.
Definition basic_type.h:567
countMobility.h
osl::mobility
Definition bishopMobility.h:11
osl::mobility::countMobilityBoth
void countMobilityBoth(const NumEffectState &state, Square pos, Offset o, int &countAll, int &countSafe)
P : 駒pの持ち主 All : countAllを求めるかどうか?
Definition countMobility.h:20
osl::mobility::countMobilitySafe
int countMobilitySafe(Player pl, const NumEffectState &state, Square pos, Offset o)
相手の利きがない動けるマスを求める
Definition countMobility.h:56
osl
Definition additionalEffect.h:6
osl::BISHOP
@ BISHOP
Definition basic_type.h:99
osl::PBISHOP
@ PBISHOP
Definition basic_type.h:91
osl::Direction
Direction
Definition basic_type.h:310
osl::UL
@ UL
Definition basic_type.h:313
osl::DR
@ DR
Definition basic_type.h:320
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::inverse
constexpr Direction inverse(Direction d)
Definition basic_type.h:358
osl::DirectionPlayerTraits
Definition directionTraits.h:242
osl::mobility::BishopMobility
盤上の角および馬が動けるマスの数を数える
Definition bishopMobility.h:16
osl::mobility::BishopMobility::countAllDir
static int countAllDir(const NumEffectState &state, Piece p)
Definition bishopMobility.h:74
osl::mobility::BishopMobility::countAllDir
static int countAllDir(Player pl, const NumEffectState &state, Piece p)
Definition bishopMobility.h:86
osl::mobility::BishopMobility::countBoth
static void countBoth(Player pl, const NumEffectState &state, Piece p, int &countAll, int &countSafe)
Definition bishopMobility.h:36
osl::mobility::BishopMobility::countBoth
static void countBoth(const NumEffectState &state, Piece p, int &countAll, int &countSafe)
斜め方向， P : 駒pの持ち主 countAll : 利きに関係なく動けるマス countSafe : 相手の利きがない動けるマス 両方を求める
Definition bishopMobility.h:26
osl::mobility::BishopMobility::countAll
static int countAll(Player pl, const NumEffectState &state, Piece p)
Definition bishopMobility.h:66
osl::mobility::BishopMobility::countSafe
static int countSafe(const NumEffectState &state, Piece p)
斜め方向，相手の利きがない動けるマスを求める
Definition bishopMobility.h:96
osl::mobility::BishopMobility::countAll
static int countAll(const NumEffectState &state, Piece p)
Definition bishopMobility.h:60
osl::mobility::BishopMobility::countAll
static int countAll(const NumEffectState &state, int num)
斜め方向，利きに関係なく動けるマスの数
Definition bishopMobility.h:46
osl::mobility::BishopMobility::countSafe
static int countSafe(Player pl, const NumEffectState &state, Piece p)
Definition bishopMobility.h:107