00001
00002
00003 #ifndef OSL_CATEGARY_KNIGHT_H
00004 #define OSL_CATEGARY_KNIGHT_H
00005
00006 #include "osl/category/categoryTraits.h"
00007 #include "osl/category/categoryEnv.h"
00008 #include "osl/container/moveStack.h"
00009 #include "osl/container/moveVector.h"
00010
00011 namespace osl
00012 {
00013 namespace category
00014 {
00018 struct KnightDoubleAttack : public FixedProbabilityCategory
00019 {
00020 static FixedValueTable probTable;
00021 static const char *getName() { return "KnightDoubleAttack"; }
00022
00023 static bool isInCategory(const CategoryEnv& env, Move move)
00024 {
00025 if (move.ptype() != KNIGHT)
00026 return false;
00027 const Player P = move.player();
00028 const Position to = move.to();
00029
00030 if (env.state->hasEffectBy(alt(P), to))
00031 return false;
00032 const Position front = Board_Table.nextPosition(P, to, U);
00033 const Piece left =
00034 env.state->getPieceAt(Board_Table.nextPosition(P, front, UL));
00035 const Piece right =
00036 env.state->getPieceAt(Board_Table.nextPosition(P, front, UR));
00037
00038 return (left.isPiece() && right.isPiece() &&
00039 left.owner() != P && right.owner() != P &&
00040 left.ptype() != PAWN && right.ptype() != PAWN);
00041 }
00042 };
00043
00048 struct KnightToAttack : public FixedProbabilityCategory
00049 {
00050 static FixedValueTable probTable;
00051 static const char *getName() { return "KnightToAttack"; }
00052
00053 static bool isInCategory(const CategoryEnv& env, Move move)
00054 {
00055 if (move.ptype() != KNIGHT || !move.isDrop())
00056 return false;
00057 const Player P = move.player();
00058 const Position to = move.to();
00059
00060 if (env.state->hasEffectBy(alt(P), to))
00061 return false;
00062 const Piece king = env.state->getKingPiece(alt(P));
00063 const int y = (P == BLACK ? (king.position().y() + 4) :
00064 (king.position().y() - 4));
00065 const int x_diff = king.position().x() - to.x();
00066
00067 return (y == to.y() &&
00068 (x_diff == -2 || x_diff == 2 || x_diff == 0));
00069 }
00070 };
00074 struct JoiningKnights : public FixedProbabilityCategory
00075 {
00076 static FixedValueTable probTable;
00077 static const char *getName() { return "JoiningKnights"; }
00078
00079 static bool isInCategory(const CategoryEnv& env, Move move)
00080 {
00081 if (move.ptype() != KNIGHT || !move.isDrop())
00082 return false;
00083 const Player P = move.player();
00084 const Position to = move.to();
00085 const Piece king = env.state->getKingPiece(alt(P));
00086 if (!env.state->hasEffectFromTo(move.ptypeO(), to, king.position()))
00087 return false;
00088 if (env.state->hasEffectByPtype<KNIGHT>(P, to))
00089 return true;
00090 return false;
00091 }
00092 };
00096 struct KnightAttackYagura : public FixedProbabilityCategory
00097 {
00098 static FixedValueTable probTable;
00099 static const char* getName() { return "KnightAttackYagura"; }
00100
00101 static bool isInCategory(const CategoryEnv &env, Move move)
00102 {
00103 if (move.ptype() != KNIGHT)
00104 return false;
00105 const Player player = move.player();
00106 if (!env.state->hasEffectByPtype<PAWN>(player, move.to()) ||
00107 !env.state->hasEffectByPtype<PAWN>(alt(player), move.to()))
00108 return false;
00109 const Piece king = env.state->getKingPiece(alt(player));
00110
00111 return king.position().x() == move.to().x() &&
00112 ((player == BLACK && king.position().y() - move.to().y() == 2) ||
00113 (player == WHITE && move.to().y() - king.position().y() == 2));
00114 }
00115 };
00116 }
00117 }
00118
00119 #endif
00120
00121
00122
00123