00001
00002
00003 #ifndef _GROUP_H
00004 #define _GROUP_H
00005
00006 #include "osl/rating/feature.h"
00007 #include "osl/rating/range.h"
00008 #include "osl/stl/vector.h"
00009 #include <boost/ptr_container/ptr_vector.hpp>
00010
00011 namespace osl
00012 {
00013 namespace rating
00014 {
00016 struct Group : public boost::ptr_vector<Feature>
00017 {
00018 std::string group_name;
00019
00020 Group(const std::string& name);
00021 Group(Feature *f) : group_name(f->name()) { push_back(f); }
00022 virtual ~Group();
00023 virtual void show(std::ostream&, int name_width, const range_t& range,
00024 const vector<double>& weights) const;
00025
00027 virtual int findMatch(const NumEffectState& state, Move m, const RatingEnv& env) const;
00028 void showMinMax(std::ostream& os, int name_width, const range_t& range,
00029 const vector<double>& weights) const;
00030 void showAll(std::ostream& os, int name_width, const range_t& range,
00031 const vector<double>& weights) const;
00032 void showTopN(std::ostream& os, int name_width, const range_t& range,
00033 const vector<double>& weights, int n) const;
00034 void saveResult(const std::string& directory, const range_t& range,
00035 const vector<double>& weights) const;
00036 bool load(const std::string& directory, const range_t& range,
00037 vector<double>& weights) const;
00038 virtual bool effectiveInCheck() const { return (*this)[0].effectiveInCheck(); }
00039 };
00040
00041 struct TakeBackGroup : public Group
00042 {
00043 TakeBackGroup() : Group("TakeBack")
00044 {
00045 push_back(new TakeBack());
00046 push_back(new TakeBack2());
00047 }
00048 void show(std::ostream& os, int name_width, const range_t& range,
00049 const vector<double>& weights) const
00050 {
00051 showAll(os, name_width, range, weights);
00052 }
00053 int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
00054 {
00055 const Position to = move.to();
00056 if (! env.history.hasLastMove() || env.history.lastMove().to() != to)
00057 return -1;
00058 if (! env.history.hasLastMove(2) || env.history.lastMove(2).to() != to)
00059 return 0;
00060 return 1;
00061 }
00062 bool effectiveInCheck() const { return true; }
00063 };
00064
00065 struct CheckGroup : public Group
00066 {
00067 CheckGroup() : Group("Check")
00068 {
00069 for (int i=0; i<4; ++i)
00070 for (int p=0; p<8; ++p)
00071 push_back(new Check(i));
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 using namespace osl::move_classifier;
00081 const bool direct = PlayerMoveAdaptor<osl::move_classifier::DirectCheck>::isMember(state, move);
00082 const bool open = ConditionAdaptor<osl::move_classifier::OpenCheck>::isMember(state, move);
00083 int index = -1;
00084 if (direct && !open)
00085 index = Check::openLong(state, move);
00086 else if (open)
00087 index = direct + 2;
00088 const int progress8 = env.progress.value()/2;
00089 return index*8 + progress8;
00090 }
00091 bool effectiveInCheck() const { return true; }
00092 };
00093
00094 struct SendOffGroup : public Group
00095 {
00096 SendOffGroup() : Group("SendOff")
00097 {
00098 for (int p=0; p<8; ++p)
00099 push_back(new SendOff(0));
00100 for (int p=0; p<8; ++p)
00101 push_back(new SendOff(1));
00102 }
00103 void show(std::ostream& os, int name_width, const range_t& range,
00104 const vector<double>& weights) const
00105 {
00106 showAll(os, name_width, range, weights);
00107 }
00108 int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
00109 {
00110 if (! env.sendoffs.isMember(move.to()))
00111 return -1;
00112 const int progress8 = env.progress.value()/2;
00113 return (move.capturePtype() != PTYPE_EMPTY)*8 + progress8;
00114 }
00115 };
00116
00117 struct BlockGroup : public Group
00118 {
00119 BlockGroup() : Group("Block")
00120 {
00121 for (int s=0; s<=3; ++s) {
00122 for (int o=0; o<=3; ++o) {
00123 push_back(new Block(s, o));
00124 }
00125 }
00126 }
00127 void show(std::ostream& os, int name_width, const range_t& range,
00128 const vector<double>& weights) const
00129 {
00130 showAll(os, name_width, range, weights);
00131 }
00132 int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
00133 {
00134 const int index = Block::count(state, move.to(), state.getTurn())*4
00135 + Block::count(state, move.to(), alt(state.getTurn()));
00136 return index;
00137 }
00138 bool effectiveInCheck() const { return true; }
00139 };
00140
00141 struct OpenGroup : public Group
00142 {
00143 OpenGroup() : Group("Open")
00144 {
00145 for (int i=0; i<16; ++i)
00146 push_back(new Open(i));
00147 }
00148 void show(std::ostream& os, int name_width, const range_t& range,
00149 const vector<double>& weights) const
00150 {
00151 showTopN(os, name_width, range, weights, 3);
00152 }
00153 int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
00154 {
00155 const int index = Open::index(state, move);
00156 return index;
00157 }
00158 bool effectiveInCheck() const { return true; }
00159 };
00160
00161 struct ChaseGroup : public Group
00162 {
00163 ChaseGroup();
00164 void show(std::ostream& os, int name_width, const range_t& range,
00165 const vector<double>& weights) const
00166 {
00167 showTopN(os, name_width, range, weights, 3);
00168 }
00169 int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const;
00170 };
00171
00172 struct KaranariGroup : public Group
00173 {
00174 KaranariGroup();
00175 void show(std::ostream& os, int name_width, const range_t& range,
00176 const vector<double>& weights) const
00177 {
00178 showAll(os, name_width, range, weights);
00179 }
00180 int findMatch(const NumEffectState& state, Move move, const RatingEnv&) const;
00181 };
00182
00183 struct ImmediateAddSupportGroup : public Group
00184 {
00185 ImmediateAddSupportGroup();
00186 void show(std::ostream& os, int name_width, const range_t& range,
00187 const vector<double>& weights) const
00188 {
00189 showTopN(os, name_width, range, weights, 3);
00190 }
00191 int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
00192 {
00193 const int index = ImmediateAddSupport::index(state, move, env);
00194 if (index < 0)
00195 return index;
00196 const int progress8 = env.progress.value()/2;
00197 return index*8 + progress8;
00198 }
00199 };
00200
00201 struct BadLanceGroup : public Group
00202 {
00203 BadLanceGroup() : Group("BadLance")
00204 {
00205 push_back(new BadLance(false));
00206 push_back(new BadLance(true));
00207 }
00208 void show(std::ostream& os, int name_width, const range_t& range,
00209 const vector<double>& weights) const
00210 {
00211 showAll(os, name_width, range, weights);
00212 }
00213 int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
00214 {
00215 const Position front = Board_Table.nextPosition(move.player(), move.to(), U);
00216 if (! BadLance::basicMatch(state, move, front))
00217 return -1;
00218 const int index = state.hasEffectBy(alt(move.player()), front);
00219 return index;
00220 }
00221 };
00222
00223 struct PawnAttackGroup : public Group
00224 {
00225 PawnAttackGroup() : Group("PawnAttack")
00226 {
00227 for (int p=0; p<8; ++p)
00228 push_back(new PawnAttack());
00229 }
00230 void show(std::ostream& os, int name_width, const range_t& range,
00231 const vector<double>& weights) const
00232 {
00233 showAll(os, name_width, range, weights);
00234 }
00235 int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
00236 {
00237 if (! (*this)[0].match(state, move, env))
00238 return -1;
00239 const int progress8 = env.progress.value()/2;
00240 return progress8;
00241 }
00242 };
00243 }
00244 }
00245
00246 #endif
00247
00248
00249
00250