My Project
rookMobility.h
Go to the documentation of this file.
1/* rookMobility.h
2 */
3#ifndef MOBILITY_ROOK_MOBILITY_H
4#define MOBILITY_ROOK_MOBILITY_H
7
8namespace osl
9{
10 namespace mobility
11 {
16 {
17 public:
25 template<Player P>
26 static void countVerticalBoth(const NumEffectState& state,Piece p,int& countAll,int& countSafe){
27 assert(p.ptype()==ROOK || p.ptype()==PROOK);
28 assert(p.isOnBoard());
29 assert(p.owner()==P);
30 const Square pos=p.square();
31 countMobilityBoth(P,state,pos,DirectionPlayerTraits<U,P>::offset(),countAll,countSafe);
32 countMobilityBoth(P,state,pos,DirectionPlayerTraits<D,P>::offset(),countAll,countSafe);
33 }
34 static void countVerticalBoth(Player pl,const NumEffectState& state,Piece p,int& countAll,int& countSafe){
35 if(pl==BLACK)
36 countVerticalBoth<BLACK>(state,p,countAll,countSafe);
37 else
38 countVerticalBoth<WHITE>(state,p,countAll,countSafe);
39 }
43 template<Player P>
44 static int countVerticalAll(const NumEffectState& state,int num){
45 // const Square pos=p.square();
46 const Square posU=state.mobilityOf(U,num);
47 const Square posD=state.mobilityOf(D,num);
48 int count=posD.y()-posU.y()-2+
49 (state.pieceAt(posU).template canMoveOn<P>() ? 1 : 0)+
50 (state.pieceAt(posD).template canMoveOn<P>() ? 1 : 0);
51 return count;
52 }
53 template<Player P>
54 static int countVerticalAll(const NumEffectState& state,Piece p){
55 return countVerticalAll<P>(state,p.number());
56 }
57 static int countVerticalAll(Player pl,const NumEffectState& state,Piece p){
58 if(pl==BLACK)
59 return countVerticalAll<BLACK>(state,p);
60 else
61 return countVerticalAll<WHITE>(state,p);
62 }
66 template<Player P>
67 static int countVerticalSafe(const NumEffectState& state,Piece p){
68 const Square pos=p.square();
69 return
72 }
73 static int countVerticalSafe(Player pl,const NumEffectState& state,Piece p){
74 if(pl==BLACK)
75 return countVerticalSafe<BLACK>(state,p);
76 else
77 return countVerticalSafe<WHITE>(state,p);
78 }
86 template<Player P>
87 static void countHorizontalBoth(const NumEffectState& state,Piece p,int& countAll,int& countSafe){
88 assert(p.ptype()==ROOK || p.ptype()==PROOK);
89 assert(p.isOnBoard());
90 assert(p.owner()==P);
91 const Square pos=p.square();
92 countMobilityBoth(P,state,pos,DirectionPlayerTraits<L,P>::offset(),countAll,countSafe);
93 countMobilityBoth(P,state,pos,DirectionPlayerTraits<R,P>::offset(),countAll,countSafe);
94 }
95 static void countHorizontalBoth(Player pl,const NumEffectState& state,Piece p,int& countAll,int& countSafe){
96 if(pl==BLACK)
97 countHorizontalBoth<BLACK>(state,p,countAll,countSafe);
98 else
99 countHorizontalBoth<WHITE>(state,p,countAll,countSafe);
100 }
101
102 template<Player P>
103 static int countHorizontalAll(const NumEffectState& state,int num)
104 {
105 const Square posR=state.mobilityOf(R,num);
106 const Square posL=state.mobilityOf(L,num);
107 int count=(posL.x()-posR.x()-2)+
108 (state.pieceAt(posR).template canMoveOn<P>() ? 1 : 0)+
109 (state.pieceAt(posL).template canMoveOn<P>() ? 1 : 0);
110 return count;
111 }
115 template<Player P>
116 static int countHorizontalAll(const NumEffectState& state,Piece p){
117 return countHorizontalAll<P>(state,p.number());
118 }
119 static int countHorizontalAll(Player pl,const NumEffectState& state,Piece p){
120 if(pl==BLACK)
121 return countHorizontalAll<BLACK>(state,p);
122 else
123 return countHorizontalAll<WHITE>(state,p);
124 }
128 template<Player P>
129 static int countHorizontalSafe(const NumEffectState& state,Piece p){
130 const Square pos=p.square();
131 return
134 }
135 static int countHorizontalSafe(Player pl,const NumEffectState& state,Piece p){
136 if(pl==BLACK)
137 return countHorizontalSafe<BLACK>(state,p);
138 else
139 return countHorizontalSafe<WHITE>(state,p);
140 }
141 };
142 }
143}
144#endif /* MOBILITY_ROOK_MOBILITY_H */
145// ;;; Local Variables:
146// ;;; mode:c++
147// ;;; c-basic-offset:2
148// ;;; End:
利きを持つ局面
Square mobilityOf(Direction d, int num) const
Ptype ptype() const
Definition basic_type.h:821
const Square square() const
Definition basic_type.h:832
Player owner() const
Definition basic_type.h:963
int number() const
Definition basic_type.h:828
bool isOnBoard() const
Definition basic_type.h:985
const Piece pieceAt(Square sq) const
int y() const
将棋としてのY座標を返す.
Definition basic_type.h:567
int x() const
将棋としてのX座標を返す.
Definition basic_type.h:563
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)
相手の利きがない動けるマスを求める
@ ROOK
Definition basic_type.h:100
@ PROOK
Definition basic_type.h:92
Player
Definition basic_type.h:8
@ BLACK
Definition basic_type.h:9
盤上の飛車および竜の動けるマス
static int countHorizontalAll(Player pl, const NumEffectState &state, Piece p)
static int countHorizontalAll(const NumEffectState &state, int num)
static int countHorizontalSafe(Player pl, const NumEffectState &state, Piece p)
static int countVerticalAll(const NumEffectState &state, int num)
縦方向,利きに関係なく動けるマスの数
static int countHorizontalAll(const NumEffectState &state, Piece p)
横方向,利きに関係なく動けるマスの数
static void countVerticalBoth(const NumEffectState &state, Piece p, int &countAll, int &countSafe)
縦方向, P : 駒pの持ち主 countAll : 利きに関係なく動けるマス countSafe : 相手の利きがない動けるマス 両方を求める
static int countVerticalAll(Player pl, const NumEffectState &state, Piece p)
static void countVerticalBoth(Player pl, const NumEffectState &state, Piece p, int &countAll, int &countSafe)
static void countHorizontalBoth(Player pl, const NumEffectState &state, Piece p, int &countAll, int &countSafe)
static int countVerticalSafe(Player pl, const NumEffectState &state, Piece p)
static int countHorizontalSafe(const NumEffectState &state, Piece p)
横方向,相手の利きがない動けるマスを求める
static int countVerticalSafe(const NumEffectState &state, Piece p)
縦方向,相手の利きがない動けるマスを求める
static void countHorizontalBoth(const NumEffectState &state, Piece p, int &countAll, int &countSafe)
横方向, P : 駒pの持ち主 countAll : 利きに関係なく動けるマス countSafe : 相手の利きがない動けるマス 両方を求める
static int countVerticalAll(const NumEffectState &state, Piece p)