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 #ifndef MINIMAL
00049 void show(std::ostream& os, int name_width, const range_t& range,
00050 const vector<double>& weights) const
00051 {
00052 showAll(os, name_width, range, weights);
00053 }
00054 #endif
00055 int findMatch(const NumEffectState&, Move move, const RatingEnv& env) const
00056 {
00057 const Position to = move.to();
00058 if (! env.history.hasLastMove() || env.history.lastMove().to() != to)
00059 return -1;
00060 if (! env.history.hasLastMove(2) || env.history.lastMove(2).to() != to)
00061 return 0;
00062 return 1;
00063 }
00064 bool effectiveInCheck() const { return true; }
00065 };
00066
00067 struct CheckGroup : public Group
00068 {
00069 CheckGroup() : Group("Check")
00070 {
00071 for (int i=0; i<4; ++i)
00072 for (int p=0; p<8; ++p)
00073 push_back(new Check(i));
00074 }
00075 void show(std::ostream& os, int name_width, const range_t& range,
00076 const vector<double>& weights) const
00077 {
00078 showAll(os, name_width, range, weights);
00079 }
00080 int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
00081 {
00082 using namespace osl::move_classifier;
00083 const bool direct = PlayerMoveAdaptor<osl::move_classifier::DirectCheck>::isMember(state, move);
00084 const bool open = ConditionAdaptor<osl::move_classifier::OpenCheck>::isMember(state, move);
00085 int index = -1;
00086 if (direct && !open)
00087 index = Check::openLong(state, move);
00088 else if (open)
00089 index = direct + 2;
00090 const int progress8 = env.progress.value()/2;
00091 return index*8 + progress8;
00092 }
00093 bool effectiveInCheck() const { return true; }
00094 };
00095
00096 struct SendOffGroup : public Group
00097 {
00098 SendOffGroup() : Group("SendOff")
00099 {
00100 for (int p=0; p<8; ++p)
00101 push_back(new SendOff(0));
00102 for (int p=0; p<8; ++p)
00103 push_back(new SendOff(1));
00104 }
00105 void show(std::ostream& os, int name_width, const range_t& range,
00106 const vector<double>& weights) const
00107 {
00108 showAll(os, name_width, range, weights);
00109 }
00110 int findMatch(const NumEffectState&, Move move, const RatingEnv& env) const
00111 {
00112 if (! env.sendoffs.isMember(move.to()))
00113 return -1;
00114 const int progress8 = env.progress.value()/2;
00115 return (move.capturePtype() != PTYPE_EMPTY)*8 + progress8;
00116 }
00117 };
00118
00119 struct BlockGroup : public Group
00120 {
00121 BlockGroup() : Group("Block")
00122 {
00123 for (int s=0; s<=3; ++s) {
00124 for (int o=0; o<=3; ++o) {
00125 push_back(new Block(s, o));
00126 }
00127 }
00128 }
00129 void show(std::ostream& os, int name_width, const range_t& range,
00130 const vector<double>& weights) const
00131 {
00132 showAll(os, name_width, range, weights);
00133 }
00134 int findMatch(const NumEffectState& state, Move move, const RatingEnv& ) const
00135 {
00136 const int index = Block::count(state, move.to(), state.getTurn())*4
00137 + Block::count(state, move.to(), alt(state.getTurn()));
00138 return index;
00139 }
00140 bool effectiveInCheck() const { return true; }
00141 };
00142
00143 struct OpenGroup : public Group
00144 {
00145 OpenGroup() : Group("Open")
00146 {
00147 for (int i=0; i<16; ++i)
00148 push_back(new Open(i));
00149 }
00150 void show(std::ostream& os, int name_width, const range_t& range,
00151 const vector<double>& weights) const
00152 {
00153 showTopN(os, name_width, range, weights, 3);
00154 }
00155 int findMatch(const NumEffectState& state, Move move, const RatingEnv& ) const
00156 {
00157 const int index = Open::index(state, move);
00158 return index;
00159 }
00160 bool effectiveInCheck() const { return true; }
00161 };
00162
00163 struct ChaseGroup : public Group
00164 {
00165 ChaseGroup();
00166 void show(std::ostream& os, int name_width, const range_t& range,
00167 const vector<double>& weights) const
00168 {
00169 showTopN(os, name_width, range, weights, 3);
00170 }
00171 int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const;
00172 };
00173
00174 struct KaranariGroup : public Group
00175 {
00176 KaranariGroup();
00177 void show(std::ostream& os, int name_width, const range_t& range,
00178 const vector<double>& weights) const
00179 {
00180 showAll(os, name_width, range, weights);
00181 }
00182 int findMatch(const NumEffectState& state, Move move, const RatingEnv&) const;
00183 };
00184
00185 struct ImmediateAddSupportGroup : public Group
00186 {
00187 ImmediateAddSupportGroup();
00188 void show(std::ostream& os, int name_width, const range_t& range,
00189 const vector<double>& weights) const
00190 {
00191 showTopN(os, name_width, range, weights, 3);
00192 }
00193 int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
00194 {
00195 const int index = ImmediateAddSupport::index(state, move, env);
00196 if (index < 0)
00197 return index;
00198 const int progress8 = env.progress.value()/2;
00199 return index*8 + progress8;
00200 }
00201 };
00202
00203 struct BadLanceGroup : public Group
00204 {
00205 BadLanceGroup() : Group("BadLance")
00206 {
00207 push_back(new BadLance(false));
00208 push_back(new BadLance(true));
00209 }
00210 void show(std::ostream& os, int name_width, const range_t& range,
00211 const vector<double>& weights) const
00212 {
00213 showAll(os, name_width, range, weights);
00214 }
00215 int findMatch(const NumEffectState& state, Move move, const RatingEnv&) const
00216 {
00217 const Position front = Board_Table.nextPosition(move.player(), move.to(), U);
00218 if (! BadLance::basicMatch(state, move, front))
00219 return -1;
00220 const int index = state.hasEffectBy(alt(move.player()), front);
00221 return index;
00222 }
00223 };
00224
00225 struct PawnAttackGroup : public Group
00226 {
00227 PawnAttackGroup() : Group("PawnAttack")
00228 {
00229 for (int p=0; p<8; ++p)
00230 push_back(new PawnAttack());
00231 }
00232 void show(std::ostream& os, int name_width, const range_t& range,
00233 const vector<double>& weights) const
00234 {
00235 showAll(os, name_width, range, weights);
00236 }
00237 int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
00238 {
00239 if (! (*this)[0].match(state, move, env))
00240 return -1;
00241 const int progress8 = env.progress.value()/2;
00242 return progress8;
00243 }
00244 };
00245 }
00246 }
00247
00248 #endif
00249
00250
00251
00252