Debian Codegraph @

old-sample/legacy-checkmate/lib/safeFilter.h

raw
1 /* safeFilter.h
2 */
3 #ifndef _MOVE_ACTION_SAFE_FILTER_H
4 #define _MOVE_ACTION_SAFE_FILTER_H
5 #include "osl/state/numEffectState.h"
6 #include "osl/move_action/concept.h"
7 #include "osl/move_classifier/safeMove.h"
8 namespace osl
9 {
10 namespace move_action
11 {
12
13 /**
14 * 自玉に王手がかかっていない状況から
15 * 着手して自殺手になる手を除く
16 */
17 template<Player P,class OrigAction>
18 struct SafeFilter
19 {
20 BOOST_CLASS_REQUIRE(OrigAction,osl::move_action,Concept);
21 const NumEffectState& state;
22 OrigAction & action;
23 public:
24 SafeFilter(const NumEffectState& s, OrigAction & action)
25 : state(s), action(action) {
26 assert(state.template kingSquare<P>().isPieceStand()
27 || !state.template
28 hasEffectAt<PlayerTraits<P>::opponent>(state.template
29 kingSquare<P>())
30 || (state.dump(), 0));
31 }
32 bool isSafeMove(Ptype ptype,Square from,Square to)
33 {
34 return move_classifier::SafeMove<P>::isMember(state, ptype, from, to);
35 }
36 void simpleMove(Square from,Square to,Ptype ptype, bool isPromote,Player
37 #ifndef NDEBUG
38 p
39 #endif
40 ){
41 assert(p == P);
42 if(isSafeMove(ptype,from,to))
43 action.simpleMove(from,to,ptype,isPromote,P);
44
45 }
46 void unknownMove(Square from,Square to,Piece p1,Ptype ptype,bool isPromote,Player
47 #ifndef NDEBUG
48 p
49 #endif
50 ){
51 assert(p == P);
52 if(isSafeMove(ptype,from,to))
53 action.unknownMove(from,to,p1,ptype,isPromote,P);
54 }
55 /**
56 * dropMoveが自殺手になることはない
57 */
58 void dropMove(Square to,Ptype ptype,Player
59 #ifndef NDEBUG
60 p
61 #endif
62 ){
63 assert(p == P);
64 action.dropMove(to,ptype,P);
65 }
66 };
67 } // namespace move_action
68 } // namespace osl
69
70 #endif /* _MOVE_ACTION_SAFE_FILTER_H */
71 // ;;; Local Variables:
72 // ;;; mode:c++
73 // ;;; c-basic-offset:2
74 // ;;; End: