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