betterToPromote.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
betterToPromote.h
Go to the documentation of this file.
1 #ifndef OSL_BETTER_TO_PROMOTE_MOVE_ACTION_H
2 #define OSL_BETTER_TO_PROMOTE_MOVE_ACTION_H
3 #include "osl/move_action/concept.h"
4 namespace osl
5 {
6 namespace effect_action
7 {
11 template<class Action>
12 class BetterToPromote
13 {
14 BOOST_CLASS_REQUIRE(Action,osl::move_action,Concept);
15 private:
16 const NumEffectState& state;
17 Action & ac;
18 public:
19 BetterToPromote(const NumEffectState& s, Action& a)
20 : state(s), ac(a)
21 {
22 }
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 Piece target = state.pieceAt(to);
28 if (canPromote(Type) &&
29 !p1.isPromotedNotKingGold() &&
30 (to.canPromote<P>() || from.canPromote<P>())){
31 ac.unknownMove(from,to,target,promote(Type),true,P);
32 }
33 if (!canPromote(Type) ||
34 PtypePlayerTraits<Type,P>::canDropTo(to) ||
35 p1.isPromotedNotKingGold()){
36 if (! (to.canPromote<P>() || from.canPromote<P>())
37 || (! PtypeTraits<Type>::betterToPromote
38 && (p1.ptype() != LANCE
39 || PtypePlayerTraits<LANCE,P>::canDropTo(to + DirectionPlayerTraits<U,P>::offset()))))
40 ac.unknownMove(from,to,target,p1.ptype(),false,P);
41 }
42 }
46 template<Player P>
47 void doAction(Piece p1,Square to)
48 {
49 Square from=p1.square();
50 Ptype ptype=p1.ptype();
51 Piece target = state.pieceAt(to);
52 if(canPromote(ptype))
53 {
54 if (to.canPromote<P>())
55 {
56 ac.unknownMove(from,to,target,promote(ptype),true,P);
57 if(Ptype_Table.canDropTo(P, ptype,to)
58 && ! Ptype_Table.isBetterToPromote(ptype)
59 && (ptype != LANCE
60 || PtypePlayerTraits<LANCE,P>::canDropTo(to + DirectionPlayerTraits<U,P>::offset())))
61
62 {
63 ac.unknownMove(from,to,target,ptype,false,P);
64 }
65 return;
66 }
67 if (from.canPromote<P>())
68 {
69 ac.unknownMove(from,to,target,promote(ptype),true,P);
70 if(! Ptype_Table.isBetterToPromote(ptype)
71 && (ptype != LANCE
72 || PtypePlayerTraits<LANCE,P>::canDropTo(to + DirectionPlayerTraits<U,P>::offset())))
73 ac.unknownMove(from,to,target,ptype,false,P);
74 return;
75 }
76 // fall through
77 }
78 ac.unknownMove(from,to,target,ptype,false,P);
79 }
80 };
81 } // namespace effect_action
82 } // namespace osl
83 #endif // OSL_BETTER_TO_PROMOTE_MOVE_ACTION_H
84 // ;;; Local Variables:
85 // ;;; mode:c++
86 // ;;; c-basic-offset:2
87 // ;;; End: