00001
00002
00003 #ifndef OSL_CATEGORY_CLASSIFY_TCC
00004 #define OSL_CATEGORY_CLASSIFY_TCC
00005
00006 #include "osl/category/classify.h"
00007 #include "osl/category/categoryUtil.h"
00008 #include "osl/category/moveEvaluation.h"
00009 #include "osl/move_generator/allMoves.h"
00010 #include "osl/move_action/store.h"
00011 #include <algorithm>
00012 #include <cassert>
00013
00014 template <class SubCategories>
00015 void osl::category::Classify<SubCategories>::
00016 generate(const CategoryEnv& env, MoveLogProbVector& out)
00017 {
00018 MoveVector moves;
00019 move_action::Store store(moves);
00020 move_generator::AllMoves<NumEffectState,move_action::Store>::
00021 generateMoves(env.state->getTurn(),*env.state, store);
00022
00023 Position8 sendoffs;
00024 CategoryUtilBase::findSendOff(env, sendoffs);
00025 bool threatmate =
00026 (env.record &&
00027 env.record->threatmate().threatmateMove(env.state->getTurn()).isNormal());
00028 for (MoveVector::const_iterator p=moves.begin(); p!=moves.end(); ++p)
00029 {
00030
00031
00032 const int max = threatmate ? ((env.limit+1)*5/4+1) : (env.limit+1);
00033 const int diff = MoveEvaluation::evalDetailed(env, *p, sendoffs);
00034
00035 int prob = getMinProb(SubCategories(), env, *p, diff, max);
00036 assert(prob);
00037 if (threatmate)
00038 prob = prob*4/5;
00039 if (prob < env.limit+1)
00040 out.push_back(*p, prob);
00041 }
00042 }
00043
00044 template <class SubCategories>
00045 template <class Head, class Tail>
00046 int osl::category::Classify<SubCategories>::
00047 getProb(CategoryList<Head,Tail>, const CategoryEnv& env, Move m,
00048 int pieceValue, int cur)
00049 {
00050 if (MinProb<Head>::minProb() < cur)
00051 {
00052 const std::pair<bool,int> r = CategoryUtil<Head>::getProbIf(env,m,pieceValue);
00053 if (r.first)
00054 return r.second;
00055
00056 }
00057 return getProb(Tail(), env, m, pieceValue, cur);
00058 }
00059
00060 template <class SubCategories>
00061 template <class Head>
00062 int osl::category::Classify<SubCategories>::
00063 getProb(CategoryList<Head,NullCategory>, const CategoryEnv& env, Move m,
00064 int pieceValue, int cur)
00065 {
00066 if (MinProb<Head>::minProb() < cur)
00067 {
00068 const std::pair<bool,int>
00069 r = CategoryUtil<Head>::getProbIf(env,m,pieceValue);
00070 if (r.first)
00071 return r.second;
00072 }
00073 return cur;
00074 }
00075
00076 template <class SubCategories>
00077 template <class Head, class Tail>
00078 int osl::category::Classify<SubCategories>::
00079 getMinProb(CategoryList<Head,Tail>, const CategoryEnv& env, Move m,
00080 int pieceValue, int cur)
00081 {
00082 if (MinProb<Head>::minProb() < cur)
00083 {
00084 const std::pair<bool,int> r
00085 = CategoryUtil<Head>::getProbIf(env,m,pieceValue);
00086 if (r.first)
00087 return getMinProb(Tail(), env, m, pieceValue, std::min(cur,r.second));
00088
00089 }
00090 return getMinProb(Tail(), env, m, pieceValue, cur);
00091 }
00092
00093 template <class SubCategories>
00094 template <class Head>
00095 int osl::category::Classify<SubCategories>::
00096 getMinProb(CategoryList<Head,NullCategory>,
00097 const CategoryEnv& env, Move m, int pieceValue, int cur)
00098 {
00099 if (MinProb<Head>::minProb() < cur)
00100 {
00101 const std::pair<bool,int> r = CategoryUtil<Head>::getProbIf(env,m,pieceValue);
00102 if (r.first)
00103 return std::min(cur,r.second);
00104 }
00105 return cur;
00106 }
00107
00108 #endif
00109
00110
00111
00112