My Project
countMobility.h
Go to the documentation of this file.
1/* countMobility.h
2 */
3#ifndef MOBILITY_COUNT_MOBILITY_H
4#define MOBILITY_COUNT_MOBILITY_H
6
7namespace osl
8{
9 namespace mobility
10 {
19 template<Player P,bool All,bool Safe>
20 inline void countMobilityBoth(const NumEffectState& state,Square pos,Offset o,int& countAll,int& countSafe){
21 assert(pos.isOnBoard());
22 assert(!o.zero());
23 Piece p;
24 for(pos+=o;(p=state.pieceAt(pos)).isEmpty();pos+=o){
25 if(All) countAll++;
26 if(Safe && !state.hasEffectAt<alt(P)>(pos))
27 countSafe++;
28 }
29 if(p.canMoveOn<P>()){
30 if(All) countAll++;
31 if(Safe && !state.hasEffectAt<alt(P)>(pos))
32 countSafe++;
33 }
34 }
35 inline void countMobilityBoth(Player P,const NumEffectState& state,Square pos,Offset o,int& countAll,int& countSafe){
36 if(P==BLACK)
37 countMobilityBoth<BLACK,true,true>(state,pos,o,countAll,countSafe);
38 else
39 countMobilityBoth<WHITE,true,true>(state,pos,o,countAll,countSafe);
40 }
44 inline int countMobilityAll(Player pl,const NumEffectState& state,Square pos,Offset o)
45 {
46 int ret=0,dummy=0;
47 if(pl==BLACK)
48 countMobilityBoth<BLACK,true,false>(state,pos,o,ret,dummy);
49 else
50 countMobilityBoth<WHITE,true,false>(state,pos,o,ret,dummy);
51 return ret;
52 }
56 inline int countMobilitySafe(Player pl,const NumEffectState& state,Square pos,Offset o)
57 {
58 int ret=0,dummy=0;
59 if(pl==BLACK)
60 countMobilityBoth<BLACK,false,true>(state,pos,o,dummy,ret);
61 else
62 countMobilityBoth<WHITE,false,true>(state,pos,o,dummy,ret);
63 return ret;
64 }
65 }
66}
67#endif /* MOBILITY_ROOK_MOBILITY_H */
68// ;;; Local Variables:
69// ;;; mode:c++
70// ;;; c-basic-offset:2
71// ;;; End:
利きを持つ局面
bool hasEffectAt(Square target) const
対象とするマスにあるプレイヤーの利きがあるかどうか.
座標の差分
Definition basic_type.h:430
bool zero() const
Definition basic_type.h:502
bool canMoveOn() const
Player Pの駒が,thisの上に移動できるか? PIECE_EMPTY 0x00008000 BLACK_PIECE 0x000XxxYY X>=2, YY>0 PIECE_EDGE 0xfff1...
Definition basic_type.h:980
const Piece pieceAt(Square sq) const
bool isOnBoard() const
盤面上を表すかどうかの判定. 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する.
Definition basic_type.h:583
void countMobilityBoth(const NumEffectState &state, Square pos, Offset o, int &countAll, int &countSafe)
P : 駒pの持ち主 All : countAllを求めるかどうか? Safe : countAllを求めるかどうか? countAll : 利きに関係なく動けるマス countSafe : 相手の利き...
int countMobilitySafe(Player pl, const NumEffectState &state, Square pos, Offset o)
相手の利きがない動けるマスを求める
int countMobilityAll(Player pl, const NumEffectState &state, Square pos, Offset o)
利きに関係なく動けるマスの数
Player
Definition basic_type.h:8
@ BLACK
Definition basic_type.h:9
constexpr Player alt(Player player)
Definition basic_type.h:13