00001 #ifndef _GENERATE_ALL_MOVES_TCC
00002 #define _GENERATE_ALL_MOVES_TCC
00003 #include "osl/move_generator/allMoves.h"
00004 #include "osl/move_generator/pieceOnBoard.tcc"
00005 #include "osl/move_generator/drop.h"
00006 #include "osl/move_action/concept.h"
00007 #include "osl/move_action/store.h"
00008 #include "osl/state/numEffectState.h"
00009
00010 namespace osl
00011 {
00012 namespace move_generator
00013 {
00017 template<typename State,typename Action,Player P,Ptype T>
00018 struct EachOnBoard
00019 {
00020 const State& state;
00021 Action& action;
00022 EachOnBoard(const State& state,Action& action):state(state),action(action){}
00023 void operator()(Piece p){
00024 PieceOnBoardType<P,T>::generate(state,p,action);
00025 }
00026 };
00027
00028 template<class State,class Action>
00029 template<Player P,Ptype T>
00030 void AllMoves<State, Action>::
00031 generateMovesPtype(const State& state, Action& action){
00032 typedef EachOnBoard<State,Action,P,T> each_t;
00033 each_t eachOnBoard(state,action);
00034 state.template forEachOnBoard<P,T,each_t>(eachOnBoard);
00035 }
00036
00037
00042 template<class State,class Action>
00043 template<Player P>
00044 void AllMoves<State, Action>::
00045 generateMoves(const State& state, Action& action,Int2Type<true>)
00046 {
00047 generateMovesPtype<P,PAWN>(state,action);
00048 generateMovesPtype<P,LANCE>(state,action);
00049 generateMovesPtype<P,KNIGHT>(state,action);
00050 generateMovesPtype<P,SILVER>(state,action);
00051 generateMovesPtype<P,GOLD>(state,action);
00052 generateMovesPtype<P,BISHOP>(state,action);
00053 generateMovesPtype<P,ROOK>(state,action);
00054 generateMovesPtype<P,KING>(state,action);
00055 Drop<typename State::pawn_mask_state_t,Action>
00056 ::template generateMoves<P>(state,action);
00057 }
00058
00062 template<typename State,typename Action,Player P>
00063 struct EachOnBoardWithPawnMask{
00064 const State& state;
00065 Action& action;
00066 BitXmask &pawnMask;
00067 EachOnBoardWithPawnMask(const State& state,Action& action,BitXmask& pawnMask):state(state),action(action),pawnMask(pawnMask){}
00068 void operator()(Piece p){
00069 PieceOnBoard<P>::generateMovesPawn(state,p,action,pawnMask);
00070 }
00071 };
00072
00073 template<class State,class Action>
00074 template<Player P>
00075 void AllMoves<State, Action>::
00076 generateMovesPawn(const State& state, Action& action,BitXmask &pawnMask){
00077 typedef EachOnBoardWithPawnMask<State,Action,P> each_t;
00078 each_t eachOnBoard(state,action,pawnMask);
00079 state.template forEachOnBoard<P,PAWN,each_t>(eachOnBoard);
00080 }
00081
00086 template<class State,class Action>
00087 template<Player P>
00088 void AllMoves<State, Action>::
00089 generateMoves(const State& state, Action& action,Int2Type<false>)
00090 {
00094 BitXmask pawnMask;;
00095 if(state.template hasPieceInStand<P,PAWN>()){
00096 generateMovesPawn<P>(state,action,pawnMask);
00097 }
00098 else{
00099 generateMovesPtype<P,PAWN>(state,action);
00100 }
00101 generateMovesPtype<P,LANCE>(state,action);
00102 generateMovesPtype<P,KNIGHT>(state,action);
00103 generateMovesPtype<P,SILVER>(state,action);
00104 generateMovesPtype<P,GOLD>(state,action);
00105 generateMovesPtype<P,BISHOP>(state,action);
00106 generateMovesPtype<P,ROOK>(state,action);
00107 generateMovesPtype<P,KING>(state,action);
00108 Drop<typename State::pawn_mask_state_t,Action>
00109 ::template generateMovesWithPawnMask<P>(state,action,pawnMask);
00110 }
00111
00116 template<class State,class Action>
00117 template<Player P>
00118 void AllMoves<State, Action>::
00119 generateMoves(const State& state, Action& action){
00120 AllMoves<State, Action>::template
00121 generateMoves<P>(state,action,Int2Type<State::hasPawnMask>());
00122 }
00123
00124
00125 }
00126 }
00127
00128 template <class State>
00129 void osl::GenerateAllMoves::
00130 generate(Player p, const State& state, container::MoveVector& out)
00131 {
00132 typedef move_action::Store store_t;
00133 store_t store(out);
00134 move_generator::AllMoves<State,store_t>::generateMoves(p, state, store);
00135 }
00136
00137 #endif
00138
00139
00140
00141