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