00001
00002
00003 #ifndef _CHECK_H
00004 #define _CHECK_H
00005
00006 #include "osl/category/categoryEnv.h"
00007 #include "osl/category/probTable.h"
00008 #include "osl/category/categoryTraits.h"
00009 #include "osl/move_generator/addEffect_.h"
00010 #include "osl/move_action/store.h"
00011 #include "osl/effect_util/effectUtil.h"
00012 #include "osl/effect_util/additionalEffect.h"
00013
00014 namespace osl
00015 {
00016 namespace category
00017 {
00021 struct Check : public StandardProbabilityCategory
00022 {
00023 static Interpolator<PieceValueTable> probTable;
00024 static const char *getName() { return "Check"; }
00025 static const bool AdjustSendOff = true;
00026 static void generate(const CategoryEnv& env, MoveVector& out)
00027 {
00028 assert((! EffectUtil::isKingInCheck(env.state->getTurn(), *env.state))
00029 || (env.state->dump(), 0));
00030 move_action::Store store(out);
00031 const Position target =
00032 env.state->getKingPosition(alt(env.state->getTurn()));
00033 move_generator::GenerateAddEffect<true>::
00034 generate(env.state->getTurn(), *env.state, target, store);
00035 }
00036 };
00037
00038 struct EnoughEffectCheck : public FixedProbabilityCategory
00039 {
00040 static FixedValueTable probTable;
00041 static const char *getName() { return "EnoughEffectCheck"; }
00042 static size_t getIndex(const CategoryEnv&, Move)
00043 {
00044 return 0;
00045 }
00046 static std::pair<bool,size_t>
00047 getIndexIf(const CategoryEnv& e, Move m, int )
00048 {
00049 if (!isInCategory(e, m))
00050 return std::make_pair(false, 0u);
00051 return std::make_pair(true, getIndex(e,m));
00052 }
00053 static bool isInCategory(const CategoryEnv& e, Move m)
00054 {
00055 Player P = e.state->getTurn();
00056 if (EffectUtil::isKingInCheck(alt(P), *e.state))
00057 {
00058 const int defense = e.state->countEffect(alt(P),m.to());
00059 const int offense = e.state->countEffect(P,m.to());
00060
00061 return ((defense < offense)
00062 || (defense == offense
00063 && AdditionalEffect::hasEffect(*e.state, m.to(), P)));
00064 }
00065 return false;
00066 }
00067 };
00068 }
00069 }
00070
00071 #endif
00072
00073
00074
00075