00001
00002
00003 #ifndef _MOVE_ACTION_SAFE_FILTER_H
00004 #define _MOVE_ACTION_SAFE_FILTER_H
00005 #include "osl/position.h"
00006 #include "osl/player.h"
00007 #include "osl/ptype.h"
00008 #include "osl/move_action/concept.h"
00009 #include "osl/move_classifier/safeMove.h"
00010 namespace osl
00011 {
00012 namespace move_action
00013 {
00014
00019 template<Player P,class State,class OrigAction>
00020 struct SafeFilter
00021 {
00022 BOOST_CLASS_REQUIRE(OrigAction,osl::move_action,Concept);
00023 const State& state;
00024 OrigAction & action;
00025 public:
00026 SafeFilter(const State& s, OrigAction & action)
00027 : state(s), action(action) {
00028 assert(state.template getKingPosition<P>().isPieceStand()
00029 || !state.template
00030 hasEffectBy<PlayerTraits<P>::opponent>(state.template
00031 getKingPosition<P>())
00032 || (state.dump(), 0));
00033 }
00034 bool isSafeMove(Ptype ptype,Position from,Position to)
00035 {
00036 return move_classifier::SafeMove<P>::isMember(state, ptype, from, to);
00037 }
00038 void simpleMove(Position from,Position to,Ptype ptype, bool isPromote,Player
00039 #ifndef NDEBUG
00040 p
00041 #endif
00042 ){
00043 assert(p == P);
00044 if(isSafeMove(ptype,from,to))
00045 action.simpleMove(from,to,ptype,isPromote,P);
00046
00047 }
00048 void unknownMove(Position from,Position to,Piece p1,Ptype ptype,bool isPromote,Player
00049 #ifndef NDEBUG
00050 p
00051 #endif
00052 ){
00053 assert(p == P);
00054 if(isSafeMove(ptype,from,to))
00055 action.unknownMove(from,to,p1,ptype,isPromote,P);
00056 }
00060 void dropMove(Position to,Ptype ptype,Player
00061 #ifndef NDEBUG
00062 p
00063 #endif
00064 ){
00065 assert(p == P);
00066 action.dropMove(to,ptype,P);
00067 }
00068 };
00069 }
00070 }
00071
00072 #endif
00073
00074
00075
00076