00001
00002
00003 #ifndef CATEGORY_KINGESCAPE_H
00004 #define CATEGORY_KINGESCAPE_H
00005
00006 #include "osl/category/categoryEnv.h"
00007 #include "osl/category/categoryTraits.h"
00008 #include "osl/move_generator/escape_.h"
00009 #include "osl/move_action/store.h"
00010 #include "osl/container/moveStack.h"
00011 #include "osl/effect_util/neighboring8Direct.h"
00012 #include "osl/neighboring8.h"
00013 namespace osl
00014 {
00015 namespace category
00016 {
00020 struct KingEscape : public StandardProbabilityCategory
00021 {
00022 static Interpolator<PieceValueTable> probTable;
00023 static const char *getName() { return "KingEscape"; }
00024 static const bool IsKingEscape = true;
00025 static void generate(const CategoryEnv& env, MoveVector& out)
00026 {
00027 const Player player = env.state->getTurn();
00028 const Piece kingPiece=env.state->getKingPiece(player);
00029 const Position kingPosition=kingPiece.position();
00033 if (kingPosition.isPieceStand()) return;
00034 if (! env.state->hasEffectBy(alt(player), kingPosition))
00035 return;
00036
00037 move_action::Store store(out);
00038 assert(kingPiece == (*env.state).getPieceAt(kingPosition));
00039 if (player == BLACK)
00040 move_generator::Escape<BLACK,CategoryEnv::effect_state_t,move_action::Store>::
00041 generateMoves(*env.state,kingPiece,store);
00042 else
00043 move_generator::Escape<WHITE,CategoryEnv::effect_state_t,move_action::Store>::
00044 generateMoves(*env.state,kingPiece,store);
00045 }
00046 };
00047
00051 struct EnteringKing : public FixedProbabilityCategory
00052 {
00053 static FixedValueTable probTable;
00054 static const char *getName() { return "EnteringKing"; }
00055
00056 static bool isInCategory(const CategoryEnv& , Move move)
00057 {
00058 return (move.ptype() == KING)
00059 && move.to().canPromote(move.player());
00060 }
00061 };
00062
00067 struct DirectDefenseToKing8 : public StandardProbabilityCategory
00068 {
00069 static Interpolator<PieceValueTable> probTable;
00070 static const char *getName() { return "DirectDefenseToKing8"; }
00071 public:
00072 static bool isInCategory(const CategoryEnv& env, Move move)
00073 {
00074 const PtypeO ptypeo = move.ptypeO();
00075 const Position to = move.to();
00076 const Position kingPosition =
00077 env.state->getKingPosition(env.state->getTurn());
00078 return Neighboring8::isNeighboring8(move.to(),kingPosition)
00079 || Neighboring8Direct::hasEffect(*env.state, ptypeo,
00080 to, kingPosition);
00081 }
00082 };
00083
00084 }
00085 }
00086
00087 #endif
00088
00089
00090
00091