rookMobility.h
Go to the documentation of this file.
/* rookMobility.h
*/
#ifndef MOBILITY_ROOK_MOBILITY_H
#define MOBILITY_ROOK_MOBILITY_H
#include "osl/mobility/countMobility.h"
#include "osl/bits/boardTable.h"
namespace osl
{
namespace mobility
{
struct RookMobility
{
public:
template<Player P>
static void countVerticalBoth(const NumEffectState& state,Piece p,int& countAll,int& countSafe){
assert(p.ptype()==ROOK || p.ptype()==PROOK);
assert(p.isOnBoard());
assert(p.owner()==P);
const Square pos=p.square();
countMobilityBoth(P,state,pos,DirectionPlayerTraits<U,P>::offset(),countAll,countSafe);
countMobilityBoth(P,state,pos,DirectionPlayerTraits<D,P>::offset(),countAll,countSafe);
}
static void countVerticalBoth(Player pl,const NumEffectState& state,Piece p,int& countAll,int& countSafe){
if(pl==BLACK)
countVerticalBoth<BLACK>(state,p,countAll,countSafe);
else
countVerticalBoth<WHITE>(state,p,countAll,countSafe);
}
template<Player P>
static int countVerticalAll(const NumEffectState& state,int num){
// const Square pos=p.square();
const Square posU=state.mobilityOf(U,num);
const Square posD=state.mobilityOf(D,num);
int count=posD.y()-posU.y()-2+
(state.pieceAt(posU).template canMoveOn<P>() ? 1 : 0)+
(state.pieceAt(posD).template canMoveOn<P>() ? 1 : 0);
return count;
}
template<Player P>
static int countVerticalAll(const NumEffectState& state,Piece p){
return countVerticalAll<P>(state,p.number());
}
static int countVerticalAll(Player pl,const NumEffectState& state,Piece p){
if(pl==BLACK)
return countVerticalAll<BLACK>(state,p);
else
return countVerticalAll<WHITE>(state,p);
}
template<Player P>
static int countVerticalSafe(const NumEffectState& state,Piece p){
const Square pos=p.square();
return
countMobilitySafe(P,state,pos,DirectionPlayerTraits<U,P>::offset())+
countMobilitySafe(P,state,pos,DirectionPlayerTraits<D,P>::offset());
}
static int countVerticalSafe(Player pl,const NumEffectState& state,Piece p){
if(pl==BLACK)
return countVerticalSafe<BLACK>(state,p);
else
return countVerticalSafe<WHITE>(state,p);
}
template<Player P>
static void countHorizontalBoth(const NumEffectState& state,Piece p,int& countAll,int& countSafe){
assert(p.ptype()==ROOK || p.ptype()==PROOK);
assert(p.isOnBoard());
assert(p.owner()==P);
const Square pos=p.square();
countMobilityBoth(P,state,pos,DirectionPlayerTraits<L,P>::offset(),countAll,countSafe);
countMobilityBoth(P,state,pos,DirectionPlayerTraits<R,P>::offset(),countAll,countSafe);
}
static void countHorizontalBoth(Player pl,const NumEffectState& state,Piece p,int& countAll,int& countSafe){
if(pl==BLACK)
countHorizontalBoth<BLACK>(state,p,countAll,countSafe);
else
countHorizontalBoth<WHITE>(state,p,countAll,countSafe);
}
template<Player P>
static int countHorizontalAll(const NumEffectState& state,int num)
{
const Square posR=state.mobilityOf(R,num);
const Square posL=state.mobilityOf(L,num);
int count=(posL.x()-posR.x()-2)+
(state.pieceAt(posR).template canMoveOn<P>() ? 1 : 0)+
(state.pieceAt(posL).template canMoveOn<P>() ? 1 : 0);
return count;
}
template<Player P>
static int countHorizontalAll(const NumEffectState& state,Piece p){
return countHorizontalAll<P>(state,p.number());
}
static int countHorizontalAll(Player pl,const NumEffectState& state,Piece p){
if(pl==BLACK)
return countHorizontalAll<BLACK>(state,p);
else
return countHorizontalAll<WHITE>(state,p);
}
template<Player P>
static int countHorizontalSafe(const NumEffectState& state,Piece p){
const Square pos=p.square();
return
countMobilitySafe(P,state,pos,DirectionPlayerTraits<L,P>::offset())+
countMobilitySafe(P,state,pos,DirectionPlayerTraits<R,P>::offset());
}
static int countHorizontalSafe(Player pl,const NumEffectState& state,Piece p){
if(pl==BLACK)
return countHorizontalSafe<BLACK>(state,p);
else
return countHorizontalSafe<WHITE>(state,p);
}
};
}
}
#endif /* MOBILITY_ROOK_MOBILITY_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
boardTable.h
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
osl::Square::x
int x() const
将棋としてのX座標を返す.
Definition basic_type.h:563
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::ROOK
@ ROOK
Definition basic_type.h:100
osl::PROOK
@ PROOK
Definition basic_type.h:92
osl::R
@ R
Definition basic_type.h:317
osl::D
@ D
Definition basic_type.h:319
osl::U
@ U
Definition basic_type.h:314
osl::L
@ L
Definition basic_type.h:316
osl::Player
Player
Definition basic_type.h:8
osl::BLACK
@ BLACK
Definition basic_type.h:9
osl::DirectionPlayerTraits
Definition directionTraits.h:242
osl::mobility::RookMobility
盤上の飛車および竜の動けるマス
Definition rookMobility.h:16
osl::mobility::RookMobility::countHorizontalAll
static int countHorizontalAll(Player pl, const NumEffectState &state, Piece p)
Definition rookMobility.h:119
osl::mobility::RookMobility::countHorizontalAll
static int countHorizontalAll(const NumEffectState &state, int num)
Definition rookMobility.h:103
osl::mobility::RookMobility::countHorizontalSafe
static int countHorizontalSafe(Player pl, const NumEffectState &state, Piece p)
Definition rookMobility.h:135
osl::mobility::RookMobility::countVerticalAll
static int countVerticalAll(const NumEffectState &state, int num)
縦方向，利きに関係なく動けるマスの数
Definition rookMobility.h:44
osl::mobility::RookMobility::countHorizontalAll
static int countHorizontalAll(const NumEffectState &state, Piece p)
横方向，利きに関係なく動けるマスの数
Definition rookMobility.h:116
osl::mobility::RookMobility::countVerticalBoth
static void countVerticalBoth(const NumEffectState &state, Piece p, int &countAll, int &countSafe)
縦方向， P : 駒pの持ち主 countAll : 利きに関係なく動けるマス countSafe : 相手の利きがない動けるマス 両方を求める
Definition rookMobility.h:26
osl::mobility::RookMobility::countVerticalAll
static int countVerticalAll(Player pl, const NumEffectState &state, Piece p)
Definition rookMobility.h:57
osl::mobility::RookMobility::countVerticalBoth
static void countVerticalBoth(Player pl, const NumEffectState &state, Piece p, int &countAll, int &countSafe)
Definition rookMobility.h:34
osl::mobility::RookMobility::countHorizontalBoth
static void countHorizontalBoth(Player pl, const NumEffectState &state, Piece p, int &countAll, int &countSafe)
Definition rookMobility.h:95
osl::mobility::RookMobility::countVerticalSafe
static int countVerticalSafe(Player pl, const NumEffectState &state, Piece p)
Definition rookMobility.h:73
osl::mobility::RookMobility::countHorizontalSafe
static int countHorizontalSafe(const NumEffectState &state, Piece p)
横方向，相手の利きがない動けるマスを求める
Definition rookMobility.h:129
osl::mobility::RookMobility::countVerticalSafe
static int countVerticalSafe(const NumEffectState &state, Piece p)
縦方向，相手の利きがない動けるマスを求める
Definition rookMobility.h:67
osl::mobility::RookMobility::countHorizontalBoth
static void countHorizontalBoth(const NumEffectState &state, Piece p, int &countAll, int &countSafe)
横方向， P : 駒pの持ち主 countAll : 利きに関係なく動けるマス countSafe : 相手の利きがない動けるマス 両方を求める
Definition rookMobility.h:87
osl::mobility::RookMobility::countVerticalAll
static int countVerticalAll(const NumEffectState &state, Piece p)
Definition rookMobility.h:54