00001
00002
00003 #ifndef _ESCAPE_H
00004 #define _ESCAPE_H
00005
00006 #include "osl/category/categoryEnv.h"
00007 #include "osl/category/categoryTraits.h"
00008 #include "osl/category/probTable.h"
00009 #include "osl/category/ptypePtypeProbTable.h"
00010 #include "osl/container/moveStack.h"
00011 #include "osl/effect_util/effectUtil.h"
00012 #include <boost/static_assert.hpp>
00013 namespace osl
00014 {
00015 namespace container
00016 {
00017 class MoveLogProbVector;
00018 }
00019 namespace category
00020 {
00021 using container::MoveLogProbVector;
00025 struct EscapeCommon
00026 {
00027 struct Generator;
00028 };
00029
00039 template <Ptype PTYPE>
00040 struct Escape : public TableProbabilityCategory
00041 {
00042 BOOST_STATIC_ASSERT(PtypeTraits<PTYPE>::isBasic);
00043 static Interpolator<PtypeValueTable> probTable;
00044 static const char *getName();
00045 static std::pair<bool,size_t>
00046 getIndexIf(const CategoryEnv& env, Move move, int pieceValue)
00047 {
00048 const Position from = move.from();
00049 const Player myself = move.player();
00050 const Player opponent = alt(myself);
00051 if ((unpromote(move.ptype()) == PTYPE)
00052 && !from.isPieceStand() && env.state->hasEffectBy(opponent,from))
00053 {
00054 const bool supported
00055 = env.state->hasEffectBy(myself, from);
00056 const Piece attacker =
00057 EffectUtil::cheapestPiece(opponent, *env.state, from);
00058 const size_t index = probTable.getIndex(supported,
00059 attacker.ptype(),
00060 pieceValue);
00061 return std::make_pair(true,index);
00062 }
00063 return std::make_pair(false,0u);
00064 }
00065 static void generate(const CategoryEnv& env, MoveLogProbVector& out);
00066 static void generate(const CategoryEnv& env, MoveLogProbVector& out,
00067 int *indices);
00068 };
00069
00076 struct ImmediateEscape : public TableProbabilityCategory
00077 {
00078 static Interpolator<PtypePtypeProbTable> probTable;
00079 static const char *getName() { return "Escape!"; }
00080 static std::pair<bool,size_t>
00081 getIndexIf(const CategoryEnv& env, Move move, int pieceValue)
00082 {
00083 const Move last_move=env.history->lastMove();
00084 if (! last_move.isNormal())
00085 return std::make_pair(false,0u);
00086 if (move.from()==Position::STAND())
00087 return std::make_pair(false,0u);
00088 if (env.state->hasEffectTo
00089 (env.state->getPieceOnBoard(last_move.to()), move.from()))
00090 {
00091 const bool supported
00092 = env.state->hasEffectBy(env.state->getTurn(), last_move.to());
00093 const size_t index =
00094 probTable.getIndex(move.ptype(), supported,
00095 last_move.ptype(), pieceValue);
00096 return std::make_pair(true,index);
00097 }
00098 return std::make_pair(false,0u);
00099 }
00100 struct PositionAction;
00101 static void generate(const CategoryEnv& env, MoveLogProbVector& out);
00102 static void generate(const CategoryEnv& env, MoveLogProbVector& out,
00103 int *indices);
00104 };
00105
00106
00107 }
00108 }
00109
00110 #endif
00111
00112
00113
00114