legalMoves.cc
Go to the documentation of this file.
00001 /* legalMoves.cc
00002  */
00003 #include "osl/move_generator/legalMoves.h"
00004 #include "osl/move_classifier/moveAdaptor.h"
00005 #include "osl/move_classifier/pawnDropCheckmate.h"
00006 #include "osl/move_classifier/safeMove.h"
00007 #include "osl/move_generator/allMoves.h"
00008 #include "osl/move_generator/escape_.h"
00009 #include "osl/container/moveVector.h"
00010 #include "osl/effect_util/effectUtil.h"
00011 #include <boost/foreach.hpp>
00012 
00013 void osl::move_generator::
00014 LegalMoves::generate(const NumEffectState& state, MoveVector& moves)
00015 {
00016   if (state.inCheck())
00017   {
00018     // 王手がかかっている時は防ぐ手のみを生成, 王手回避は不成も生成
00019     GenerateEscapeKing::generate(state, moves);
00020   }
00021   else
00022   {
00023     // そうでなければ全ての手を生成
00024     MoveVector all_moves;
00025     GenerateAllMoves::generate(state.turn(), state, all_moves);
00026     // この指手は,玉の素抜きがあったり,打歩詰の可能性があるので
00027     // 確認が必要
00028     using namespace osl::move_classifier;
00029     BOOST_FOREACH(Move m, all_moves)
00030     {
00031       if (m.isDrop()
00032           || PlayerMoveAdaptor<SafeMove>::isMember(state, m))
00033       {
00034         if (! PlayerMoveAdaptor<PawnDropCheckmate>::isMember(state, m))
00035         {
00036           moves.push_back(m);
00037         }
00038       }
00039     }
00040   }
00041 }
00042 
00043 void osl::move_generator::
00044 LegalMoves::generateWithFullUnpromotions(const NumEffectState& state, 
00045                                          MoveVector& moves)
00046 {
00047   generate(state, moves);
00048   if (state.inCheck())
00049     return;
00050   for (int i=0, iend=moves.size(); i<iend; ++i) {
00051     const osl::Move move = moves[i];
00052     if (move.hasIgnoredUnpromote())
00053       moves.push_back(move.unpromote());
00054   }
00055 }
00056 
00057 // ;;; Local Variables:
00058 // ;;; mode:c++
00059 // ;;; c-basic-offset:2
00060 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines