My Project
pieceOnBoard.h
Go to the documentation of this file.
1#ifndef OSL_PIECE_ON_BOARD_H
2#define OSL_PIECE_ON_BOARD_H
4
5namespace osl
6{
7 namespace move_generator
8 {
18 template<class Action,bool noCapturePromote=false>
20 {
24 template<Player P>
25 static void generatePieceUnsafe(const NumEffectState& state,Piece p, Square target, Piece p1,Action& action)
26 {
27 assert(state.hasEffectByPiece(p, target));
28 Ptype ptype=p.ptype();
29 Square from=p.square();
30 if(canPromote(ptype)){
31 if(target.canPromote<P>()){
32 action.unknownMove(from,target,p1,promote(ptype),true,P);
33 int y=(P==BLACK ? target.y() : 10-target.y());
34 if(!Ptype_Table.isBetterToPromote(ptype) &&
35 (((ptype==LANCE || ptype==PAWN) ? y==3 : true )) &&
36 Ptype_Table.canDropTo(P,ptype,target))
37 action.unknownMove(from,target,p1,ptype,false,P);
38 }
39 else if(from.canPromote<P>()){
40 action.unknownMove(from,target,p1,promote(ptype),true,P);
42 action.unknownMove(from,target,p1,ptype,false,P);
43 }
44 else
45 action.unknownMove(from,target,p1,ptype,false,P);
46 }
47 else{
48 action.unknownMove(from,target,p1,ptype,false,P);
49 }
50 }
51 template<Player P>
52 static void generatePiece(const NumEffectState& state,Piece p, Square target, Piece p1,Action& action)
53 {
54 if(p.ptype()==KING){
55 // 王手がかかっているときには自分の影になっている手も生成してしまう
56 const Player altP=alt(P);
57// assert(!state.hasEffectAt<altP>(p.square()));
58 // 自殺手
59 if(state.hasEffectAt<altP>(target)) return;
60 }
61 if(state.pinOrOpen(P).test(p.number())){
62 Direction d=state.pinnedDir<P>(p);
64 if(primDir(d)!=primDirUnsafe(d1)) return;
65 }
66 generatePieceUnsafe<P>(state,p,target,p1,action);
67 }
72 template<Player P,Ptype T>
73 static void generatePiecePtypeUnsafe(const NumEffectState& state,Piece p, Square target, Piece p1,Action& action)
74 {
75 assert(state.hasEffectByPiece(p, target));
76 assert(p.ptype()==T);
77// Ptype ptype=p.ptype();
78 Square from=p.square();
79 if(canPromote(T) & (target.canPromote<P>() || from.canPromote<P>())){
80 action.unknownMove(from,target,p1,promote(T),true,P);
81 if(((T==PAWN || T==LANCE) &&
82 (P==BLACK ? target.y()==1 : target.y()==9))||
83 (T==KNIGHT && (P==BLACK ? target.y()<=2 : target.y()>=8)))
84 return;
85 if((T==ROOK || T==BISHOP || T==PAWN ||
86 (T==LANCE && (P==BLACK ? target.y()==2 : target.y()==8))))
87 return;
88 }
89 action.unknownMove(from,target,p1,T,false,P);
90 }
91 template<Player P,Ptype T>
92 static void generatePiecePtype(const NumEffectState& state,Piece p, Square target, Piece p1,Action& action)
93 {
94 if(T==KING){
95 assert(!state.hasEffectAt(alt(P),p.square()));
96 if(state.hasEffectAt(alt(P),target)) return;
97 }
98 else if(state.pin(P).test(p.number())){
99 Direction d=state.pinnedDir<P>(p);
101 if(primDir(d)!=primDirUnsafe(d1)) return;
102 }
103 generatePiecePtypeUnsafe<P,T>(state,p,target,p1,action);
104 }
113 template <Player P,Ptype T,bool useDirMask>
114 static void generatePtype(const NumEffectState& state,Piece p, Action& action,int dirMask=0);
115
116 template <Player P,Ptype T>
117 static void generatePtype(const NumEffectState& state,Piece p, Action& action)
118 {
119 int dummy=0;
120 generatePtype<P,T,false>(state,p,action,dummy);
121 }
130 template <Player P,Ptype T,bool useDirMask>
131 static void generatePtypeUnsafe(const NumEffectState& state,Piece p, Action& action,int dirMask);
132 template <Player P,Ptype T>
133 static void generatePtypeUnsafe(const NumEffectState& state,Piece p, Action& action)
134 {
135 int dummy=0;
136 generatePtypeUnsafe<P,T,false>(state,p,action,dummy);
137 }
138
146 template <Player P,bool useDirMask>
147 static void generate(const NumEffectState& state,Piece p, Action& action,int dirMask=0);
148 };
149
151 {
152 static void generate(Player turn, const NumEffectState& state, Piece target,
153 MoveVector&);
154 };
155 } // namespace move_generator
157} // namespace osl
158
159#endif /* OSL_PIECE_ON_BOARD_H */
160// ;;; Local Variables:
161// ;;; mode:c++
162// ;;; c-basic-offset:2
163// ;;; End:
Direction getShort8Unsafe(Square from, Square to) const
8方向にいない場合も適当なものを返す.
Definition boardTable.h:134
利きを持つ局面
Direction pinnedDir(Piece p) const
pinされた駒がPのKingから見てどの方向か? Pから見たdirectionを返す
bool hasEffectByPiece(Piece attack, Square target) const
駒attack が target に利きを持つか (旧hasEffectToと統合)
bool hasEffectAt(Square target) const
対象とするマスにあるプレイヤーの利きがあるかどうか.
const PieceMask pin(Player king) const
PieceMask pinOrOpen(Player king) const
bool test(int num) const
Definition pieceMask.h:45
Ptype ptype() const
Definition basic_type.h:821
const Square square() const
Definition basic_type.h:832
int number() const
Definition basic_type.h:828
bool isBetterToPromote(Ptype ptype) const
Definition ptypeTable.h:58
bool canDropTo(Player pl, Ptype ptype, Square pos) const
Definition ptypeTable.h:68
int y() const
将棋としてのY座標を返す.
Definition basic_type.h:567
bool canPromote() const
Definition basic_type.h:659
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
@ ROOK
Definition basic_type.h:100
@ BISHOP
Definition basic_type.h:99
@ PAWN
Definition basic_type.h:95
@ KING
Definition basic_type.h:93
@ KNIGHT
Definition basic_type.h:97
@ LANCE
Definition basic_type.h:96
const PtypeTable Ptype_Table
Definition tables.cc:97
bool canPromote(Ptype ptype)
ptypeがpromote可能な型かどうかのチェック promote済みの場合はfalseを返す
Definition basic_type.h:147
const BoardTable Board_Table
Definition tables.cc:95
constexpr Direction primDirUnsafe(Direction d)
8方向について,primitiveな4方向を求める dとしてknight, INVALIDなども来る
Definition basic_type.h:374
Direction
Definition basic_type.h:310
Player
Definition basic_type.h:8
@ BLACK
Definition basic_type.h:9
constexpr Direction primDir(Direction d)
8方向について,primitiveな4方向を求める
Definition basic_type.h:366
constexpr Player alt(Player player)
Definition basic_type.h:13
Ptype promote(Ptype ptype)
promote可能なptypeに対して,promote後の型を返す promote不可のptypeを与えてはいけない.
Definition basic_type.h:173
static void generate(Player turn, const NumEffectState &state, Piece target, MoveVector &)
特定のpieceを動かす手を生成
static void generatePtype(const NumEffectState &state, Piece p, Action &action, int dirMask=0)
Generate moves without stating the Ptype as template param.
static void generatePiece(const NumEffectState &state, Piece p, Square target, Piece p1, Action &action)
static void generate(const NumEffectState &state, Piece p, Action &action, int dirMask=0)
Generate moves without stating the Ptype as template param.
static void generatePtypeUnsafe(const NumEffectState &state, Piece p, Action &action, int dirMask)
Generate moves without stating the Ptype as template param.
static void generatePtypeUnsafe(const NumEffectState &state, Piece p, Action &action)
static void generatePtype(const NumEffectState &state, Piece p, Action &action)
static void generatePiecePtype(const NumEffectState &state, Piece p, Square target, Piece p1, Action &action)
static void generatePieceUnsafe(const NumEffectState &state, Piece p, Square target, Piece p1, Action &action)
駒pがマスtargetに利きをもっているとして,手を生成する.
static void generatePiecePtypeUnsafe(const NumEffectState &state, Piece p, Square target, Piece p1, Action &action)
PtypeがTの駒pがマスtargetに利きをもっているとして,手を生成する. p1 - targetにある駒