escape.h
Go to the documentation of this file.
00001 /* escape.h
00002  */
00003 #ifndef _ESCAPE_H
00004 #define _ESCAPE_H
00005 
00006 #include "osl/rating/feature.h"
00007 #include "osl/rating/feature/countEffect2.h"
00008 
00009 namespace osl
00010 {
00011   namespace rating
00012   {
00014     class FromEffect : public Feature, CountEffect2
00015     {
00016     public:
00017       FromEffect(int attack, int defense) 
00018         : Feature("FE"+CountEffect2::name(attack, defense)), CountEffect2(attack, defense) {}
00019       bool match(const NumEffectState& state, Move move, const RatingEnv& env) const
00020       {
00021         return ! move.isDrop() && CountEffect2::match(state, move.from(), env);
00022       }
00023     };
00024 
00025     class PtypeAttacked : public Feature
00026     {
00027       Ptype self, attack;
00028     public:
00029       PtypeAttacked(Ptype s, Ptype a) 
00030         : Feature(std::string(Ptype_Table.getCsaName(s))+"<"+Ptype_Table.getCsaName(a)), 
00031           self(s), attack(a)
00032       {
00033       }
00034       bool match(const NumEffectState& state, Move move, const RatingEnv&) const
00035       {
00036         return move.oldPtype() == self
00037           && ! move.isDrop()
00038           && state.findCheapAttack(alt(move.player()), move.from()).ptype()== attack;
00039       }
00040     };
00041 
00042     class ToSupported : public Feature
00043     {
00044     public:
00045       ToSupported() : Feature("TS") {}
00046       bool match(const NumEffectState& state, Move move, const RatingEnv&) const
00047       {
00048         return state.hasEffectAt(move.player(), move.to());
00049       }
00050     };
00051 
00052     class ImmediateEscape : public Feature
00053     {
00054       Ptype self, attack;
00055     public:
00056       ImmediateEscape(Ptype s, Ptype a) 
00057         : Feature(std::string(Ptype_Table.getCsaName(s))+"<"+Ptype_Table.getCsaName(a)),
00058           self(s), attack(a)
00059       {
00060       }
00061       bool match(const NumEffectState& state, Move move, const RatingEnv& env) const
00062       {
00063         if (move.isDrop())
00064           return false;
00065         if (move.ptype() != self)
00066           return false;
00067         const Move last_move = env.history.lastMove();
00068         if (! last_move.isNormal() || last_move.ptype() != attack)
00069           return false;
00070         return state.hasEffectIf(last_move.ptypeO(), last_move.to(), move.from());
00071       }
00072     };
00073 
00074     class KingEscape : public Feature
00075     {
00076       Ptype ptype;
00077     public:
00078       KingEscape(Ptype s) 
00079         : Feature(std::string(Ptype_Table.getCsaName(s))), ptype(s)
00080       {
00081       }
00082       bool match(const NumEffectState& state, Move move, const RatingEnv&) const
00083       {
00084         return state.inCheck()
00085           && move.ptype() == ptype;
00086       }
00087       bool effectiveInCheck() const { return true; }
00088     };
00089   }
00090 }
00091 
00092 #endif /* _ESCAPE_H */
00093 // ;;; Local Variables:
00094 // ;;; mode:c++
00095 // ;;; c-basic-offset:2
00096 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines