My Project
effect_action.h
Go to the documentation of this file.
1 #ifndef OSL_EFFECT_ACTION
2 #define OSL_EFFECT_ACTION
3 #include "osl/numEffectState.h"
4 
5 namespace osl
6 {
7  namespace effect_action
8  {
12  template<class Action>
13  class AlwaysMove
14  {
15  private:
17  Action& ac;
18  public:
19  AlwaysMove(const NumEffectState& s, Action & a) : state(s), ac(a) {}
23  template<Player P,Ptype Type>
24  void doActionPtype(Piece p1,Square to){
25  assert(Type == unpromote(p1.ptype()));
26  Square from=p1.square();
27  if (canPromote(Type) &&
28  !p1.isPromotedNotKingGold() &&
29  (to.canPromote<P>() || from.canPromote<P>())){
30  ac.unknownMove(from,to,state.pieceAt(to),promote(Type),true,P);
31  }
32  if (!canPromote(Type) ||
35  ac.unknownMove(from,to,state.pieceAt(to),p1.ptype(),false,P);
36  }
37  }
41  template<Player P>
42  void doAction(Piece p1,Square to)
43  {
44  Square from=p1.square();
45  Ptype ptype=p1.ptype();
46  if(canPromote(ptype))
47  {
48  if (to.canPromote<P>())
49  {
50  ac.unknownMove(from,to,state.pieceAt(to),promote(ptype),true,P);
51  if(Ptype_Table.canDropTo(P, ptype,to))
52  {
53  ac.unknownMove(from,to,state.pieceAt(to),ptype,false,P);
54  }
55  }
56  else if (from.canPromote<P>())
57  {
58  ac.unknownMove(from,to,state.pieceAt(to),promote(ptype),true,P);
59  ac.unknownMove(from,to,state.pieceAt(to),ptype,false,P);
60  }
61  else
62  {
63  ac.unknownMove(from,to,state.pieceAt(to),ptype,false,P);
64  }
65  }
66  else
67  {
68  ac.unknownMove(from,to,state.pieceAt(to),ptype,false,P);
69  }
70  }
71  bool done() const{ return false; }
72  };
73 
77  template<class Action>
79  {
80  private:
82  Action & ac;
83  public:
84  BetterToPromote(const NumEffectState& s, Action& a)
85  : state(s), ac(a)
86  {
87  }
88  template<Player P,Ptype Type>
89  void doActionPtype(Piece p1,Square to){
90  assert(Type == unpromote(p1.ptype()));
91  Square from=p1.square();
92  Piece target = state.pieceAt(to);
93  if (canPromote(Type) &&
94  !p1.isPromotedNotKingGold() &&
95  (to.canPromote<P>() || from.canPromote<P>())){
96  ac.unknownMove(from,to,target,promote(Type),true,P);
97  }
98  if (!canPromote(Type) ||
100  p1.isPromotedNotKingGold()){
101  if (! (to.canPromote<P>() || from.canPromote<P>())
103  && (p1.ptype() != LANCE
105  ac.unknownMove(from,to,target,p1.ptype(),false,P);
106  }
107  }
111  template<Player P>
112  void doAction(Piece p1,Square to)
113  {
114  Square from=p1.square();
115  Ptype ptype=p1.ptype();
116  Piece target = state.pieceAt(to);
117  if(canPromote(ptype))
118  {
119  if (to.canPromote<P>())
120  {
121  ac.unknownMove(from,to,target,promote(ptype),true,P);
122  if(Ptype_Table.canDropTo(P, ptype,to)
123  && ! Ptype_Table.isBetterToPromote(ptype)
124  && (ptype != LANCE
126 
127  {
128  ac.unknownMove(from,to,target,ptype,false,P);
129  }
130  return;
131  }
132  if (from.canPromote<P>())
133  {
134  ac.unknownMove(from,to,target,promote(ptype),true,P);
135  if(! Ptype_Table.isBetterToPromote(ptype)
136  && (ptype != LANCE
138  ac.unknownMove(from,to,target,ptype,false,P);
139  return;
140  }
141  // fall through
142  }
143  ac.unknownMove(from,to,target,ptype,false,P);
144  }
145  };
146 
150  struct StorePiece
151  {
153  explicit StorePiece(PieceVector *s) : store(s)
154  {
155  }
156  template<Player P,Ptype Type>
158  {
159  doAction<P>(p, pos);
160  }
161  template<Player P>
163  {
164  store->push_back(p);
165  }
166  };
167 
172  {
176  : out(s), target(t)
177  {
178  }
179  template<Player P,Ptype Type>
181  {
182  store(p);
183  }
184  template<Player P>
186  {
187  store(p);
188  }
189 
190  void store(Piece p)
191  {
192  const PtypeO ptypeO = p.ptypeO();
193  out->push_back(std::make_pair(ptypeO, p.square()));
194  }
195  };
196  } // namespace effect_action
197 } // namespace osl
198 #endif // OSL_EFFECT_ACTION
199 // ;;; Local Variables:
200 // ;;; mode:c++
201 // ;;; c-basic-offset:2
202 // ;;; End:
void push_back(const T &e)
Definition: container.h:204
利きを持つ局面
PtypeO ptypeO() const
Definition: basic_type.h:824
Ptype ptype() const
Definition: basic_type.h:821
const Square square() const
Definition: basic_type.h:832
bool isPromotedNotKingGold() const
Definition: basic_type.h:908
bool isBetterToPromote(Ptype ptype) const
Definition: ptypeTable.h:58
bool canDropTo(Player pl, Ptype ptype, Square pos) const
Definition: ptypeTable.h:68
const Piece pieceAt(Square sq) const
Definition: simpleState.h:167
bool canPromote() const
Definition: basic_type.h:659
全ての指手を生成
Definition: effect_action.h:14
AlwaysMove(const NumEffectState &s, Action &a)
Definition: effect_action.h:19
const NumEffectState & state
Definition: effect_action.h:16
void doAction(Piece p1, Square to)
Ptypeをtemplate引数にできない場合
Definition: effect_action.h:42
void doActionPtype(Piece p1, Square to)
Ptypeをtemplate引数にできる場合
Definition: effect_action.h:24
成った方が良い駒は成る手のみ生成
Definition: effect_action.h:79
void doAction(Piece p1, Square to)
Ptypeをtemplate引数にできない場合
void doActionPtype(Piece p1, Square to)
Definition: effect_action.h:89
BetterToPromote(const NumEffectState &s, Action &a)
Definition: effect_action.h:84
const NumEffectState & state
Definition: effect_action.h:81
Ptype
駒の種類を4ビットでコード化する
Definition: basic_type.h:84
@ 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
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す
Definition: basic_type.h:157
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
Definition: basic_type.h:199
Ptype promote(Ptype ptype)
promote可能なptypeに対して,promote後の型を返す promote不可のptypeを与えてはいけない.
Definition: basic_type.h:173
PieceVector に格納
void doActionPtype(Piece p, Square pos)
void doAction(Piece p, Square)
PtypeOSquareVector に格納
StorePtypeOSquare(PtypeOSquareVector *s, Square t)