captureGroup.h
Go to the documentation of this file.
00001 /* captureGroup.h
00002  */
00003 #ifndef _CAPTUREGROUP_H
00004 #define _CAPTUREGROUP_H
00005 
00006 #include "osl/rating/group.h"
00007 #include "osl/rating/feature/capture.h"
00008 
00009 namespace osl
00010 {
00011   namespace rating
00012   {
00013     class CaptureGroup : public Group
00014     {
00015     public:
00016       vector<int> see_range;
00017       CaptureGroup();
00018       void show(std::ostream& os, int name_width, const range_t& range, 
00019                 const vector<double>& weights) const
00020       {
00021         showAll(os, name_width, range, weights);
00022       }
00023       int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
00024       {
00025         const int progress8 = env.progress.value()/2;
00026         const int see = Capture::see(state, move, env);
00027         size_t index;
00028         if (see > 50)
00029           index = std::min(12, 7 + (see - 51) / 200);
00030         else if (see < -50)
00031           index = std::max(0, (see + 1250) / 200);
00032         else
00033           index = 6;
00034 #ifndef NDEBUG
00035         for (size_t i=0; i<see_range.size()-1; ++i) {
00036           if (see < see_range[i+1]) {
00037             assert(i == index);
00038             return i*8+progress8;
00039           }
00040         }
00041         assert(0);
00042         abort();
00043 #endif
00044         return index*8+progress8;
00045       }
00046       bool effectiveInCheck() const { return true; }
00047     };
00048 
00049     struct ShadowEffectGroup : public Group
00050     {
00051       ShadowEffectGroup() : Group("ShadowEffect")
00052       {
00053         push_back(new ShadowEffect1());
00054         push_back(new ShadowEffect2());
00055       }
00056       void show(std::ostream& os, int name_width, const range_t& range, 
00057                 const vector<double>& weights) const
00058       {
00059         showAll(os, name_width, range, weights);
00060       }
00061       int findMatch(const NumEffectState& state, Move move, const RatingEnv&) const
00062       {
00063         return ShadowEffect::count2(state, move.to(), move.player()) -1;
00064       }
00065     };
00066 
00067     struct ContinueCaptureGroup : public Group
00068     {
00069       ContinueCaptureGroup() : Group("Cont.Capture")
00070       {
00071         for (int p=0; p<8; ++p) // progress8
00072           push_back(new ContinueCapture());
00073       }
00074       void show(std::ostream& os, int name_width, const range_t& range, 
00075                 const vector<double>& weights) const
00076       {
00077         showAll(os, name_width, range, weights);
00078       }
00079       int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
00080       {
00081         if (! (*this)[0].match(state, move, env))
00082           return -1;
00083         const int progress8 = env.progress.value()/2;
00084         return progress8;
00085       }
00086     };
00087 
00088     struct DropCapturedGroup : public Group
00089     {
00090       DropCapturedGroup();
00091       void show(std::ostream& os, int name_width, const range_t& range, 
00092                 const vector<double>& weights) const
00093       {
00094         showTopN(os, name_width, range, weights, 3);
00095       }
00096       int findMatchWithoutProgress(Move move, const RatingEnv& env) const
00097       {
00098         if (! (move.isDrop() && env.history.hasLastMove(2)))
00099           return -1;
00100         const Move last2_move = env.history.lastMove(2);
00101         if (! (last2_move.isNormal()
00102                && last2_move.capturePtype() != PTYPE_EMPTY
00103                && unpromote(last2_move.capturePtype()) == move.ptype()))
00104           return -1;
00105         return move.ptype() - PTYPE_BASIC_MIN;
00106       }
00107       int findMatch(const NumEffectState&, Move move, const RatingEnv& env) const
00108       {
00109         const int index = findMatchWithoutProgress(move, env);
00110         if (index < 0)
00111           return index; 
00112         const int progress8 = env.progress.value()/2;
00113         return index*8 + progress8;     
00114       }
00115     };
00116   }
00117 }
00118 
00119 
00120 #endif /* _CAPTUREGROUP_H */
00121 // ;;; Local Variables:
00122 // ;;; mode:c++
00123 // ;;; c-basic-offset:2
00124 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines