My Project
group.h
Go to the documentation of this file.
1 /* group.h
2  */
3 #ifndef _GROUP_H
4 #define _GROUP_H
5 
6 #include "osl/rating/feature.h"
7 #include "osl/rating/range.h"
8 #include <vector>
9 #include <boost/ptr_container/ptr_vector.hpp>
10 
11 namespace 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  {
177  KaranariGroup();
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:
osl::rating::ChaseGroup
Definition: group.h:165
osl::rating::Group::load
bool load(const std::string &directory, const range_t &range, std::vector< double > &weights) const
Definition: group.cc:47
osl::rating::ImmediateAddSupport::index
static int index(const NumEffectState &state, Move move, const RatingEnv &env)
Definition: feature.cc:89
osl::rating::CheckGroup::CheckGroup
CheckGroup()
Definition: group.h:70
osl::rating::Group::saveResult
void saveResult(const std::string &directory, const range_t &range, const std::vector< double > &weights) const
Definition: group.cc:33
osl::rating::BlockGroup::effectiveInCheck
bool effectiveInCheck() const
Definition: group.h:141
osl::Square
Definition: basic_type.h:532
osl::rating::TakeBackGroup::findMatch
int findMatch(const NumEffectState &, Move move, const RatingEnv &env) const
Definition: group.h:56
osl::rating::Group::showMinMax
void showMinMax(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition: group.cc:85
osl::rating::SendOffGroup::SendOffGroup
SendOffGroup()
Definition: group.h:99
osl::rating::ImmediateAddSupportGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition: group.h:189
osl::Board_Table
const BoardTable Board_Table
Definition: tables.cc:95
osl::rating::BadLance
Definition: rating/feature.h:218
osl::alt
constexpr Player alt(Player player)
Definition: basic_type.h:13
osl::NumEffectState::isDirectCheck
bool isDirectCheck(Move move) const
Definition: numEffectState.cc:1068
osl::rating::Check
Definition: rating/feature.h:57
osl::rating::CheckGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition: group.h:76
osl::rating::TakeBackGroup::TakeBackGroup
TakeBackGroup()
Definition: group.h:44
osl::rating::KaranariGroup::KaranariGroup
KaranariGroup()
Definition: group.cc:183
osl::Move
圧縮していない moveの表現 .
Definition: basic_type.h:1052
osl::rating::Group
mutually exclusive set of features
Definition: group.h:17
osl::container::MoveStack::lastMove
const Move lastMove(size_t last=1) const
Definition: moveStack.h:28
osl::rating::BadLanceGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition: group.h:211
osl::rating::Group::group_name
std::string group_name
Definition: group.h:19
osl::rating::RatingEnv::progress
Progress16 progress
Definition: ratingEnv.h:22
osl::rating::range_t
std::pair< int, int > range_t
Definition: range.h:10
osl::rating::OpenGroup::OpenGroup
OpenGroup()
Definition: group.h:146
osl::rating::PawnAttackGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition: group.h:233
osl::rating::Open
Definition: rating/feature.h:120
osl::NumEffectState::hasEffectAt
bool hasEffectAt(Square target) const
対象とするマスにあるプレイヤーの利きがあるかどうか.
Definition: numEffectState.h:324
osl::rating::Group::showAll
void showAll(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition: group.cc:74
osl::rating::Feature
Definition: rating/feature.h:15
osl::rating::Group::~Group
virtual ~Group()
Definition: group.cc:20
osl::rating::Group::Group
Group(Feature *f)
Definition: group.h:22
osl::rating::CheckGroup::effectiveInCheck
bool effectiveInCheck() const
Definition: group.h:93
osl::rating::TakeBackGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition: group.h:50
osl::rating::OpenGroup
Definition: group.h:145
osl::rating::SendOffGroup
Definition: group.h:97
osl::rating::RatingEnv
Definition: ratingEnv.h:16
osl::rating::OpenGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &) const
Definition: group.h:156
osl::rating::SendOffGroup::findMatch
int findMatch(const NumEffectState &, Move move, const RatingEnv &env) const
Definition: group.h:111
osl::rating::BlockGroup::BlockGroup
BlockGroup()
Definition: group.h:122
osl::rating::Group::Group
Group(const std::string &name)
Definition: group.cc:15
osl::rating::CheckGroup
Definition: group.h:69
osl::rating::TakeBack
Definition: rating/feature.h:28
osl::Move::capturePtype
Ptype capturePtype() const
Definition: basic_type.h:1180
osl::rating::Block::count
static int count(const NumEffectState &state, Square position, Player player)
Definition: rating/feature.h:91
osl::rating::Block
Definition: rating/feature.h:86
osl::NumEffectState::isOpenCheck
bool isOpenCheck(Move move) const
Definition: numEffectState.cc:1074
osl::rating::RatingEnv::sendoffs
Square8 sendoffs
Definition: ratingEnv.h:19
osl::rating::BadLanceGroup
Definition: group.h:205
osl::container::Square8::isMember
bool isMember(Square position) const
Definition: square8.h:22
osl::rating::Check::openLong
static bool openLong(const NumEffectState &state, Move move)
Definition: rating/feature.h:61
osl::rating::RatingEnv::history
MoveStack history
Definition: ratingEnv.h:18
osl::rating::TakeBackGroup::effectiveInCheck
bool effectiveInCheck() const
Definition: group.h:65
osl::rating::PawnAttackGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition: group.h:238
osl::rating::ChaseGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition: group.h:167
range.h
osl::rating::ImmediateAddSupportGroup::ImmediateAddSupportGroup
ImmediateAddSupportGroup()
Definition: group.cc:198
osl::rating::BadLanceGroup::BadLanceGroup
BadLanceGroup()
Definition: group.h:206
osl::NumEffectState
利きを持つ局面
Definition: numEffectState.h:34
osl::rating::BlockGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition: group.h:130
osl::rating::KaranariGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition: group.h:178
osl::BoardTable::nextSquare
const Square nextSquare(Player P, Square pos, Direction dr) const
next position from pos for player P.
Definition: boardTable.h:61
osl::rating::ChaseGroup::ChaseGroup
ChaseGroup()
Definition: group.cc:134
osl::rating::BadLance::basicMatch
static bool basicMatch(const NumEffectState &state, Move move, Square front)
Definition: rating/feature.h:224
osl::rating::CheckGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition: group.h:81
osl::rating::BlockGroup
Definition: group.h:121
osl::rating::Group::findMatch
virtual int findMatch(const NumEffectState &state, Move m, const RatingEnv &env) const
Definition: group.cc:24
osl::rating::SendOff
Definition: rating/feature.h:75
osl::rating::KaranariGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &) const
Definition: group.cc:192
osl::rating::TakeBack2
Definition: rating/feature.h:41
osl::rating::PawnAttack
Definition: rating/feature.h:241
osl::rating::Open::index
static int index(const NumEffectState &state, Move move)
Definition: rating/feature.h:124
osl::rating::Group::effectiveInCheck
virtual bool effectiveInCheck() const
Definition: group.h:39
osl::PTYPE_EMPTY
@ PTYPE_EMPTY
Definition: basic_type.h:85
osl::SimpleState::turn
Player turn() const
Definition: simpleState.h:220
osl::rating::KaranariGroup
Definition: group.h:176
osl::rating::SendOffGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition: group.h:106
osl::rating::OpenGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition: group.h:151
osl::rating::PawnAttackGroup::PawnAttackGroup
PawnAttackGroup()
Definition: group.h:228
osl::rating::Group::showTopN
void showTopN(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights, int n) const
Definition: group.cc:100
osl::Move::to
const Square to() const
Definition: basic_type.h:1132
osl::container::MoveStack::hasLastMove
bool hasLastMove(size_t last=1) const
Definition: moveStack.h:27
osl::rating::Group::show
virtual void show(std::ostream &, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition: group.cc:62
osl::rating::PawnAttackGroup
Definition: group.h:227
osl::rating::OpenGroup::effectiveInCheck
bool effectiveInCheck() const
Definition: group.h:161
osl::rating::ImmediateAddSupportGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition: group.h:194
osl::U
@ U
Definition: basic_type.h:314
osl::rating::ChaseGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition: group.cc:150
osl::rating::BadLanceGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &) const
Definition: group.h:216
osl::rating::BlockGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &) const
Definition: group.h:135
osl::Move::player
Player player() const
Definition: basic_type.h:1195
osl::rating::ImmediateAddSupportGroup
Definition: group.h:187
osl
Definition: additionalEffect.h:6
feature.h
osl::rating::TakeBackGroup
Definition: group.h:43