00001
00002
00003 #ifndef GROUP_ESCAPE_H
00004 #define GROUP_ESCAPE_H
00005
00006 #include "osl/rating/group.h"
00007 #include "osl/rating/feature/escape.h"
00008
00009 namespace osl
00010 {
00011 namespace rating
00012 {
00013 struct FromEffectGroup : public Group
00014 {
00015 FromEffectGroup();
00016 void show(std::ostream& os, int name_width, const range_t& range,
00017 const std::vector<double>& weights) const
00018 {
00019 showTopN(os, name_width, range, weights, 3);
00020 }
00021 int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
00022 {
00023 if (move.isDrop())
00024 return -1;
00025 const int index = CountEffect2::index(state, move.from(), env);
00026 const int progress8 = env.progress.value()/2;
00027 return index*8 + progress8;
00028 }
00029 bool effectiveInCheck() const { return true; }
00030 };
00031
00032 struct PtypeAttackedGroup : public Group
00033 {
00034 PtypeAttackedGroup();
00035 void show(std::ostream& os, int name_width, const range_t& range,
00036 const std::vector<double>& weights) const
00037 {
00038 showTopN(os, name_width, range, weights, 3);
00039 }
00040 int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
00041 {
00042 if (move.isDrop())
00043 return -1;
00044 const int progress8 = env.progress.value()/2;
00045 const Ptype self = move.oldPtype();
00046 const Ptype attack = state.findCheapAttack(alt(move.player()), move.from()).ptype();
00047 const int index = (self-PTYPE_PIECE_MIN)*(PTYPE_MAX+1-PTYPE_MIN)+attack;
00048 return index*8 + progress8;
00049 }
00050 bool effectiveInCheck() const { return true; }
00051 };
00052
00053 struct ToSupportedGroup : public Group
00054 {
00055 ToSupportedGroup() : Group("ToSupported")
00056 {
00057 for (int p=0; p<8; ++p)
00058 push_back(new ToSupported());
00059 }
00060 void show(std::ostream& os, int name_width, const range_t& range,
00061 const std::vector<double>& weights) const
00062 {
00063 showAll(os, name_width, range, weights);
00064 }
00065 int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
00066 {
00067 if (! (*this)[0].match(state, move, env))
00068 return -1;
00069 const int progress8 = env.progress.value()/2;
00070 return progress8;
00071 }
00072 bool effectiveInCheck() const { return true; }
00073 };
00074
00075 struct ImmediateEscapeGroup : public Group
00076 {
00077 ImmediateEscapeGroup();
00078 void show(std::ostream& os, int name_width, const range_t& range,
00079 const std::vector<double>& weights) const
00080 {
00081 showTopN(os, name_width, range, weights, 3);
00082 }
00083 int findMatchWithoutProgress(const NumEffectState& state, Move move, const RatingEnv& env) const
00084 {
00085 if (move.isDrop())
00086 return -1;
00087 const Move last_move = env.history.lastMove();
00088 if (! last_move.isNormal()
00089 || ! state.hasEffectIf(last_move.ptypeO(), last_move.to(), move.from()))
00090 return -1;
00091 return (move.ptype() - PTYPE_PIECE_MIN) * (PTYPE_MAX+1 - PTYPE_PIECE_MIN)
00092 + last_move.ptype() - PTYPE_PIECE_MIN;
00093 }
00094 int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
00095 {
00096 const int index = findMatchWithoutProgress(state, move, env);
00097 if (index < 0)
00098 return index;
00099 const int progress8 = env.progress.value()/2;
00100 return index*8 + progress8;
00101 }
00102 };
00103
00104 class KingEscapeGroup : public Group
00105 {
00106 public:
00107 KingEscapeGroup();
00108 void show(std::ostream& os, int name_width, const range_t& range,
00109 const std::vector<double>& weights) const
00110 {
00111 showAll(os, name_width, range, weights);
00112 }
00113 int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
00114 {
00115 if (! state.inCheck())
00116 return -1;
00117 const Ptype self = move.ptype();
00118 const int index = self-PTYPE_PIECE_MIN;
00119 assert((*this)[index].match(state, move, env));
00120 return index;
00121 }
00122 bool effectiveInCheck() const { return true; }
00123 };
00124 }
00125 }
00126
00127 #endif
00128
00129
00130
00131