00001
00002
00003 #ifndef OSL_MOVEACTION_H
00004 #define OSL_MOVEACTION_H
00005 #include "osl/numEffectState.h"
00006 #include "osl/move_classifier/kingOpenMove.h"
00007
00008 namespace osl
00009 {
00010 namespace move_action
00011 {
00015 struct Store
00016 {
00017 FixedCapacityVectorPushBack<Move> moves;
00018 template <size_t Capacity>
00019 explicit Store(FixedCapacityVector<Move, Capacity>& v)
00020 : moves(v.pushBackHelper())
00021 {
00022 }
00024 void simpleMove(Square ,Square ,Ptype , bool ,Player ,Move move){
00025 assert(move.isValid());
00026 moves.push_back(move);
00027 }
00037 void unknownMove(Square ,Square ,Piece ,Ptype ,bool ,Player ,Move move)
00038 {
00039 assert(move.isValid());
00040 moves.push_back(move);
00041 }
00043 void dropMove(Square ,Ptype ,Player ,Move move)
00044 {
00045 assert(move.isValid());
00046 moves.push_back(move);
00047 }
00048
00049 void simpleMove(Square from,Square to,Ptype ptype,
00050 bool isPromote,Player p)
00051 {
00052 simpleMove(from,to,ptype,isPromote,p,
00053 Move(from,to,ptype,PTYPE_EMPTY,isPromote,p));
00054 }
00055 void unknownMove(Square from,Square to,Piece captured,
00056 Ptype ptype,bool isPromote,Player p)
00057 {
00058 unknownMove(from,to,captured,ptype,isPromote,p,
00059 Move(from,to,ptype,captured.ptype(),isPromote,p));
00060 }
00061 void dropMove(Square to,Ptype ptype,Player p)
00062 {
00063 dropMove(to,ptype,p,
00064 Move(to,ptype,p));
00065 }
00066 };
00067
00071 template<Player P,class OrigAction>
00072 class NoEffectFilter
00073 {
00074 const NumEffectState& state;
00075 OrigAction & action;
00076 Square removed;
00077 public:
00078 NoEffectFilter(const NumEffectState& s, OrigAction & action,Square pos) : state(s), action(action),removed(pos) {}
00079 void simpleMove(Square from,Square to,Ptype ptype, bool isPromote,Player ,Move m){
00080 if(!state.template hasEffectByWithRemove<alt(P)>(to,removed))
00081 action.simpleMove(from,to,ptype,isPromote,P,m);
00082 }
00083 void unknownMove(Square from,Square to,Piece p1,Ptype ptype,bool isPromote,Player ,Move m){
00084 if(!state.template hasEffectByWithRemove<alt(P)>(to,removed)){
00085 action.unknownMove(from,to,p1,ptype,isPromote,P,m);
00086 }
00087 }
00088 void dropMove(Square to,Ptype ptype,Player ,Move m){
00090 if(!state.template hasEffectByWithRemove<alt(P)>(to,removed))
00091 action.dropMove(to,ptype,P,m);
00092 }
00093
00094 void simpleMove(Square from,Square to,Ptype ptype,
00095 bool isPromote,Player p)
00096 {
00097 simpleMove(from,to,ptype,isPromote,p,
00098 Move(from,to,ptype,PTYPE_EMPTY,isPromote,p));
00099 }
00100 void unknownMove(Square from,Square to,Piece captured,
00101 Ptype ptype,bool isPromote,Player p)
00102 {
00103 unknownMove(from,to,captured,ptype,isPromote,p,
00104 Move(from,to,ptype,captured.ptype(),isPromote,p));
00105 }
00106 void dropMove(Square to,Ptype ptype,Player p)
00107 {
00108 dropMove(to,ptype,p,
00109 Move(to,ptype,p));
00110 }
00111 };
00112
00116 template<class OrigAction>
00117 class NoAddEffectFilter
00118 {
00119 const NumEffectState& state;
00120 OrigAction & action;
00121 Square target;
00122 public:
00123 NoAddEffectFilter(const NumEffectState& s, OrigAction & action,Square target) : state(s), action(action),target(target) {}
00124 void simpleMove(Square from,Square to,Ptype ptype, bool isPromote,Player p,Move m){
00125 if(!state.hasEffectIf(newPtypeO(p,ptype),to,target))
00126 action.simpleMove(from,to,ptype,isPromote,p,m);
00127 }
00128 void unknownMove(Square from,Square to,Piece p1,Ptype ptype,bool isPromote,Player p,Move m){
00129 if(!state.hasEffectIf(newPtypeO(p,ptype),to,target))
00130 action.unknownMove(from,to,p1,ptype,isPromote,p,m);
00131 }
00132 void dropMove(Square to,Ptype ptype,Player p,Move m){
00133 if(!state.hasEffectIf(newPtypeO(p,ptype),to,target))
00134 action.dropMove(to,ptype,p,m);
00135 }
00136
00137 void simpleMove(Square from,Square to,Ptype ptype,
00138 bool isPromote,Player p)
00139 {
00140 simpleMove(from,to,ptype,isPromote,p,
00141 Move(from,to,ptype,PTYPE_EMPTY,isPromote,p));
00142 }
00143 void unknownMove(Square from,Square to,Piece captured,
00144 Ptype ptype,bool isPromote,Player p)
00145 {
00146 unknownMove(from,to,captured,ptype,isPromote,p,
00147 Move(from,to,ptype,captured.ptype(),isPromote,p));
00148 }
00149 void dropMove(Square to,Ptype ptype,Player p)
00150 {
00151 dropMove(to,ptype,p,
00152 Move(to,ptype,p));
00153 }
00154 };
00155
00159 template<Player P,class OrigAction>
00160 struct NotKingOpenFilter
00161 {
00162 const NumEffectState& state;
00163 OrigAction & action;
00164 public:
00165 NotKingOpenFilter(const NumEffectState& s, OrigAction & action)
00166 : state(s), action(action) {
00167 }
00168 bool isNotKingOpenMove(Ptype ptype,Square from,Square to)
00169 {
00170 return !move_classifier::KingOpenMove<P>::isMember(state, ptype, from, to);
00171 }
00172 void simpleMove(Square from,Square to,Ptype ptype, bool isPromote,Player
00173 #ifndef NDEBUG
00174 p
00175 #endif
00176 ,Move m
00177 ){
00178 assert(p == P);
00179 if(isNotKingOpenMove(ptype,from,to))
00180 action.simpleMove(from,to,ptype,isPromote,P,m);
00181
00182 }
00183 void unknownMove(Square from,Square to,Piece p1,Ptype ptype,bool isPromote,Player
00184 #ifndef NDEBUG
00185 p
00186 #endif
00187 ,Move m
00188 ){
00189 assert(p == P);
00190 if(isNotKingOpenMove(ptype,from,to))
00191 action.unknownMove(from,to,p1,ptype,isPromote,P,m);
00192 }
00196 void dropMove(Square to,Ptype ptype,Player
00197 #ifndef NDEBUG
00198 p
00199 #endif
00200 ,Move m
00201 ){
00202 assert(p == P);
00203 action.dropMove(to,ptype,P,m);
00204 }
00205
00206 void simpleMove(Square from,Square to,Ptype ptype,
00207 bool isPromote,Player p)
00208 {
00209 simpleMove(from,to,ptype,isPromote,p,
00210 Move(from,to,ptype,PTYPE_EMPTY,isPromote,p));
00211 }
00212 void unknownMove(Square from,Square to,Piece captured,
00213 Ptype ptype,bool isPromote,Player p)
00214 {
00215 unknownMove(from,to,captured,ptype,isPromote,p,
00216 Move(from,to,ptype,captured.ptype(),isPromote,p));
00217 }
00218 void dropMove(Square to,Ptype ptype,Player p)
00219 {
00220 dropMove(to,ptype,p,
00221 Move(to,ptype,p));
00222 }
00223 };
00224 }
00225 }
00226
00227 #endif
00228
00229
00230
00231