alwaysMove.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
alwaysMove.h
Go to the documentation of this file.
1 #ifndef _ALWAYS_MOVE_ACTION
2 #define _ALWAYS_MOVE_ACTION
3 #include "osl/player.h"
4 #include "osl/ptype.h"
5 #include "osl/ptypeTable.h"
6 #include "osl/ptypeTraits.h"
7 #include "osl/piece.h"
8 #include "osl/move_action/concept.h"
9
10 namespace osl
11 {
12 namespace effect_action
13 {
17 template<class Action>
18 class AlwaysMove
19 {
20 BOOST_CLASS_REQUIRE(Action,osl::move_action,Concept);
21 private:
22 const NumEffectState& state;
23 Action& ac;
24 public:
25 AlwaysMove(const NumEffectState& s, Action & a) : state(s), ac(a) {}
29 template<Player P,Ptype Type>
30 void doActionPtype(Piece p1,Square to){
31 assert(Type == unpromote(p1.ptype()));
32 Square from=p1.square();
33 if (canPromote(Type) &&
34 !p1.isPromotedNotKingGold() &&
35 (to.canPromote<P>() || from.canPromote<P>())){
36 ac.unknownMove(from,to,state.pieceAt(to),promote(Type),true,P);
37 }
38 if (!canPromote(Type) ||
39 PtypePlayerTraits<Type,P>::canDropTo(to) ||
40 p1.isPromotedNotKingGold()){
41 ac.unknownMove(from,to,state.pieceAt(to),p1.ptype(),false,P);
42 }
43 }
47 template<Player P>
48 void doAction(Piece p1,Square to)
49 {
50 Square from=p1.square();
51 Ptype ptype=p1.ptype();
52 if(canPromote(ptype))
53 {
54 if (to.canPromote<P>())
55 {
56 ac.unknownMove(from,to,state.pieceAt(to),promote(ptype),true,P);
57 if(Ptype_Table.canDropTo(P, ptype,to))
58 {
59 ac.unknownMove(from,to,state.pieceAt(to),ptype,false,P);
60 }
61 }
62 else if (from.canPromote<P>())
63 {
64 ac.unknownMove(from,to,state.pieceAt(to),promote(ptype),true,P);
65 ac.unknownMove(from,to,state.pieceAt(to),ptype,false,P);
66 }
67 else
68 {
69 ac.unknownMove(from,to,state.pieceAt(to),ptype,false,P);
70 }
71 }
72 else
73 {
74 ac.unknownMove(from,to,state.pieceAt(to),ptype,false,P);
75 }
76 }
77 bool done() const{ return false; }
78 };
79 } // namespace effect_action
80 } // namespace osl
81 #endif // _ALWAYS_MOVE_ACTION
82 // ;;; Local Variables:
83 // ;;; mode:c++
84 // ;;; c-basic-offset:2
85 // ;;; End: