escape.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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"
7 #include "osl/rating/feature/escape.h"
8
9 namespace osl
10 {
11 namespace rating
12 {
13 struct FromEffectGroup : public Group
14 {
15 FromEffectGroup();
16 void show(std::ostream& os, int name_width, const range_t& range,
17 const 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 {
34 PtypeAttackedGroup();
35 void show(std::ostream& os, int name_width, const range_t& range,
36 const 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 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 {
77 ImmediateEscapeGroup();
78 void show(std::ostream& os, int name_width, const range_t& range,
79 const 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 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: