My Project
group/escape.h
Go to the documentation of this file.
1 /* escape.h
2  */
3 #ifndef GROUP_ESCAPE_H
4 #define GROUP_ESCAPE_H
5 
6 #include "osl/rating/group.h"
8 
9 namespace osl
10 {
11  namespace rating
12  {
13  struct FromEffectGroup : public Group
14  {
16  void show(std::ostream& os, int name_width, const range_t& range,
17  const std::vector<double>& weights) const
18  {
19  showTopN(os, name_width, range, weights, 3);
20  }
21  int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
22  {
23  if (move.isDrop())
24  return -1;
25  const int index = CountEffect2::index(state, move.from(), env);
26  const int progress8 = env.progress.value()/2;
27  return index*8 + progress8;
28  }
29  bool effectiveInCheck() const { return true; }
30  };
31 
32  struct PtypeAttackedGroup : public Group
33  {
35  void show(std::ostream& os, int name_width, const range_t& range,
36  const std::vector<double>& weights) const
37  {
38  showTopN(os, name_width, range, weights, 3);
39  }
40  int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
41  {
42  if (move.isDrop())
43  return -1;
44  const int progress8 = env.progress.value()/2;
45  const Ptype self = move.oldPtype();
46  const Ptype attack = state.findCheapAttack(alt(move.player()), move.from()).ptype();
47  const int index = (self-PTYPE_PIECE_MIN)*(PTYPE_MAX+1-PTYPE_MIN)+attack;
48  return index*8 + progress8;
49  }
50  bool effectiveInCheck() const { return true; }
51  };
52 
53  struct ToSupportedGroup : public Group
54  {
55  ToSupportedGroup() : Group("ToSupported")
56  {
57  for (int p=0; p<8; ++p) // progress8
58  push_back(new ToSupported());
59  }
60  void show(std::ostream& os, int name_width, const range_t& range,
61  const std::vector<double>& weights) const
62  {
63  showAll(os, name_width, range, weights);
64  }
65  int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
66  {
67  if (! (*this)[0].match(state, move, env))
68  return -1;
69  const int progress8 = env.progress.value()/2;
70  return progress8;
71  }
72  bool effectiveInCheck() const { return true; }
73  };
74 
75  struct ImmediateEscapeGroup : public Group
76  {
78  void show(std::ostream& os, int name_width, const range_t& range,
79  const std::vector<double>& weights) const
80  {
81  showTopN(os, name_width, range, weights, 3);
82  }
83  int findMatchWithoutProgress(const NumEffectState& state, Move move, const RatingEnv& env) const
84  {
85  if (move.isDrop())
86  return -1;
87  const Move last_move = env.history.lastMove();
88  if (! last_move.isNormal()
89  || ! state.hasEffectIf(last_move.ptypeO(), last_move.to(), move.from()))
90  return -1;
91  return (move.ptype() - PTYPE_PIECE_MIN) * (PTYPE_MAX+1 - PTYPE_PIECE_MIN)
92  + last_move.ptype() - PTYPE_PIECE_MIN;
93  }
94  int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
95  {
96  const int index = findMatchWithoutProgress(state, move, env);
97  if (index < 0)
98  return index;
99  const int progress8 = env.progress.value()/2;
100  return index*8 + progress8;
101  }
102  };
103 
104  class KingEscapeGroup : public Group
105  {
106  public:
107  KingEscapeGroup();
108  void show(std::ostream& os, int name_width, const range_t& range,
109  const std::vector<double>& weights) const
110  {
111  showAll(os, name_width, range, weights);
112  }
113  int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
114  {
115  if (! state.inCheck())
116  return -1;
117  const Ptype self = move.ptype();
118  const int index = self-PTYPE_PIECE_MIN;
119  assert((*this)[index].match(state, move, env));
120  return index;
121  }
122  bool effectiveInCheck() const { return true; }
123  };
124  }
125 }
126 
127 #endif /* GROUP_ESCAPE_H */
128 // ;;; Local Variables:
129 // ;;; mode:c++
130 // ;;; c-basic-offset:2
131 // ;;; End:
osl::rating::PtypeAttackedGroup::PtypeAttackedGroup
PtypeAttackedGroup()
Definition: escape.cc:15
osl::PTYPE_PIECE_MIN
@ PTYPE_PIECE_MIN
Definition: basic_type.h:104
osl::NumEffectState::findCheapAttack
const Piece findCheapAttack(Player P, Square square) const
Definition: numEffectState.h:560
escape.h
osl::rating::ImmediateEscapeGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition: group/escape.h:94
osl::alt
constexpr Player alt(Player player)
Definition: basic_type.h:13
osl::rating::ImmediateEscapeGroup::findMatchWithoutProgress
int findMatchWithoutProgress(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition: group/escape.h:83
group.h
osl::rating::FromEffectGroup
Definition: group/escape.h:14
osl::rating::ImmediateEscapeGroup
Definition: group/escape.h:76
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::RatingEnv::progress
Progress16 progress
Definition: ratingEnv.h:22
osl::rating::KingEscapeGroup
Definition: group/escape.h:105
osl::rating::PtypeAttackedGroup
Definition: group/escape.h:33
osl::Ptype
Ptype
駒の種類を4ビットでコード化する
Definition: basic_type.h:84
osl::rating::PtypeAttackedGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition: group/escape.h:40
osl::rating::range_t
std::pair< int, int > range_t
Definition: range.h:10
osl::NumEffectState::hasEffectIf
bool hasEffectIf(PtypeO ptypeo, Square attacker, Square target) const
attackerにptypeoの駒がいると仮定した場合にtargetに利きがあるかどうか を stateをupdateしないで確かめる.
Definition: numEffectState.h:465
osl::rating::ToSupportedGroup::effectiveInCheck
bool effectiveInCheck() const
Definition: group/escape.h:72
osl::rating::PtypeAttackedGroup::effectiveInCheck
bool effectiveInCheck() const
Definition: group/escape.h:50
osl::NumEffectState::inCheck
bool inCheck(Player P) const
Pの玉が王手状態
Definition: numEffectState.h:88
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::ToSupportedGroup
Definition: group/escape.h:54
osl::Move::oldPtype
Ptype oldPtype() const
移動前のPtype, i.e., 成る手だった場合成る前
Definition: basic_type.h:1174
osl::rating::RatingEnv
Definition: ratingEnv.h:16
osl::PTYPE_MAX
@ PTYPE_MAX
Definition: basic_type.h:105
osl::rating::KingEscapeGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition: group/escape.h:113
osl::rating::PtypeAttackedGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition: group/escape.h:35
osl::rating::ImmediateEscapeGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition: group/escape.h:78
osl::rating::FromEffectGroup::FromEffectGroup
FromEffectGroup()
Definition: escape.cc:6
osl::rating::ImmediateEscapeGroup::ImmediateEscapeGroup
ImmediateEscapeGroup()
Definition: escape.cc:26
osl::Move::isDrop
bool isDrop() const
Definition: basic_type.h:1150
osl::Move::ptypeO
PtypeO ptypeO() const
移動後のPtype, i.e., 成る手だった場合成った後
Definition: basic_type.h:1162
osl::rating::CountEffect2::index
static int index(const NumEffectState &state, Square position, const RatingEnv &env)
Definition: countEffect2.h:43
osl::rating::RatingEnv::history
MoveStack history
Definition: ratingEnv.h:18
osl::PTYPE_MIN
@ PTYPE_MIN
Definition: basic_type.h:102
osl::Move::isNormal
bool isNormal() const
INVALID でも PASS でもない.
Definition: basic_type.h:1088
osl::rating::ToSupportedGroup::ToSupportedGroup
ToSupportedGroup()
Definition: group/escape.h:55
osl::Move::from
const Square from() const
Definition: basic_type.h:1125
osl::rating::FromEffectGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition: group/escape.h:16
osl::NumEffectState
利きを持つ局面
Definition: numEffectState.h:34
osl::rating::KingEscapeGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition: group/escape.h:108
osl::Piece::ptype
Ptype ptype() const
Definition: basic_type.h:821
osl::Move::ptype
Ptype ptype() const
Definition: basic_type.h:1155
osl::rating::FromEffectGroup::effectiveInCheck
bool effectiveInCheck() const
Definition: group/escape.h:29
osl::rating::ToSupported
Definition: feature/escape.h:43
osl::rating::ToSupportedGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition: group/escape.h:60
osl::rating::KingEscapeGroup::KingEscapeGroup
KingEscapeGroup()
Definition: escape.cc:37
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::rating::KingEscapeGroup::effectiveInCheck
bool effectiveInCheck() const
Definition: group/escape.h:122
osl::Move::to
const Square to() const
Definition: basic_type.h:1132
osl::rating::FromEffectGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition: group/escape.h:21
osl::Move::player
Player player() const
Definition: basic_type.h:1195
osl::rating::ToSupportedGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition: group/escape.h:65
osl
Definition: additionalEffect.h:6