My Project
group.h
Go to the documentation of this file.
1/* group.h
2 */
3#ifndef _GROUP_H
4#define _GROUP_H
5
7#include "osl/rating/range.h"
8#include <vector>
9#include <boost/ptr_container/ptr_vector.hpp>
10
11namespace osl
12{
13 namespace rating
14 {
16 class Group : public boost::ptr_vector<Feature>
17 {
18 public:
19 std::string group_name;
20
21 Group(const std::string& name);
22 Group(Feature *f) : group_name(f->name()) { push_back(f); }
23 virtual ~Group();
24 virtual void show(std::ostream&, int name_width, const range_t& range,
25 const std::vector<double>& weights) const;
26
28 virtual int findMatch(const NumEffectState& state, Move m, const RatingEnv& env) const;
29 void showMinMax(std::ostream& os, int name_width, const range_t& range,
30 const std::vector<double>& weights) const;
31 void showAll(std::ostream& os, int name_width, const range_t& range,
32 const std::vector<double>& weights) const;
33 void showTopN(std::ostream& os, int name_width, const range_t& range,
34 const std::vector<double>& weights, int n) const;
35 void saveResult(const std::string& directory, const range_t& range,
36 const std::vector<double>& weights) const;
37 bool load(const std::string& directory, const range_t& range,
38 std::vector<double>& weights) const;
39 virtual bool effectiveInCheck() const { return (*this)[0].effectiveInCheck(); }
40 };
41
42 struct TakeBackGroup : public Group
43 {
44 TakeBackGroup() : Group("TakeBack")
45 {
46 push_back(new TakeBack());
47 push_back(new TakeBack2());
48 }
49#ifndef MINIMAL
50 void show(std::ostream& os, int name_width, const range_t& range,
51 const std::vector<double>& weights) const
52 {
53 showAll(os, name_width, range, weights);
54 }
55#endif
56 int findMatch(const NumEffectState&, Move move, const RatingEnv& env) const
57 {
58 const Square to = move.to();
59 if (! env.history.hasLastMove() || env.history.lastMove().to() != to)
60 return -1;
61 if (! env.history.hasLastMove(2) || env.history.lastMove(2).to() != to)
62 return 0;
63 return 1;
64 }
65 bool effectiveInCheck() const { return true; }
66 };
67
68 struct CheckGroup : public Group
69 {
70 CheckGroup() : Group("Check")
71 {
72 for (int i=0; i<4; ++i)
73 for (int p=0; p<8; ++p) // progress8
74 push_back(new Check(i));
75 }
76 void show(std::ostream& os, int name_width, const range_t& range,
77 const std::vector<double>& weights) const
78 {
79 showAll(os, name_width, range, weights);
80 }
81 int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
82 {
83 const bool direct = state.isDirectCheck(move);
84 const bool open = state.isOpenCheck(move);
85 int index = -1;
86 if (direct && !open)
87 index = Check::openLong(state, move);
88 else if (open)
89 index = direct + 2;
90 const int progress8 = env.progress.value()/2;
91 return index*8 + progress8;
92 }
93 bool effectiveInCheck() const { return true; }
94 };
95
96 class SendOffGroup : public Group
97 {
98 public:
99 SendOffGroup() : Group("SendOff")
100 {
101 for (int p=0; p<8; ++p) // progress8
102 push_back(new SendOff(0));
103 for (int p=0; p<8; ++p) // progress8
104 push_back(new SendOff(1));
105 }
106 void show(std::ostream& os, int name_width, const range_t& range,
107 const std::vector<double>& weights) const
108 {
109 showAll(os, name_width, range, weights);
110 }
111 int findMatch(const NumEffectState&, Move move, const RatingEnv& env) const
112 {
113 if (! env.sendoffs.isMember(move.to()))
114 return -1;
115 const int progress8 = env.progress.value()/2;
116 return (move.capturePtype() != PTYPE_EMPTY)*8 + progress8;
117 }
118 };
119
120 struct BlockGroup : public Group
121 {
122 BlockGroup() : Group("Block")
123 {
124 for (int s=0; s<=3; ++s) {
125 for (int o=0; o<=3; ++o) {
126 push_back(new Block(s, o));
127 }
128 }
129 }
130 void show(std::ostream& os, int name_width, const range_t& range,
131 const std::vector<double>& weights) const
132 {
133 showAll(os, name_width, range, weights);
134 }
135 int findMatch(const NumEffectState& state, Move move, const RatingEnv& ) const
136 {
137 const int index = Block::count(state, move.to(), state.turn())*4
138 + Block::count(state, move.to(), alt(state.turn()));
139 return index;
140 }
141 bool effectiveInCheck() const { return true; }
142 };
143
144 struct OpenGroup : public Group
145 {
146 OpenGroup() : Group("Open")
147 {
148 for (int i=0; i<16; ++i)
149 push_back(new Open(i));
150 }
151 void show(std::ostream& os, int name_width, const range_t& range,
152 const std::vector<double>& weights) const
153 {
154 showTopN(os, name_width, range, weights, 3);
155 }
156 int findMatch(const NumEffectState& state, Move move, const RatingEnv& ) const
157 {
158 const int index = Open::index(state, move);
159 return index;
160 }
161 bool effectiveInCheck() const { return true; }
162 };
163
164 struct ChaseGroup : public Group
165 {
166 ChaseGroup();
167 void show(std::ostream& os, int name_width, const range_t& range,
168 const std::vector<double>& weights) const
169 {
170 showTopN(os, name_width, range, weights, 3);
171 }
172 int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const;
173 };
174
175 struct KaranariGroup : public Group
176 {
178 void show(std::ostream& os, int name_width, const range_t& range,
179 const std::vector<double>& weights) const
180 {
181 showAll(os, name_width, range, weights);
182 }
183 int findMatch(const NumEffectState& state, Move move, const RatingEnv&) const;
184 };
185
187 {
189 void show(std::ostream& os, int name_width, const range_t& range,
190 const std::vector<double>& weights) const
191 {
192 showTopN(os, name_width, range, weights, 3);
193 }
194 int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
195 {
196 const int index = ImmediateAddSupport::index(state, move, env);
197 if (index < 0)
198 return index;
199 const int progress8 = env.progress.value()/2;
200 return index*8 + progress8;
201 }
202 };
203
204 struct BadLanceGroup : public Group
205 {
206 BadLanceGroup() : Group("BadLance")
207 {
208 push_back(new BadLance(false));
209 push_back(new BadLance(true));
210 }
211 void show(std::ostream& os, int name_width, const range_t& range,
212 const std::vector<double>& weights) const
213 {
214 showAll(os, name_width, range, weights);
215 }
216 int findMatch(const NumEffectState& state, Move move, const RatingEnv&) const
217 {
218 const Square front = Board_Table.nextSquare(move.player(), move.to(), U);
219 if (! BadLance::basicMatch(state, move, front))
220 return -1;
221 const int index = state.hasEffectAt(alt(move.player()), front);
222 return index;
223 }
224 };
225
226 struct PawnAttackGroup : public Group
227 {
228 PawnAttackGroup() : Group("PawnAttack")
229 {
230 for (int p=0; p<8; ++p) // progress8
231 push_back(new PawnAttack());
232 }
233 void show(std::ostream& os, int name_width, const range_t& range,
234 const std::vector<double>& weights) const
235 {
236 showAll(os, name_width, range, weights);
237 }
238 int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
239 {
240 if (! (*this)[0].match(state, move, env))
241 return -1;
242 const int progress8 = env.progress.value()/2;
243 return progress8;
244 }
245 };
246 }
247}
248
249#endif /* _GROUP_H */
250// ;;; Local Variables:
251// ;;; mode:c++
252// ;;; c-basic-offset:2
253// ;;; End:
const Square nextSquare(Player P, Square pos, Direction dr) const
next position from pos for player P.
Definition boardTable.h:61
圧縮していない moveの表現 .
Player player() const
Ptype capturePtype() const
const Square to() const
利きを持つ局面
bool isOpenCheck(Move move) const
bool isDirectCheck(Move move) const
bool hasEffectAt(Square target) const
対象とするマスにあるプレイヤーの利きがあるかどうか.
Player turn() const
bool hasLastMove(size_t last=1) const
Definition moveStack.h:27
const Move lastMove(size_t last=1) const
Definition moveStack.h:28
static bool basicMatch(const NumEffectState &state, Move move, Square front)
static int count(const NumEffectState &state, Square position, Player player)
static bool openLong(const NumEffectState &state, Move move)
mutually exclusive set of features
Definition group.h:17
void showAll(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.cc:74
void saveResult(const std::string &directory, const range_t &range, const std::vector< double > &weights) const
Definition group.cc:33
virtual int findMatch(const NumEffectState &state, Move m, const RatingEnv &env) const
Definition group.cc:24
bool load(const std::string &directory, const range_t &range, std::vector< double > &weights) const
Definition group.cc:47
Group(Feature *f)
Definition group.h:22
void showTopN(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights, int n) const
Definition group.cc:100
void showMinMax(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.cc:85
virtual bool effectiveInCheck() const
Definition group.h:39
std::string group_name
Definition group.h:19
virtual void show(std::ostream &, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.cc:62
virtual ~Group()
Definition group.cc:20
static int index(const NumEffectState &state, Move move, const RatingEnv &env)
Definition feature.cc:89
static int index(const NumEffectState &state, Move move)
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.h:106
int findMatch(const NumEffectState &, Move move, const RatingEnv &env) const
Definition group.h:111
std::pair< int, int > range_t
Definition range.h:10
@ PTYPE_EMPTY
Definition basic_type.h:85
const BoardTable Board_Table
Definition tables.cc:95
constexpr Player alt(Player player)
Definition basic_type.h:13
bool isMember(Square position) const
Definition square8.h:22
int findMatch(const NumEffectState &state, Move move, const RatingEnv &) const
Definition group.h:216
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.h:211
int findMatch(const NumEffectState &state, Move move, const RatingEnv &) const
Definition group.h:135
bool effectiveInCheck() const
Definition group.h:141
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.h:130
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition group.cc:150
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.h:167
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition group.h:81
bool effectiveInCheck() const
Definition group.h:93
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.h:76
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.h:189
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition group.h:194
int findMatch(const NumEffectState &state, Move move, const RatingEnv &) const
Definition group.cc:192
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.h:178
bool effectiveInCheck() const
Definition group.h:161
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.h:151
int findMatch(const NumEffectState &state, Move move, const RatingEnv &) const
Definition group.h:156
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.h:233
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition group.h:238
bool effectiveInCheck() const
Definition group.h:65
int findMatch(const NumEffectState &, Move move, const RatingEnv &env) const
Definition group.h:56
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.h:50