My Project
bishopMobility.h
Go to the documentation of this file.
1/* bishopMobility.h
2 */
3#ifndef MOBILITY_BISHOP_MOBILITY_H
4#define MOBILITY_BISHOP_MOBILITY_H
6#include <cstdlib>
7
8namespace osl
9{
10 namespace mobility
11 {
16 {
17 public:
25 template<Player P>
26 static void countBoth(const NumEffectState& state,Piece p,int& countAll,int& countSafe){
27 assert(p.ptype()==BISHOP || p.ptype()==PBISHOP);
28 assert(p.isOnBoard());
29 assert(p.owner()==P);
30 const Square pos=p.square();
31 countMobilityBoth<P,true,true>(state,pos,DirectionPlayerTraits<UL,P>::offset(),countAll,countSafe);
32 countMobilityBoth<P,true,true>(state,pos,DirectionPlayerTraits<UR,P>::offset(),countAll,countSafe);
33 countMobilityBoth<P,true,true>(state,pos,DirectionPlayerTraits<DL,P>::offset(),countAll,countSafe);
34 countMobilityBoth<P,true,true>(state,pos,DirectionPlayerTraits<DR,P>::offset(),countAll,countSafe);
35 }
36 static void countBoth(Player pl,const NumEffectState& state,Piece p,int& countAll,int& countSafe){
37 if(pl==BLACK)
38 countBoth<BLACK>(state,p,countAll,countSafe);
39 else
40 countBoth<WHITE>(state,p,countAll,countSafe);
41 }
45 template<Player P>
46 static int countAll(const NumEffectState& state,int num){
47 const Square posUL=state.mobilityOf(UL,num);
48 const Square posUR=state.mobilityOf(UR,num);
49 const Square posDL=state.mobilityOf(DL,num);
50 const Square posDR=state.mobilityOf(DR,num);
51 int count=posDR.y()-posUL.y()+
52 posDL.y()-posUR.y()-4+
53 (state.pieceAt(posUR).template canMoveOn<P>() ? 1 : 0)+
54 (state.pieceAt(posDR).template canMoveOn<P>() ? 1 : 0)+
55 (state.pieceAt(posUL).template canMoveOn<P>() ? 1 : 0)+
56 (state.pieceAt(posDL).template canMoveOn<P>() ? 1 : 0);
57 return count;
58 }
59 template<Player P>
60 static int countAll(const NumEffectState& state,Piece p){
61 assert(p.ptype()==BISHOP || p.ptype()==PBISHOP);
62 assert(p.isOnBoard());
63 assert(p.owner()==P);
64 return countAll<P>(state,p.number());
65 }
66 static int countAll(Player pl,const NumEffectState& state,Piece p){
67 if(pl==BLACK)
68 return countAll<BLACK>(state,p);
69 else
70 return countAll<WHITE>(state,p);
71 }
72
73 template<Player P, Direction Dir>
74 static int countAllDir(const NumEffectState& state,Piece p){
75 assert(p.ptype()==BISHOP || p.ptype()==PBISHOP);
76 assert(p.isOnBoard());
77 assert(p.owner()==P);
78 assert(Dir == UL || Dir == UR || Dir == DL || Dir == DR);
79 Direction dir = (P == BLACK ? Dir : inverse(Dir));
80 const Square pos = state.mobilityOf(dir, p.number());
81 int count = std::abs(pos.y() - p.square().y())
82 - 1 + (state.pieceAt(pos).template canMoveOn<P>() ? 1 : 0);
83 return count;
84 }
85 template <Direction dir>
86 static int countAllDir(Player pl,const NumEffectState& state,Piece p){
87 if(pl==BLACK)
88 return countAllDir<BLACK, dir>(state,p);
89 else
90 return countAllDir<WHITE, dir>(state,p);
91 }
95 template<Player P>
96 static int countSafe(const NumEffectState& state,Piece p){
97 assert(p.ptype()==BISHOP || p.ptype()==PBISHOP);
98 assert(p.isOnBoard());
99 assert(p.owner()==P);
100 const Square pos=p.square();
101 return
106 }
107 static int countSafe(Player pl,const NumEffectState& state,Piece p){
108 if(pl==BLACK)
109 return countSafe<BLACK>(state,p);
110 else
111 return countSafe<WHITE>(state,p);
112 }
113 };
114 }
115}
116#endif /* MOBILITY_BISHOP_MOBILITY_H */
117// ;;; Local Variables:
118// ;;; mode:c++
119// ;;; c-basic-offset:2
120// ;;; 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 countMobilitySafe(Player pl, const NumEffectState &state, Square pos, Offset o)
相手の利きがない動けるマスを求める
@ BISHOP
Definition basic_type.h:99
@ PBISHOP
Definition basic_type.h:91
Direction
Definition basic_type.h:310
Player
Definition basic_type.h:8
@ BLACK
Definition basic_type.h:9
constexpr Direction inverse(Direction d)
Definition basic_type.h:358
盤上の角および馬が動けるマスの数を数える
static int countAllDir(const NumEffectState &state, Piece p)
static int countAllDir(Player pl, const NumEffectState &state, Piece p)
static void countBoth(Player pl, const NumEffectState &state, Piece p, int &countAll, int &countSafe)
static void countBoth(const NumEffectState &state, Piece p, int &countAll, int &countSafe)
斜め方向, P : 駒pの持ち主 countAll : 利きに関係なく動けるマス countSafe : 相手の利きがない動けるマス 両方を求める
static int countAll(Player pl, const NumEffectState &state, Piece p)
static int countSafe(const NumEffectState &state, Piece p)
斜め方向,相手の利きがない動けるマスを求める
static int countAll(const NumEffectState &state, Piece p)
static int countAll(const NumEffectState &state, int num)
斜め方向,利きに関係なく動けるマスの数
static int countSafe(Player pl, const NumEffectState &state, Piece p)