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
9namespace 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
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:
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:
圧縮していない moveの表現 .
PtypeO ptypeO() const
移動後のPtype, i.e., 成る手だった場合成った後
Ptype ptype() const
Player player() const
bool isDrop() const
bool isNormal() const
INVALID でも PASS でもない.
Ptype oldPtype() const
移動前のPtype, i.e., 成る手だった場合成る前
const Square to() const
const Square from() const
利きを持つ局面
const Piece findCheapAttack(Player P, Square square) const
bool hasEffectIf(PtypeO ptypeo, Square attacker, Square target) const
attackerにptypeoの駒がいると仮定した場合にtargetに利きがあるかどうか を stateをupdateしないで確かめる.
bool inCheck(Player P) const
Pの玉が王手状態
Ptype ptype() const
Definition basic_type.h:821
const Move lastMove(size_t last=1) const
Definition moveStack.h:28
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 showTopN(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights, int n) const
Definition group.cc:100
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
std::pair< int, int > range_t
Definition range.h:10
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
@ PTYPE_PIECE_MIN
Definition basic_type.h:104
@ PTYPE_MAX
Definition basic_type.h:105
@ PTYPE_MIN
Definition basic_type.h:102
constexpr Player alt(Player player)
Definition basic_type.h:13
static int index(const NumEffectState &state, Square position, const RatingEnv &env)
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
int findMatchWithoutProgress(const NumEffectState &state, Move move, const RatingEnv &env) const
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const