00001
00002
00003 #ifndef _SILVER_H
00004 #define _SILVER_H
00005
00006 #include "osl/category/categoryTraits.h"
00007 #include "osl/category/categoryEnv.h"
00008 #include "osl/container/moveVector.h"
00009 #include "osl/container/moveStack.h"
00010 namespace osl
00011 {
00012 namespace category
00013 {
00017 struct StabInTheBack : public FixedProbabilityCategory
00018 {
00019 static FixedValueTable probTable;
00020 static const char *getName() { return "StabInTheBack"; }
00021 static bool isInCategory(const CategoryEnv& env, Move move)
00022 {
00023 const CategoryEnv::effect_state_t& state = *env.state;
00024 const Player P = move.player();
00025 const Piece backL =
00026 state.getPieceAt(Board_Table.nextPosition(P, move.to(), DL));
00027 const Piece backR =
00028 state.getPieceAt(Board_Table.nextPosition(P, move.to(), DR));
00029 return (move.ptype() == SILVER)
00030 && move.isDrop()
00031 && backR.isPiece()
00032 && (backR.owner() == alt(P))
00033 && backL.isPiece()
00034 && (backL.owner() == alt(P))
00035 && ((backL.ptype() == GOLD)
00036 || (backL.ptype() == ROOK))
00037 && ((backR.ptype() == GOLD)
00038 || (backR.ptype() == ROOK))
00039 && (! state.hasEffectBy(alt(P), move.to()));
00040 }
00041 };
00042
00046 struct SilverHeadOfKnight : public FixedProbabilityCategory
00047 {
00048 static FixedValueTable probTable;
00049 static const char *getName() { return "SilverHeadOfKnight"; }
00050
00051 static bool isInCategory(const CategoryEnv& env, Move move)
00052 {
00053 if (! ((move.ptype() == SILVER)
00054 && move.isDrop()))
00055 return false;
00056 const Player P = move.player();
00057 const Position to = move.to();
00058 const Piece front =
00059 env.state->getPieceAt(Board_Table.nextPosition(P, to, U));
00060 return front.isPiece()
00061 && (front.owner() == alt(P))
00062 && (front.ptype() == KNIGHT);
00063 }
00064 };
00065
00069 struct SilverHeadOfLastKnight : public FixedProbabilityCategory
00070 {
00071 static FixedValueTable probTable;
00072 static const char *getName() { return "SilverHeadOfKnight!"; }
00073
00074 static bool isEffective(const CategoryEnv& env)
00075 {
00076 return env.history->lastMove().isNormal();
00077 }
00078 static bool isInCategory(const CategoryEnv& env, Move move)
00079 {
00080 if (! isEffective(env))
00081 return false;
00082 const Player P = move.player();
00083 const Move last_move=env.history->lastMove();
00084 assert(last_move.isNormal());
00085 const Position to = move.to();
00086 return (last_move.to() == Board_Table.nextPosition(P, to, U))
00087 && SilverHeadOfKnight::isInCategory(env, move);
00088 }
00089 static void generate(const CategoryEnv& env, MoveVector& moves)
00090 {
00091 if (! isEffective(env))
00092 return;
00093 const Move last_move=env.history->lastMove();
00094 assert(last_move.isNormal());
00095 if (last_move.ptype() != KNIGHT)
00096 return;
00097 const Player P = env.state->getTurn();
00098 if (! env.state->hasPieceOnStand(P, SILVER))
00099 return;
00100 const Position to
00101 = Board_Table.nextPosition(alt(P), last_move.to(), U);
00102 if (env.state->getPieceOnBoard(to) != Piece::EMPTY())
00103 return;
00104 moves.push_back(Move(to, SILVER, P));
00105 }
00106 };
00107
00111 struct SilverNextToKing : public FixedProbabilityCategory
00112 {
00113 static FixedValueTable probTable;
00114 static const char *getName() { return "SilverNextToKing"; }
00115
00116 static bool isInCategory(const CategoryEnv &env, Move move)
00117 {
00118 if (move.ptype() != SILVER)
00119 return false;
00120
00121 const Player player = move.player();
00122 const Piece king = env.state->getKingPiece(alt(player));
00123 if (move.to().y() != king.position().y() ||
00124 !env.state->hasEffectByPtype<KING>(alt(player), move.to()) ||
00125 env.state->countEffect(alt(player), move.to()) != 1)
00126 return false;
00127 if (((player == BLACK && move.to().y()) == 2 ||
00128 (player == WHITE && move.to().y() == 8)) &&
00129 ((move.to().x() < 4 && move.to().x() == king.position().y() + 1) ||
00130 (move.to().x() > 6 && move.to().x() + 1 == king.position().y())))
00131 {
00132 return
00133 env.state->hasEffectBy(player,
00134 Board_Table.nextPosition(player, move.to(), U)) ||
00135 env.state->hasEffectBy(player,
00136 Board_Table.nextPosition(player, move.to(), D));
00137 }
00138 return false;
00139 }
00140 };
00141 }
00142 }
00143
00144
00145 #endif
00146
00147
00148
00149