00001
00002
00003 #ifndef _CATEGORY_MATE_H
00004 #define _CATEGORY_MATE_H
00005
00006 #include "osl/category/categoryEnv.h"
00007 #include "osl/category/categoryTraits.h"
00008 #include "osl/effect_util/neighboring8Direct.h"
00009
00015 namespace osl
00016 {
00017 namespace category
00018 {
00019 class PieceValueTable;
00023 struct DirectAttackToKing8 : public StandardProbabilityCategory
00024 {
00025 static Interpolator<PieceValueTable> probTable;
00026 static const char *getName() { return "DirectAttackToKing8"; }
00027 public:
00028 static bool isInCategory(const CategoryEnv& env, Move move)
00029 {
00030 const PtypeO ptypeo = move.ptypeO();
00031 const Position to = move.to();
00032 const Position op_king =
00033 env.state->getKingPosition(alt(env.state->getTurn()));
00034 return Neighboring8Direct::hasEffect(*env.state, ptypeo, to,
00035 op_king);
00036 }
00037 };
00038
00042 struct SlowApproach : public StandardProbabilityCategory
00043 {
00044 static Interpolator<PieceValueTable> probTable;
00045 static const char *getName() { return "SlowApproach"; }
00046
00047 static bool isInCategory(const CategoryEnv& env, Move move)
00048 {
00049 if (move.capturePtype() != PTYPE_EMPTY)
00050 return false;
00051 if ((move.ptype() != PPAWN)
00052 && (move.ptype() != PLANCE)
00053 && (move.ptype() != PKNIGHT)
00054 && (move.ptype() != KNIGHT)
00055 && (move.ptype() != GOLD)
00056 && (move.ptype() != SILVER)
00057 && (move.ptype() != PSILVER)
00058 && (move.ptype() != PBISHOP)
00059 && (move.ptype() != PROOK)
00060 )
00061 return false;
00062 const Position from = move.from();
00063 if (from == Position::STAND())
00064 return false;
00065 const Position to = move.to();
00066 const Position op_king =
00067 env.state->getKingPosition(alt(env.state->getTurn()));
00068 return approaching(from, to, op_king)
00069 || (Board_Table.nextPosition(move.player(), from, D) == to);
00070 }
00072 static bool approaching(Position from, Position to, Position target)
00073 {
00074
00075 int fromX = from.x();
00076 int fromY = from.y();
00077 int toX = to.x();
00078 int toY = to.y();
00079 int targetX = target.x();
00080 int targetY = target.y();
00081 return(abs(toY-targetY) < 2
00082 && ((abs(toX-targetX) < abs(fromX-targetX))
00083 || (toX-targetX == fromX-targetX
00084 && abs(toY-targetY) <= abs(fromY-targetY))));
00085 }
00086 };
00087
00093 struct DropPieceOnEscapeRoute : public FixedProbabilityCategory
00094 {
00095 static FixedValueTable probTable;
00096 static const char *getName() { return "DropPieceOnEscapeRoute"; }
00097 static bool isInCategory(const CategoryEnv &env, Move move)
00098 {
00099 if (!move.isDrop())
00100 return false;
00101 const Position king =
00102 env.state->getKingPosition(alt(env.state->getTurn()));
00103 if (abs(king.x() - move.to().x()) != 2 ||
00104 abs(king.y() - move.to().y()) > 1 )
00105 return false;
00106
00107 const Player p = move.player();
00108 const Position up = Board_Table.nextPosition(p, move.to(), U);
00109 const Position down = Board_Table.nextPosition(p, move.to(), D);
00110 const Piece piece1 = up.isOnBoard() ? env.state->getPieceAt(up)
00111 : env.state->getPieceAt(Board_Table.nextPosition(p, down, D));
00112
00113
00114 const Piece piece2 = env.state->getPieceAt(down);
00115 return (piece1.isPiece() &&
00116 piece1.owner() == alt(p) &&
00117 piece2.isPiece() &&
00118 piece2.owner() == alt(p));
00119 }
00120 };
00121
00125 struct LureKingToBottom : public FixedProbabilityCategory
00126 {
00127 static FixedValueTable probTable;
00128 static const char *getName() { return "LureKingToBottom"; }
00129 static bool isInCategory(const CategoryEnv &env, Move move)
00130 {
00131 Player player = move.player();
00132 if ((player == BLACK && move.to().y() == 1) ||
00133 (player == WHITE && move.to().y() == 9))
00134 {
00135 return (env.state->hasEffectByPtype<KING>(alt(player), move.to()) &&
00136 env.state->countEffect(alt(player), move.to()) == 1);
00137 }
00138 return false;
00139 }
00140 };
00141 }
00142 }
00143
00144 #endif
00145
00146
00147
00148