countMobility.h
Go to the documentation of this file.
/* countMobility.h
*/
#ifndef MOBILITY_COUNT_MOBILITY_H
#define MOBILITY_COUNT_MOBILITY_H
#include "osl/numEffectState.h"
namespace osl
{
namespace mobility
{
template<Player P,bool All,bool Safe>
inline void countMobilityBoth(const NumEffectState& state,Square pos,Offset o,int& countAll,int& countSafe){
assert(pos.isOnBoard());
assert(!o.zero());
Piece p;
for(pos+=o;(p=state.pieceAt(pos)).isEmpty();pos+=o){
if(All) countAll++;
if(Safe && !state.hasEffectAt<alt(P)>(pos))
countSafe++;
}
if(p.canMoveOn<P>()){
if(All) countAll++;
if(Safe && !state.hasEffectAt<alt(P)>(pos))
countSafe++;
}
}
inline void countMobilityBoth(Player P,const NumEffectState& state,Square pos,Offset o,int& countAll,int& countSafe){
if(P==BLACK)
countMobilityBoth<BLACK,true,true>(state,pos,o,countAll,countSafe);
else
countMobilityBoth<WHITE,true,true>(state,pos,o,countAll,countSafe);
}
inline int countMobilityAll(Player pl,const NumEffectState& state,Square pos,Offset o)
{
int ret=0,dummy=0;
if(pl==BLACK)
countMobilityBoth<BLACK,true,false>(state,pos,o,ret,dummy);
else
countMobilityBoth<WHITE,true,false>(state,pos,o,ret,dummy);
return ret;
}
inline int countMobilitySafe(Player pl,const NumEffectState& state,Square pos,Offset o)
{
int ret=0,dummy=0;
if(pl==BLACK)
countMobilityBoth<BLACK,false,true>(state,pos,o,dummy,ret);
else
countMobilityBoth<WHITE,false,true>(state,pos,o,dummy,ret);
return ret;
}
}
}
#endif /* MOBILITY_ROOK_MOBILITY_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::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::canMoveOn
bool canMoveOn() const
Player Pの駒が，thisの上に移動できるか?
Definition basic_type.h:980
osl::SimpleState::pieceAt
const Piece pieceAt(Square sq) const
Definition simpleState.h:167
osl::Square
Definition basic_type.h:532
osl::Square::isOnBoard
bool isOnBoard() const
盤面上を表すかどうかの判定． 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する．
Definition basic_type.h:583
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::mobility::countMobilityAll
int countMobilityAll(Player pl, const NumEffectState &state, Square pos, Offset o)
利きに関係なく動けるマスの数
Definition countMobility.h:44
osl
Definition additionalEffect.h:6
osl::Player
Player
Definition basic_type.h:8
osl::BLACK
@ BLACK
Definition basic_type.h:9
osl::alt
constexpr Player alt(Player player)
Definition basic_type.h:13
numEffectState.h