00001 #ifndef _GENERATE_DROP_MOVES_TCC
00002 #define _GENERATE_DROP_MOVES_TCC
00003 #include "osl/move_generator/drop.h"
00004 #include "osl/move_action/concept.h"
00005 namespace osl
00006 {
00007 namespace move_generator
00008 {
00009 template<class State>
00010 inline
00011 bool isPawnMaskSet(State const& state,int x,BitXmask pawnMask,Int2Type<BLACK>){
00012 return pawnMask.isSet(x);
00013 }
00014 template<class State>
00015 inline
00016 bool isPawnMaskSet(State const& state,int x,BitXmask pawnMask,Int2Type<WHITE>){
00017 return pawnMask.isSet(x);
00018 }
00019
00020 template<class State>
00021 inline
00022 bool isPawnMaskSet(State const& state,int x,misc::EmptyType ,Int2Type<BLACK>){
00023 return state.template isPawnMaskSet<BLACK>(x);
00024 }
00025 template<class State>
00026 inline
00027 bool isPawnMaskSet(State const& state,int x,misc::EmptyType ,Int2Type<WHITE>){
00028 return state.template isPawnMaskSet<WHITE>(x);
00029 }
00030
00031
00032 template<class State,class Action>
00033 template<Player P,typename PawnMaskT,bool hasPawn,bool hasLance,bool hasKnight,bool hasSilver,bool hasGold,bool hasBishop,bool hasRook>
00034 void Drop<State, Action>::
00035 generateDropMoves(const State& state,Action& action,PawnMaskT pawnMask)
00036 {
00037 if(hasPawn || hasLance || hasKnight || hasSilver || hasGold || hasBishop || hasRook){
00038 if(hasPawn){
00039 if(hasLance || hasKnight || hasSilver || hasGold || hasBishop || hasRook){
00040 for(int x=9;x>0;x--){
00041 if(isPawnMaskSet(state,x,pawnMask,Int2Type<P>()))
00042 generateDropMovesX<P,false,hasLance,hasKnight,hasSilver,hasGold,hasBishop,hasRook>(state,action,x);
00043 else
00044 generateDropMovesX<P,true,hasLance,hasKnight,hasSilver,hasGold,hasBishop,hasRook>(state,action,x);
00045 }
00046 }
00047 else{
00048 for(int x=9;x>0;x--){
00049 if(!isPawnMaskSet(state,x,pawnMask,Int2Type<P>()))
00050 generateDropMovesX<P,true,hasLance,hasKnight,hasSilver,hasGold,hasBishop,hasRook>(state,action,x);
00051 }
00052 }
00053 }
00054 else{
00055 for(int x=9;x>0;x--){
00056 generateDropMovesX<P,false,hasLance,hasKnight,hasSilver,hasGold,hasBishop,hasRook>(state,action,x);
00057 }
00058 }
00059 }
00060 }
00061
00065 template<class State,class Action>
00066 template<Player P,bool hasPawn,bool hasLance,bool hasKnight,bool hasSilver,bool hasGold,bool hasBishop,bool hasRook>
00067 void Drop<State, Action>::
00068 generateDropMovesX(const State& state,Action& action,int x)
00069 {
00070 assert(hasPawn || hasLance || hasKnight || hasSilver || hasGold || hasBishop || hasRook);
00071 if(P==BLACK){
00072 if(hasSilver || hasGold || hasBishop || hasRook){
00073 Position pos(x,1);
00074 Piece p=state.getPieceAt(pos);
00075 if(p==Piece::EMPTY()){
00076 if(hasRook)
00077 action.dropMove(pos,ROOK,P);
00078 if(hasBishop)
00079 action.dropMove(pos,BISHOP,P);
00080 if(hasGold)
00081 action.dropMove(pos,GOLD,P);
00082 if(hasSilver)
00083 action.dropMove(pos,SILVER,P);
00084 }
00085 }
00086 if(hasPawn || hasLance || hasSilver || hasGold || hasBishop || hasRook){
00087 Position pos(x,2);
00088 Piece p=state.getPieceAt(pos);
00089 if(p==Piece::EMPTY()){
00090 if(hasRook)
00091 action.dropMove(pos,ROOK,P);
00092 if(hasBishop)
00093 action.dropMove(pos,BISHOP,P);
00094 if(hasGold)
00095 action.dropMove(pos,GOLD,P);
00096 if(hasSilver)
00097 action.dropMove(pos,SILVER,P);
00098 if(hasLance)
00099 action.dropMove(pos,LANCE,P);
00100 if(hasPawn)
00101 action.dropMove(pos,PAWN,P);
00102 }
00103 }
00104 for(int y=3;y<=9;y++){
00105 Position pos(x,y);
00106 Piece p=state.getPieceAt(pos);
00107 if(p==Piece::EMPTY()){
00108 if(hasRook)
00109 action.dropMove(pos,ROOK,P);
00110 if(hasBishop)
00111 action.dropMove(pos,BISHOP,P);
00112 if(hasGold)
00113 action.dropMove(pos,GOLD,P);
00114 if(hasSilver)
00115 action.dropMove(pos,SILVER,P);
00116 if(hasKnight)
00117 action.dropMove(pos,KNIGHT,P);
00118 if(hasLance)
00119 action.dropMove(pos,LANCE,P);
00120 if(hasPawn)
00121 action.dropMove(pos,PAWN,P);
00122 }
00123 }
00124 }
00125 else{
00126 if(hasSilver || hasGold || hasBishop || hasRook){
00127 Position pos(x,9);
00128 Piece p=state.getPieceAt(pos);
00129 if(p==Piece::EMPTY()){
00130 if(hasRook)
00131 action.dropMove(pos,ROOK,P);
00132 if(hasBishop)
00133 action.dropMove(pos,BISHOP,P);
00134 if(hasGold)
00135 action.dropMove(pos,GOLD,P);
00136 if(hasSilver)
00137 action.dropMove(pos,SILVER,P);
00138 }
00139 }
00140 if(hasPawn || hasLance || hasSilver || hasGold|| hasBishop || hasRook){
00141 Position pos(x,8);
00142 Piece p=state.getPieceAt(pos);
00143 if(p==Piece::EMPTY()){
00144 if(hasRook)
00145 action.dropMove(pos,ROOK,P);
00146 if(hasBishop)
00147 action.dropMove(pos,BISHOP,P);
00148 if(hasGold)
00149 action.dropMove(pos,GOLD,P);
00150 if(hasSilver)
00151 action.dropMove(pos,SILVER,P);
00152 if(hasLance)
00153 action.dropMove(pos,LANCE,P);
00154 if(hasPawn)
00155 action.dropMove(pos,PAWN,P);
00156 }
00157 }
00158 for(int y=7;y>=1;y--){
00159 Position pos(x,y);
00160 Piece p=state.getPieceAt(pos);
00161 if(p==Piece::EMPTY()){
00162 if(hasRook)
00163 action.dropMove(pos,ROOK,P);
00164 if(hasBishop)
00165 action.dropMove(pos,BISHOP,P);
00166 if(hasGold)
00167 action.dropMove(pos,GOLD,P);
00168 if(hasSilver)
00169 action.dropMove(pos,SILVER,P);
00170 if(hasKnight)
00171 action.dropMove(pos,KNIGHT,P);
00172 if(hasLance)
00173 action.dropMove(pos,LANCE,P);
00174 if(hasPawn)
00175 action.dropMove(pos,PAWN,P);
00176 }
00177 }
00178 }
00179 }
00180
00181 }
00182 }
00183
00184 template<class State,class Action>
00185 template<osl::Player P>
00186 void osl::move_generator::Drop<State,Action>::
00187 generateMoves(const State& state,Action& action)
00188 {
00189 if(state.template hasPieceOnStand<P,PAWN>())
00190 generateDropMovesPawn<P,misc::EmptyType,true>(state,action,misc::EmptyType());
00191 else
00192 generateDropMovesPawn<P,misc::EmptyType,false>(state,action,misc::EmptyType());
00193 }
00194
00195 template<class State,class Action>
00196 template<osl::Player P,typename PawnMaskT,
00197 bool hasPawn,bool hasLance,bool hasKnight,bool hasSilver,bool hasGold>
00198 void osl::move_generator::Drop<State,Action>::
00199 generateDropMovesGold(const State& state,Action& action,PawnMaskT pawnMask)
00200 {
00201 if(state.template hasPieceOnStand<P,BISHOP>())
00202 generateDropMovesBishop<P,PawnMaskT,hasPawn,hasLance,hasKnight,hasSilver,hasGold,true>(state,action,pawnMask);
00203 else
00204 generateDropMovesBishop<P,PawnMaskT,hasPawn,hasLance,hasKnight,hasSilver,hasGold,false>(state,action,pawnMask);
00205 }
00206
00207
00208 template<class State,class Action>
00209 template<osl::Player P>
00210 void osl::move_generator::Drop<State,Action>::
00211 generateMovesWithPawnMask(const State& state,Action& action,BitXmask pawnMask)
00212 {
00213 if(state.template hasPieceOnStand<P,PAWN>())
00214 generateDropMovesPawn<P,BitXmask,true>(state,action,pawnMask);
00215 else
00216 generateDropMovesPawn<P,BitXmask,false>(state,action,pawnMask);
00217 }
00218
00219 #endif
00220
00221
00222
00223