00001
00002
00003 #ifndef _MOVE_CLASSIFIER_SAFE_MOVE_H
00004 #define _MOVE_CLASSIFIER_SAFE_MOVE_H
00005 #include "osl/position.h"
00006 #include "osl/player.h"
00007 #include "osl/ptype.h"
00008 #include "osl/piece.h"
00009 #include "osl/move_classifier/kingOpenMove.h"
00010 #include "osl/move_classifier/classifierTraits.h"
00011 namespace osl
00012 {
00013 namespace move_classifier
00014 {
00019 template <Player P>
00020 struct SafeMove
00021 {
00022 static bool isMember(const NumEffectState& state,
00023 Ptype ptype,Position from,Position to)
00024 {
00025 assert(! from.isPieceStand());
00026 assert(state.getPieceOnBoard(from).owner() == P);
00031 if (ptype==KING)
00032 return ! state.template hasEffectBy<PlayerTraits<P>::opponent>(to);
00033 return ! KingOpenMove<P>::isMember(state,ptype,from,to);
00034 }
00035 };
00036
00037 static inline bool isSafeMove(NumEffectState& state, Move move)
00038 {
00039 const Position from = move.from();
00040 if (from.isPieceStand())
00041 return true;
00042 const Player turn = move.player();
00043 const Ptype ptype = move.ptype();
00044 const Position to = move.to();
00045
00046 if (turn == BLACK)
00047 return SafeMove<BLACK>::isMember(state, ptype, from, to);
00048 else
00049 return SafeMove<WHITE>::isMember(state, ptype, from, to);
00050 }
00051 template <Player P> struct ClassifierTraits<SafeMove<P> >
00052 {
00053 static const bool drop_suitable = false;
00054 static const bool result_if_drop = true;
00055 };
00056 }
00057 using move_classifier::isSafeMove;
00058 }
00059 #endif
00060
00061
00062
00063