00001
00002
00003 #ifndef _CATEGORY_ADDEFFECT_H
00004 #define _CATEGORY_ADDEFFECT_H
00005
00006 #include "osl/category/categoryEnv.h"
00007 #include "osl/category/categoryTraits.h"
00008 #include "osl/category/ptypePtypeProbTable.h"
00009 #include "osl/misc/carray.h"
00010 #include "osl/container/moveVector.h"
00011 #include "osl/container/moveLogProbVector.h"
00012 #include "osl/container/moveStack.h"
00013 #include "osl/effect_util/effectUtil.h"
00014 #include <utility>
00015
00016 namespace osl
00017 {
00018 namespace category
00019 {
00023 struct AddEffect : public TableProbabilityCategory
00024 {
00025 static Interpolator<PtypePtype2ProbTable> probTable;
00026 static const char *getName() { return "AddEffect"; }
00027 static std::pair<bool,size_t>
00028 getIndexIf(const CategoryEnv& env, Move move, int pieceValue)
00029 {
00030 const Player opponent = alt(env.state->getTurn());
00031 CArray<Piece,2> highest;
00032 EffectUtil::mostValuableEffectOfMoveNotKing
00033 (opponent, *env.state, move, highest);
00034 if (highest[0] != Piece::EMPTY())
00035 {
00036 CArray<bool,2> supported;
00037 if(highest[0].position().isPieceStand())
00038 supported[0]=false;
00039 else
00040 supported[0] =
00041 env.state->hasEffectBy(opponent, highest[0].position());
00042 if(highest[1].position().isPieceStand())
00043 supported[1]=false;
00044 else
00045 supported[1] =
00046 env.state->hasEffectBy(opponent, highest[1].position());
00047 const size_t index =
00048 probTable.getIndex(highest[0].ptype(), highest[1].ptype(),
00049 supported, move.ptype(), pieceValue);
00050 return std::make_pair(true,index);
00051 }
00052 return std::make_pair(false,0u);
00053 }
00054
00055 };
00056
00066 struct AddEffectToLastMove : public TableProbabilityCategory
00067 {
00068 static Interpolator<PtypePtypeProbTable> probTable;
00069 static const char *getName();
00070 static int minProb() { return 381; }
00071 static const int pieceValueLimit;
00072 static std::pair<bool,size_t>
00073 getIndexIf(const CategoryEnv& env, Move move, int pieceValue)
00074 {
00075 const Move last_move = env.history->lastMove();
00076 if ((! last_move.isNormal()) || (pieceValue < pieceValueLimit))
00077 return std::make_pair(false,0u);
00078 if (env.state->hasEffectFromTo(move.ptypeO(),move.to(),
00079 env.history->lastMove().to()))
00080 {
00081 const Ptype target = last_move.ptype();
00082 const bool supported
00083 = env.state->hasEffectBy(alt(last_move.player()),last_move.to());
00084 const size_t index
00085 = probTable.getIndex(target, supported,move.ptype(), pieceValue);
00086 return std::make_pair(true,index);
00087 }
00088 return std::make_pair(false,0u);
00089 }
00090 static void generate(const CategoryEnv& env, MoveLogProbVector& out);
00091 static void generate(const CategoryEnv& env, MoveLogProbVector& out,
00092 int *indices);
00093 };
00094
00098 struct OpenBishop : public StandardProbabilityCategory
00099 {
00100 static Interpolator<PieceValueTable> probTable;
00101 static const char *getName() { return "OpenBishop"; }
00102 static bool isInCategory(const CategoryEnv& env,
00103 Move move)
00104 {
00105 const Player player = move.player();
00106 return
00107 (env.state->hasEffectByPtype<BISHOP>(player, move.from()) &&
00108 (move.from().x() >= 3 && move.from().x() <= 7 &&
00109 move.from().y() >= 3 && move.from().y() <= 7));
00110 }
00111 };
00112 }
00113 }
00114
00115 #endif
00116
00117
00118
00119