00001
00002
00003 #ifndef OSL_CATEGORY_INDEXUTIL_H
00004 #define OSL_CATEGORY_INDEXUTIL_H
00005
00006 #include "osl/category/categoryUtil.h"
00007 #include "osl/move_classifier/safeMove.h"
00008
00009 namespace osl
00010 {
00011 namespace category
00012 {
00016 template <class Category>
00017 struct IndexUtil : CategoryUtilBase
00018 {
00019 private:
00020 static void doNotCompile();
00021 private:
00022 static void generateWithIndex(const CategoryEnv&, MoveLogProbVector&,
00023 int *, Int2Type<SPECIAL>)
00024 {
00025 doNotCompile();
00026 }
00027 static void generateWithIndex(const CategoryEnv& env,
00028 MoveLogProbVector& out, int *indices,
00029 Int2Type<TABLE>)
00030 {
00031 Category::generate(env, out, indices);
00032 out.sortByProbability();
00033 }
00034 static void generateWithIndex(const CategoryEnv& env,
00035 MoveLogProbVector& out, int *indices,
00036 Int2Type<STANDARD_TABLE>)
00037 {
00038 MoveVector moves;
00039 Category::generate(env, moves);
00040 using namespace move_classifier;
00041 for (MoveVector::const_iterator p=moves.begin(); p!=moves.end(); ++p)
00042 {
00043 if (! ConditionAdaptor<SafeMove>::isMember(*env.state, *p))
00044 continue;
00045
00046 const int diff = MoveEvaluation::evalLight(*env.state, *p);
00047 const size_t index = Category::getIndex(env, *p, diff);
00048 const int moveProb = Category::probTable[index];
00049 if (moveProb <= env.limit)
00050 {
00051 *indices++ = index;
00052 out.push_back(*p, moveProb);
00053 }
00054 }
00055 out.sortByProbability();
00056 }
00057 static void generateWithIndex(const CategoryEnv& env,
00058 MoveLogProbVector& out, int *indices,
00059 Int2Type<FIXED>)
00060 {
00061 using namespace move_classifier;
00062 assert(env.limit >= Category::probTable[0]);
00063 MoveVector moves;
00064 Category::generate(env, moves);
00065 for (MoveVector::const_iterator p=moves.begin(); p!=moves.end(); ++p)
00066 {
00067 if (! ConditionAdaptor<SafeMove>::isMember(*env.state, *p))
00068 continue;
00069
00070 out.push_back(*p, Category::probTable[0]);
00071 *indices++ = 0;
00072 }
00073
00074 }
00075 public:
00082 static void generateWithIndex(const CategoryEnv& env,
00083 MoveLogProbVector& out, int *indices)
00084 {
00085 generateWithIndex(env, out, indices, Int2Type<Category::probType>());
00086 }
00087 };
00088 }
00089 }
00090
00091 #endif
00092
00093
00094
00095