00001
00002
00003 #include "osl/category/addEffect.h"
00004 #include "osl/category/probTable.tcc"
00005 #include "osl/category/moveEvaluation.h"
00006 #include "osl/category/probTableDefine.h"
00007 #include "osl/move_generator/addEffect_.h"
00008 #include "osl/move_action/store.h"
00009 #include "osl/move_classifier/moveAdaptor.h"
00010
00011 namespace osl
00012 {
00013 namespace category
00014 {
00015 DEF_CATEGORY_TABLE_IP(PtypePtype2ProbTable, AddEffect);
00016 DEF_CATEGORY_TABLE_IP(PtypePtypeProbTable, AddEffectToLastMove);
00017 DEF_CATEGORY_TABLE_IP(PieceValueTable, OpenBishop);
00018 }
00019 }
00020
00021 const int osl::category::AddEffectToLastMove::pieceValueLimit
00022 = -eval::PtypeEvalTraits<PAWN>::val*2;
00023
00024 void osl::category::AddEffectToLastMove::
00025 generate(const CategoryEnv& env, MoveLogProbVector& out, int *indices)
00026 {
00027 const Move last_move = env.history->lastMove();
00028 if (! last_move.isNormal())
00029 return;
00030 const Ptype target = last_move.ptype();
00031 MoveVector moves;
00032 move_action::Store store(moves);
00033 move_generator::GenerateAddEffect<false>::generate
00034 (env.state->getTurn(), *env.state, last_move.to(), store);
00035
00036 for (size_t i=0; i<moves.size(); ++i)
00037 {
00038 const int pieceValue = MoveEvaluation::evalLight(*env.state, moves[i]);
00039 if (pieceValue < pieceValueLimit)
00040 continue;
00041 const bool supported
00042 = env.state->hasEffectBy(alt(last_move.player()),last_move.to());
00043 const size_t index =
00044 probTable.getIndex(target,supported, moves[i].ptype(),pieceValue);
00045 const int prob = probTable[index];
00046 if (prob <= env.limit)
00047 {
00048 out.push_back(moves[i], prob);
00049 if (indices)
00050 *indices++ = index;
00051 }
00052 }
00053 }
00054
00055 void osl::category::AddEffectToLastMove::
00056 generate(const CategoryEnv& env, MoveLogProbVector& out)
00057 {
00058 generate(env, out, 0);
00059 }
00060
00061 const char * osl::category::AddEffectToLastMove::
00062 getName()
00063 {
00064 return "AddEffect!";
00065 }
00066
00067
00068
00069
00070
00071